/* Modern Design System for schneider-busch.de */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Colors */
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --primary-text: #0369a1;

  --danger: #ef4444;
  --danger-light: #fee2e2;

  --success: #10b981;
  --success-light: #d1fae5;

  --sidebar-width: 320px;
  --header-height: 60px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--text-main);
  background-color: var(--bg-app);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Mobile Header */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  padding: 0 16px;
  z-index: 40;
  gap: 12px;
}

.mobile-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-main);
  flex: 1;
}

.admin-badge-mobile {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-text);
  padding: 3px 8px;
  border-radius: 9999px;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-branding {
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-icon {
  font-size: 1.75rem;
}

.site-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.site-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Search Box */
.sidebar-search {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-light);
  pointer-events: none;
}

.search-input-wrapper input {
  width: 100%;
  padding: 8px 30px 8px 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-app);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrapper input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.clear-search-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
}

.search-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  padding-left: 2px;
}

/* Tree Navigation */
.tree-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.tree-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tree-item {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 6px;
  transition: background-color 0.15s, color 0.15s;
  position: relative;
}

.tree-row:hover {
  background-color: #f1f5f9;
}

.tree-row.active {
  background-color: var(--primary-light);
  color: var(--primary-text);
  font-weight: 600;
}

.tree-expander {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.2s, color 0.15s;
  flex-shrink: 0;
}

.tree-expander:hover {
  color: var(--text-main);
  background: rgba(0,0,0,0.05);
}

.tree-expander.open {
  transform: rotate(90deg);
}

.tree-expander.empty {
  visibility: hidden;
}

.tree-icon {
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  flex-shrink: 0;
}

.tree-label {
  font-size: 0.9rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-highlight {
  background: #fef08a;
  border-radius: 2px;
  padding: 0 1px;
}

/* Tree Admin Actions on Row */
.tree-actions {
  display: none;
  align-items: center;
  gap: 3px;
  margin-left: auto;
}

.tree-row:hover .tree-actions,
.tree-row:focus-within .tree-actions {
  display: flex;
}

.tree-action-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.tree-action-btn:hover {
  color: var(--text-main);
  border-color: var(--primary);
  background: var(--primary-light);
}

.tree-action-btn.delete-btn:hover {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
}

.tree-children {
  padding-left: 18px;
  display: none;
  flex-direction: column;
  gap: 2px;
  border-left: 1px solid var(--border-subtle);
  margin-left: 9px;
  margin-top: 2px;
}

.tree-children.open {
  display: flex;
}

.tree-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 10px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Sidebar Footer & Admin Buttons */
.admin-tree-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
}

.auth-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.admin-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--success);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--success-light);
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #ffffff;
  overflow-y: auto;
  position: relative;
}

.content-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb-item {
  color: var(--text-muted);
}

.breadcrumb-sep {
  color: var(--text-light);
}

.breadcrumb-item.current {
  color: var(--text-main);
  font-weight: 600;
}

.content-header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.last-modified {
  font-size: 0.78rem;
  color: var(--text-light);
}

/* Content Body */
.content-body {
  padding: 40px 60px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

/* Markdown Rendering */
.markdown-rendered {
  line-height: 1.7;
  color: #1e293b;
  font-size: 1.05rem;
}

.markdown-rendered h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 1.2rem;
  line-height: 1.25;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.markdown-rendered h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: var(--text-main);
}

.markdown-rendered h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.markdown-rendered p {
  margin-bottom: 1.2rem;
}

.markdown-rendered ul,
.markdown-rendered ol {
  margin-bottom: 1.2rem;
  padding-left: 1.5rem;
}

.markdown-rendered li {
  margin-bottom: 0.4rem;
}

.markdown-rendered a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.markdown-rendered a:hover {
  color: var(--primary-hover);
}

.markdown-rendered hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
}

.markdown-rendered blockquote {
  border-left: 4px solid var(--primary);
  background: var(--primary-light);
  padding: 12px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1.2rem 0;
  color: #1e293b;
  font-style: italic;
}

.markdown-rendered code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: #f1f5f9;
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
}

.markdown-rendered pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 1.4rem 0;
}

.markdown-rendered pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 0.95em;
}

.markdown-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.markdown-rendered th,
.markdown-rendered td {
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  text-align: left;
}

.markdown-rendered th {
  background: #f8fafc;
  font-weight: 600;
}

.markdown-rendered tr:nth-child(even) {
  background: #fcfcfc;
}

/* Editor Styling */
.content-editor {
  display: flex;
  flex-direction: column;
  padding: 24px 32px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  gap: 16px;
}

.editor-title-input {
  width: 100%;
  font-size: 1.8rem;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid var(--border-color);
  padding: 8px 0;
  outline: none;
  color: var(--text-main);
  transition: border-color 0.2s;
}

.editor-title-input:focus {
  border-bottom-color: var(--primary);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.toolbar-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.15s;
}

.toolbar-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-text);
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

.editor-tabs {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: none;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}

.tab-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.editor-container {
  flex: 1;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.editor-textarea {
  width: 100%;
  flex: 1;
  min-height: 400px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
  outline: none;
  resize: vertical;
}

.editor-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.editor-preview {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 24px;
  min-height: 400px;
  background: #ffffff;
}

.editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: #f1f5f9;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.icon-btn:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

/* Modals / Dialogs */
.modal-dialog {
  margin: auto;
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  background: #ffffff;
  max-width: 460px;
  width: calc(100% - 32px);
  padding: 0;
  outline: none;
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.modal-content {
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.close-dialog-btn {
  font-size: 1.5rem;
  line-height: 1;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.radio-label:hover {
  background: #f8fafc;
}

.parent-info-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.form-error {
  background: var(--danger-light);
  color: var(--danger);
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Utility */
.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

/* Responsive / Mobile View */
@media (max-width: 768px) {
  body {
    padding-top: var(--header-height);
  }

  .mobile-header {
    display: flex;
  }

  .mobile-only {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 45;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .content-header {
    padding: 0 16px;
  }

  .content-body {
    padding: 24px 16px;
  }

  .content-editor {
    padding: 16px;
  }
}
