/* ============================================================
   OPENDOCS — Global Design System
   ============================================================ */

/* --- Tokens ------------------------------------------------- */
:root {
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Sidebar — light */
  --sidebar-bg:          #f8f9fa;
  --sidebar-border:      #e5e7eb;
  --sidebar-text:        #374151;
  --sidebar-text-active: #111827;
  --sidebar-hover:       #f0f1f3;
  --sidebar-active:      #eff6ff;
  --sidebar-active-bar:  #2563eb;
  --sidebar-width:       220px;

  /* Auth brand panel (keeps dark — separate token) */
  --auth-brand-bg:       #0B0D11;
  --auth-brand-text:     #8892A4;
  --auth-brand-border:   rgba(255, 255, 255, 0.07);

  /* Surface */
  --bg:          #F5F4F1;
  --surface:     #FFFFFF;
  --surface-2:   #F0EFF0;
  --border:      #E4E3E0;
  --border-subtle: rgba(0,0,0,0.06);

  /* Text */
  --text:        #0D1117;
  --text-muted:  #6B7280;
  --text-faint:  #9CA3AF;

  /* Accent */
  --accent:      #2563EB;
  --accent-dark: #1D4ED8;
  --accent-soft: #DBEAFE;
  --accent-text: #FFFFFF;

  /* Status */
  --danger: #DC2626;
  --success: #16A34A;

  /* Radius */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

/* --- Base --------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Auth Shell -------------------------------------------- */
.auth-body {
  background: #0B0D11;
}

.auth-shell {
  display: flex;
  min-height: 100vh;
}

/* Brand panel — left, dark */
.auth-brand {
  width: 480px;
  flex-shrink: 0;
  background: linear-gradient(160deg, #0B0D11 0%, #111827 50%, #0f172a 100%);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.auth-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 80%, rgba(37, 99, 235, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 20%, rgba(139, 92, 246, 0.08) 0%, transparent 60%);
  pointer-events: none;
}

.auth-brand::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

.auth-brand-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 40px 48px;
}

.auth-brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.auth-brand-logo:hover { text-decoration: none; }

.auth-brand-logo span {
  font-size: 18px;
  font-weight: 700;
  color: #F1F5F9;
  letter-spacing: -0.4px;
}

.auth-brand-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 0;
}

.auth-brand-content h2 {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
  color: #F1F5F9;
  letter-spacing: -0.8px;
  margin: 0 0 16px;
}

.auth-brand-content p {
  font-size: 15px;
  color: #94A3B8;
  line-height: 1.6;
  margin: 0 0 32px;
}

.auth-feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-feature-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #94A3B8;
}

.auth-feature-list li svg { flex-shrink: 0; }

.auth-brand-footer {
  font-size: 12px;
  color: rgba(148, 163, 184, 0.4);
  margin: 0;
}

/* Form panel — right */
.auth-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  padding: 48px 40px;
  overflow-y: auto;
}

.auth-form-inner {
  width: 100%;
  max-width: 380px;
}

/* Auth header */
.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.5px;
  margin: 0 0 6px;
}

.auth-header p {
  font-size: 14px;
  color: #6B7280;
  margin: 0 0 28px;
}

/* External login buttons */
.auth-external { margin-bottom: 0; }
.auth-external form { display: flex; flex-direction: column; gap: 10px; }

.btn-external {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  border: 1.5px solid #E5E7EB;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-external:hover {
  border-color: #D1D5DB;
  background: #F9FAFB;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.btn-external:active { transform: translateY(0); }

.btn-external-google:hover { border-color: #4285F4; background: #F8FBFF; }
.btn-external-github { background: #24292F; border-color: #24292F; color: #FFFFFF; }
.btn-external-github:hover { background: #32383F; border-color: #32383F; }
.btn-external-github svg { color: #FFFFFF; }

/* Divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  color: #9CA3AF;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #E5E7EB;
}

/* Form styles */
.auth-form { margin: 0; }

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}

.form-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.form-label-row label { margin-bottom: 0; }

.form-link {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}

.form-link:hover { text-decoration: underline; }

.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #E5E7EB;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: #111827;
  background: #FFFFFF;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-group input::placeholder {
  color: #9CA3AF;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.field-error {
  display: block;
  font-size: 12px;
  color: #DC2626;
  margin-top: 4px;
}

.auth-error {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 13px;
  color: #991B1B;
}

.auth-error:empty { display: none; }

/* Checkbox */
.form-check-row { margin-bottom: 20px; }

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #6B7280;
  cursor: pointer;
}

.check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  accent-color: var(--accent);
}

/* Primary auth button */
.btn-auth-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  color: #FFFFFF;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.1px;
}

.btn-auth-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-auth-primary:active { transform: translateY(0); box-shadow: none; }

/* Footer links */
.auth-footer-links {
  text-align: center;
  margin-top: 24px;
}

.auth-footer-links p {
  font-size: 13px;
  color: #6B7280;
  margin: 0;
}

.auth-footer-links a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.auth-footer-links a:hover { text-decoration: underline; }

/* Legacy Identity overrides (for non-scaffolded pages) */
.auth-form-inner .row { display: block; }
.auth-form-inner .col-lg-6,
.auth-form-inner .col-lg-4 { width: 100%; max-width: 100%; padding: 0; }
.auth-form-inner .form-floating { margin-bottom: 14px !important; }
.auth-form-inner .form-control {
  border: 1.5px solid #E5E7EB !important;
  border-radius: 10px !important;
  background: #FFFFFF !important;
  font-family: var(--font-ui) !important;
  font-size: 14px !important;
  color: #111827 !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
}
.auth-form-inner .form-control:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
  outline: none !important;
}
.auth-form-inner .form-floating > label {
  font-size: 13px !important;
  color: #6B7280 !important;
  font-family: var(--font-ui) !important;
}
.auth-form-inner .btn-primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: white !important;
  font-family: var(--font-ui) !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  border-radius: 10px !important;
  padding: 12px 20px !important;
  transition: all 0.15s ease !important;
}
.auth-form-inner .btn-primary:hover {
  background: var(--accent-dark) !important;
  border-color: var(--accent-dark) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25) !important;
}
.auth-form-inner .btn-primary:active { transform: translateY(0) !important; }
.auth-form-inner p a { color: var(--accent); font-size: 13px; font-weight: 500; }
.auth-form-inner .text-secondary { color: #9CA3AF !important; font-size: 12px; }
.auth-form-inner .text-danger { font-size: 12px !important; color: #DC2626 !important; }

/* Responsive — stack on mobile */
@media (max-width: 768px) {
  .auth-shell { flex-direction: column; }
  .auth-brand { width: 100%; min-height: 200px; }
  .auth-brand-inner { padding: 24px 24px; }
  .auth-brand-content { padding: 16px 0; }
  .auth-brand-content h2 { font-size: 22px; }
  .auth-feature-list { display: none; }
  .auth-form-panel { padding: 32px 24px; }
}

/* Validation */
.valid.modified:not([type=checkbox]) { outline: 1.5px solid var(--success); border-radius: var(--r-sm); }
.invalid { outline: 1.5px solid var(--danger); border-radius: var(--r-sm); }
.validation-message { color: var(--danger); font-size: 12px; }

/* --- Dashboard Shell --------------------------------------- */
.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.shell-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  background: var(--bg);
}

.shell-content {
  padding: 32px 40px;
  max-width: 1100px;
}

/* --- Sidebar Internal Layout ------------------------------ */
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
}

/* Nav links */
.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  position: relative;
  border: none;
  cursor: pointer;
  width: 100%;
  background: none;
}

.sidebar-nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
  text-decoration: none;
}

.sidebar-nav-link.active {
  background: var(--sidebar-active);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--sidebar-active-bar);
  border-radius: 0 2px 2px 0;
}

.sidebar-nav-link .nav-icon { opacity: 0.55; width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-nav-link:hover .nav-icon,
.sidebar-nav-link.active .nav-icon { opacity: 1; }

/* User footer */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 12.5px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* --- Org Switcher ----------------------------------------- */
.org-switcher {
  position: relative;
}

.org-switcher[open] > summary { background: var(--sidebar-hover); }

summary.org-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  list-style: none;
  transition: background 0.12s;
}
summary.org-trigger:hover { background: var(--sidebar-hover); }
summary.org-trigger::-webkit-details-marker { display: none; }

.org-avatar {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.org-avatar.sm {
  width: 22px;
  height: 22px;
  font-size: 11px;
  border-radius: 5px;
}

.org-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--sidebar-text-active);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-chevron {
  color: var(--sidebar-text);
  flex-shrink: 0;
  transition: transform 0.15s;
}
.org-switcher[open] .org-chevron { transform: rotate(180deg); }

.org-dropdown {
  margin-top: 4px;
  background: #ffffff;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  padding: 4px;
}

.org-option-form { margin: 0; }

.org-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--sidebar-text);
  text-align: left;
  transition: background 0.1s, color 0.1s;
}
.org-option:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.org-option.active { color: var(--sidebar-text-active); }

.check-icon { color: var(--accent); margin-left: auto; }

.org-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 10px;
}

.org-empty-icon { color: var(--sidebar-text); }

.org-empty-text {
  font-size: 12px;
  color: var(--sidebar-text);
}

.org-create-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: 1px solid rgba(37, 99, 235, 0.35);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.12s;
}
.org-create-btn:hover { background: rgba(37, 99, 235, 0.1); }

/* --- Dashboard Pages -------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  margin: 0 0 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 64px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-soft);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--accent);
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.empty-state p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.6;
  margin: 0 0 20px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13.5px;
  border-radius: var(--r-md);
  padding: 9px 18px;
  transition: background 0.15s, transform 0.1s;
  border: none;
  cursor: pointer;
}
.btn-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 13.5px;
  border-radius: var(--r-md);
  padding: 8px 18px;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--text-muted); background: var(--surface-2); }

/* Settings pages */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* Form controls in dashboard */
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
  display: block;
}

.form-control {
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  outline: none;
}
.form-control:disabled,
.form-control[readonly] {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-trial { background: #FEF3C7; color: #92400E; }
.badge-active { background: #D1FAE5; color: #065F46; }
.badge-expired { background: #FEE2E2; color: #991B1B; }
.badge-owner { background: var(--accent-soft); color: var(--accent); }
.badge-admin { background: #E0F2FE; color: #0369A1; }
.badge-editor { background: #F0FDF4; color: #166534; }
.badge-viewer { background: var(--surface-2); color: var(--text-muted); }

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }

/* Blazor errors */
#blazor-error-ui {
  color-scheme: light only;
  background: #FEF3C7;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0,0,0,0.12);
  box-sizing: border-box;
  display: none;
  left: 0;
  padding: 12px 20px;
  position: fixed;
  width: 100%;
  z-index: 9999;
  font-size: 13px;
  color: #92400E;
}
#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 16px;
  top: 12px;
  font-weight: 600;
}

/* Paywall page */
.paywall-container {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
}
.paywall-icon {
  width: 64px;
  height: 64px;
  background: #FEF3C7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 28px;
}
.paywall-container h1 { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.paywall-container p { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; line-height: 1.6; }

/* ============================================================
   Editor Mode — 4-panel grid
   ============================================================ */

body.editor-mode {
  overflow: hidden;
}

body.editor-mode .shell {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: var(--sidebar-width) 240px 1fr 220px;
  grid-template-areas:
    "topbar   topbar    topbar   topbar"
    "leftnav  pagetree  content  toc";
  height: 100vh;
  overflow: hidden;
}

body.editor-mode .editor-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--sidebar-border);
  z-index: 200;
}

body.editor-mode .sidebar {
  grid-area: leftnav;
  height: 100%;
  overflow-y: auto;
}

body.editor-mode .editor-tree-panel {
  grid-area: pagetree;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  height: 100%;
  padding: 12px;
}

body.editor-mode .shell-body {
  grid-area: content;
  overflow-y: auto;
  height: 100%;
  background: #fff;
}

body.editor-mode .shell-content {
  padding: 0;
  max-width: none;
}

body.editor-mode .editor-toc-panel {
  grid-area: toc;
  background: #fff;
  border-left: 1px solid var(--sidebar-border);
  overflow-y: auto;
  height: 100%;
  padding: 48px 16px 24px;
}

/* ============================================================
   Editor Topbar Components
   ============================================================ */

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar-logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.topbar-crumb {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.topbar-crumb:hover { color: var(--text); text-decoration: none; }

.topbar-crumb-current {
  color: var(--text);
  font-weight: 600;
  cursor: default;
}

.topbar-crumb-sep {
  color: var(--text-faint);
  font-size: 13px;
  flex-shrink: 0;
  user-select: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-state-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.topbar-state-badge.badge-draft {
  background: #f3f4f6;
  color: var(--text-muted);
}

.topbar-state-badge.badge-published {
  background: #dcfce7;
  color: #15803d;
}

.topbar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  border: none;
  background: none;
  cursor: pointer;
}

.topbar-icon-btn:hover {
  background: #f3f4f6;
  color: var(--text);
  text-decoration: none;
}

.topbar-publish-btn {
  padding: 0 14px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}

.topbar-publish-btn:hover { background: var(--accent-dark); }

.topbar-publish-btn.btn-unpublish {
  background: #f3f4f6;
  color: var(--text);
}

.topbar-publish-btn.btn-unpublish:hover { background: #e5e7eb; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  min-width: 240px;
  max-width: 360px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  pointer-events: all;
  animation: toast-in 0.2s ease;
}

.toast-success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.toast-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.toast-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Help pages
   ============================================================ */

.help-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 24px;
}

.help-page h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}

.help-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 28px;
}

/* Tabs */
.help-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  overflow-x: auto;
}

.help-tab {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.help-tab:hover {
  color: var(--text);
}

.help-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Topic cards grid (landing page) */
.help-topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.help-topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px 20px;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.help-topic-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
  transform: translateY(-2px);
}

.help-topic-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-soft);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  color: var(--accent);
}

.help-topic-icon svg {
  width: 20px;
  height: 20px;
}

.help-topic-card h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.help-topic-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Content sections */
.help-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.help-section h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}

.help-section p {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  margin: 0 0 10px;
}

.help-section p:last-child {
  margin-bottom: 0;
}

.help-list {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.help-list li {
  margin-bottom: 4px;
}

.help-list-ordered {
  list-style-type: decimal;
}

/* Tip callout */
.help-tip {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: var(--r-lg);
  padding: 16px 20px;
  font-size: 13px;
  color: #92400E;
  line-height: 1.5;
  margin-top: 20px;
}

/* Code block */
.help-code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 16px;
  margin: 10px 0;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  color: var(--text);
  overflow-x: auto;
}

/* Keyboard shortcuts table */
.help-shortcuts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 20px;
  align-items: center;
}

.help-shortcut {
  display: contents;
}

.help-shortcut kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.help-shortcut span {
  font-size: 13px;
  color: var(--text-muted);
}

/* Plan comparison cards */
.help-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}

.help-plan-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px;
}

.help-plan-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text);
}

.help-plan-pro {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.help-plan-pro h4 {
  color: var(--accent);
}

/* --- Image Lightbox ------------------------------------- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.lightbox-overlay.lightbox-visible { opacity: 1; }
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  object-fit: contain;
  cursor: default;
}

/* --- File Upload Preview -------------------------------- */
.file-upload-preview {
  margin-bottom: 8px;
}
.file-upload-preview img {
  max-height: 48px;
  max-width: 200px;
  border-radius: 4px;
  border: 1px solid var(--sidebar-border, #e5e7eb);
  object-fit: contain;
}
.file-upload-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  border: 1.5px dashed var(--sidebar-border, #d1d5db);
  border-radius: 6px;
  color: #9ca3af;
  font-size: 13px;
}
.file-upload-empty svg { flex-shrink: 0; }

/* --- Confirm Modal -------------------------------------- */
.confirm-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-modal {
  background: #fff;
  border-radius: 10px;
  padding: 28px 32px 24px;
  max-width: 380px;
  width: 90vw;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.confirm-modal-icon { margin-bottom: 12px; }
.confirm-modal-icon svg { color: #dc2626; }
.confirm-modal-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px;
  color: #111827;
}
.confirm-modal-text {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 20px;
  line-height: 1.5;
}
.confirm-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-modal-actions .btn {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
}
.btn-secondary {
  background: #f3f4f6;
  color: #374151;
}
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger {
  background: #dc2626;
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

/* --- Space Cards ------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.card-grid .card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e4e3e0);
  border-radius: var(--r-lg, 12px);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.card-grid .card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-subtle, rgba(0,0,0,0.12));
}

.card-grid .card-header {
  padding: 16px 16px 8px;
  border-bottom: none;
  background: none;
}

.card-grid .card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-grid .card-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.card-grid .card-title a {
  color: var(--text, #0d1117);
  text-decoration: none;
}

.card-grid .card-title a:hover {
  color: var(--accent, #2563eb);
}

.card-grid .card-slug {
  font-size: 0.8rem;
  color: var(--text-muted, #6b7280);
  margin: 4px 0 0;
}

.card-grid .card-description {
  padding: 0 16px 4px;
  font-size: 0.85rem;
  color: var(--text-muted, #6b7280);
  margin: 0;
}

.card-grid .card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
  background: var(--surface-2, #f0eff0);
  border-radius: 0 0 var(--r-lg, 12px) var(--r-lg, 12px);
  display: flex;
  gap: 6px;
}
