:root {
  --primary-color: #1a2f4e;
  --primary-color-buttons: #254678;
  --primary-light: #e3ecf9;
  --primary-500: #1a2f4e;
  --primary-400: #2b4d80;
  --primary-300: #3d66a4;
  --primary-200: #6d8fc0;
  --primary-100: #d0deef;
  --accent-color: #10B981;
  --accent-500: #34D399;
  --bg-color: #ffffff;
  --bg-secondary: #F6F9FC;
  --dark-bg: #F3F7FB;
  --dark-surface: #EEF3F7;
  --light-bg: #E9F1F9;
  --text-color: #0B1220;
  --text-secondary: #4B5563;
  --light-text: #999;
  --timestamp-color: #6B7280;
  --success-color: #16A34A;
  --danger-color: #DC2626;
  --warning-color: #B45309;
  --info-color: #0284C7;
  --neutral-900: #0F172A;
  --neutral-50: #FFFFFF;
  --border-color: #E6EDF5;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.08);
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --space-2xs: 2px;
  --space-xs: 6px;
  --space-sm: 10px;
  --space-md: 14px;
  --space-lg: 20px;
  --space-xl: 28px;
  --header-height: 56px;
  --footer-height: 0px;
  --toc-extra: 48px;
  --font-family: 'Bookerly', 'Iowan Old Style', 'Palatino Linotype', Palatino, 'URW Palladio L', 'Literata', 'Spectral', 'Merriweather', Georgia, 'Noto Serif', serif;
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.3s ease-in-out;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-fg: #ffffff;
  --header-fg-muted: rgba#f9fafb;
  --header-fg-dim: rgba(255,255,255,0.65);
  --header-hover-bg: rgba(255,255,255,0.12);
  --header-border: rgba(255,255,255,0.18);
  --font-sans: 'Amazon Ember', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, 'Noto Sans', sans-serif;
  --font-serif-reading: 'Bookerly', 'Iowan Old Style', 'Palatino Linotype', Palatino, 'URW Palladio L', 'Literata', 'Spectral', 'Merriweather', Georgia, 'Noto Serif', serif;
  --font-serif-slab: 'Caecilia', 'Roboto Slab', 'Arvo', 'Zilla Slab', 'PT Serif', Georgia, serif;
  --font-sans-neutral: 'Helvetica Neue', Helvetica, Arial, 'Inter', system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  --reading-font-size: 1.0625rem;
  --reading-line-height: 1.6;
  --reading-measure: 66ch;
}

body.theme-teal {
  --primary-color: #14b8a6;
  --primary-color-buttons: #0ea5a3;
  --primary-light: #99f6e4;
  --accent-color: #06b6d4;
  --bg-secondary: #f0fdfa;
  --text-color: #0f766e;
}
body.theme-purple {
  --primary-color: #a855f7;
  --primary-color-buttons: #9333ea;
  --primary-light: #f3e8ff;
  --accent-color: #ec4899;
  --bg-secondary: #faf5ff;
  --text-color: #581c87;
}
body.theme-indigo {
  --primary-color: #6366f1;
  --primary-color-buttons: #4f46e5;
  --primary-light: #e0e7ff;
  --accent-color: #3b82f6;
  --bg-secondary: #eef2ff;
  --text-color: #3730a3;
}
body.theme-emerald {
  --primary-color: #10b981;
  --primary-color-buttons: #059669;
  --primary-light: #a7f3d0;
  --accent-color: #f59e0b;
  --bg-secondary: #ecfdf5;
  --text-color: #065f46;
}
body.theme-amber {
  --primary-color: #f59e0b;
  --primary-color-buttons: #d97706;
  --primary-light: #fef3c7;
  --accent-color: #ef4444;
  --bg-secondary: #fffbeb;
  --text-color: #92400e;
}
body.theme-rose {
  --primary-color: #f43f5e;
  --primary-color-buttons: #e11d48;
  --primary-light: #ffe4e6;
  --accent-color: #a855f7;
  --bg-secondary: #fff1f2;
  --text-color: #9f1239;
}

body { font-family: var(--font-family); }

body.font-sans { --font-family: var(--font-sans); }
body.font-serif { --font-family: var(--font-serif-reading); }
body.font-serif-slab { --font-family: var(--font-serif-slab); }
body.font-neutral { --font-family: var(--font-sans-neutral); }
body.font-mono { --font-family: var(--font-mono); }
body.font-bookerly { --font-family: 'Bookerly', var(--font-serif-reading); }
body.font-ember { --font-family: 'Amazon Ember', var(--font-sans); }

.reading-area {
  font-family: var(--font-serif-reading);
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
  max-width: var(--reading-measure);
}

.code, pre, code, kbd, samp { font-family: var(--font-mono); }


/* --- Global Styles & Resets --- */
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  color: var(--text-color);
  font: 400 15px/1.55 var(--font-family);
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
::selection { background: var(--primary-200); }
:focus-visible { outline: 2px solid var(--primary-300); outline-offset: 2px; border-radius: 4px; }


/* --- Layout --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-height);
  display: flex; /* Changed to flexbox for better alignment */
  align-items: center;
  justify-content: space-between; /* Pushes left and right apart */
  padding: 0 var(--space-lg);
  color: var(--header-fg-muted);
  background: #131921;
  border-bottom: 1px solid var(--header-border);
  backdrop-filter: saturate(1.5) blur(8px);
  -webkit-backdrop-filter: saturate(1.5) blur(8px);
  flex: 0 0 var(--header-height);
  box-sizing: border-box;
}
.app-header .brand,
.app-header .site-title {
  color: var(--header-fg);
}
.app-header .site-title {
  color: var(--header-fg);
}

.header-left { display: flex; align-items: center; gap: var(--space-sm); }
.brand { display: flex; align-items: center; gap: var(--space-sm); }
.brand-logo { height: 38px; width: 38px; border-radius: 10px; object-fit: contain; }
.site-title { margin: 0; font-size: 1.1rem; font-weight: 700; letter-spacing: .2px; }

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm); /* Tighter gap between main elements */
  color: rgba(255, 255, 255, 0.8); 
}

/* Unified style for all header buttons/links */
.header-link, .dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--header-fg);
  background-color: transparent;
  border: none;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.header-link:hover, .dropdown.active .dropdown-toggle {
  background-color: var(--header-hover-bg);
}

.header-link i {
  font-size: 1rem;
  color: var(--header-fg-muted);
}

.app-header .desktop-nav > .dropdown-item {
  color: var(--header-fg);
  background: transparent;
  border: 1px solid transparent;
}
.app-header .desktop-nav > .dropdown-item:hover {
  background: var(--header-hover-bg);
}
.app-header .desktop-nav > .dropdown-item i.fa-fw {
  color: var(--header-fg-muted);
  opacity: 1;
}

.dropdown-chevron {
  color: var(--header-fg-dim);
}
.dropdown.active .dropdown-toggle,
.dropdown.active .profile-pic-btn {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.22);
}

.app-header .profile-pic {
  border: 2px solid rgba(255,255,255,0.35);
}

.app-header .header-icon {
  border-color: transparent;
  background: transparent;
  color: var(--header-fg);
}
.app-header .header-icon:hover {
  background: var(--header-hover-bg);
  box-shadow: none;
}

.dropdown {
  position: relative;
}

.profile-pic-btn {
  padding: 0;
  border-radius: 50%;
  display: flex;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.profile-pic-btn:hover {
    transform: scale(1.05);
}

.dropdown.active .profile-pic-btn {
    box-shadow: 0 0 0 3px var(--primary-200);
}

.profile-pic {
  height: 38px; 
  width: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-color);
}

.dropdown-chevron {
  font-size: 0.65em;
  margin-left: 2px;
  transition: transform var(--transition-fast);
  color: var(--text-secondary);
}

.dropdown.active .dropdown-chevron {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 12px;
  z-index: 1100;
  max-width: 280px; 
  background: var(--neutral-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  min-width: 240px;
  padding: var(--space-xs);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.dropdown-header .username,
.dropdown-header .email {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-menu-right {
  right: 0;
  left: auto;
}

.dropdown.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-header {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
}
.dropdown-header .username {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-color);
}
.dropdown-header .email {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.dropdown-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-xs) 0;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  padding: 10px var(--space-md);
  border-radius: var(--radius-md);
  text-align: left;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-color);
  background: none;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-item i.fa-fw {
  width: 18px;
  text-align: center;
  font-size: 1rem;
  color: var(--primary-color);
  opacity: 0.7;
}

.dropdown-item:hover {
  background-color: var(--dark-bg);
}

.dropdown-item-danger:hover {
  background-color: #fee2e2;
  color: var(--danger-color);
}
.dropdown-item-danger:hover i {
  color: var(--danger-color);
}

.main-content {
  flex: 1 1 auto;
  padding: var(--space-lg);
  background: var(--bg-secondary);
  min-height: 0;
  box-sizing: border-box;
  max-height: calc(100vh - var(--header-height) - var(--footer-height));
}
.page-container > :last-child { margin-bottom: 0; }

.footer {
  flex: 0 0 var(--footer-height);
  min-height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-lg);
  border-top: 1px solid var(--border-color);
  background: var(--neutral-50);
  color: var(--text-secondary);
  text-align: center;
  padding-bottom: var(--safe-bottom);
  box-sizing: border-box;
}
.footer p { margin: 0; }
.container { width: min(1100px, 92vw); margin: 0 auto; }

/* --- Components --- */
.btn, .header-icon {
  appearance: none;
  border: 1px solid var(--border-color);
  background: var(--neutral-50);
  color: var(--text-color);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
}
.btn:hover, .header-icon:hover {
  transform: translateY(-1px);
  background: var(--dark-bg);
  box-shadow: var(--shadow-sm);
}

.btn-primary { background: var(--primary-color-buttons); color: #fff; border-color: transparent; }
.btn-primary:hover {
  background: var(--primary-color-buttons);
  filter: brightness(90%);
  color: #fff;
}
.btn-danger { background: var(--danger-color); color: #fff; border-color: transparent; }
.btn-danger:hover {
  background: var(--danger-color);
  filter: brightness(90%);
  color: #fff;
}

.profile-pic {
  height: 32px; width: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.card {
  background: var(--neutral-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-lg);
}

pre, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
pre {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow: auto;
}

/* --- Forms --- */
form { display: grid; gap: var(--space-md); }
label { font-weight: 600; color: var(--text-secondary); }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--neutral-50);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  box-sizing: border-box;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary-300);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-300) 20%, transparent);
}
.price-preview {
  text-align: center;
  font-weight: 600;
  margin: -4px 0 8px;
  color: var(--text-secondary);
}

/* --- Modals --- */
.modal, .settings-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: rgba(15, 23, 42, 0.35);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal .modal-content {
  width: min(300px, 94vw);
  background: var(--neutral-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
  position: relative;
}

.close-modal {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--neutral-50);
  cursor: pointer;
  line-height: 1;
}

.settings-modal-container {
  width: min(250px, 94vw);
  background: var(--neutral-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.settings-modal-header,
.settings-modal-footer {
  padding: var(--space-md) var(--space-lg);
  background: var(--dark-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-modal-footer {
  border-top: 1px solid var(--border-color);
  border-bottom: none;
}

.settings-modal-body { padding: var(--space-lg); }

.settings-modal-header h2 { margin: 0; }


/* --- Utilities & Animations --- */
.text-center { text-align: center; }
.w-100 { width: 100%; }
.hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.card, .modal-content, .settings-modal-container {
  animation: fadeUp 0.25s ease both;
}

/* --- Scrollbar --- */
* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
*::-webkit-scrollbar-track { background: transparent; }

.mobile-nav-trigger {
  display: none;
}
.mobile-nav-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background-color: var(--neutral-50);
  z-index: 1200;
  box-shadow: -5px 0 25px rgba(15, 23, 42, 0.1);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex;
  flex-direction: column;
}
body.mobile-nav-open .mobile-nav-panel {
  transform: translateX(0);
}
body.mobile-nav-open .overlay {
  opacity: 1;
  visibility: visible;
  z-index: 1199;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.mobile-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--space-xs) 0 var(--space-sm);
  height: var(--header-height);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.mobile-nav-title {
  font-size: 0.95rem;
  font-weight: 600;
}

#mobileNavClose {
  font-size: 1.25rem;
  font-weight: 300;
}

.mobile-nav-content {
  padding: var(--space-sm);
  overflow-y: auto;
  flex-grow: 1;
}

.mobile-nav-profile {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px 0;
}

.mobile-nav-profile .profile-pic {
  width: 44px;
  height: 44px;
}

.mobile-nav-profile .profile-info {
  line-height: 1.3;
  min-width: 0;
}

.mobile-nav-profile .username,
.mobile-nav-profile .email {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.mobile-nav-link {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  transition: background-color 0.2s ease;
  line-height: 1.35;
}

.mobile-nav-link:hover {
  background-color: var(--dark-bg);
}

.mobile-nav-link-danger {
  color: var(--danger-color);
}

.flash-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flash-message {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 320px;
  padding: 12px 16px;
  border-radius: 10px;
  color: white;
  font-weight: 500;
  font-size: 0.95rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  animation: fadeInOut 5s ease forwards;
  opacity: 0;
}

.flash-success   { background-color: var(--success-color, #16A34A); }
.flash-danger    { background-color: var(--danger-color, #DC2626); }
.flash-warning   { background-color: var(--warning-color, #B45309); }
.flash-info      { background-color: var(--info-color, #0284C7); }

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(10px); }
  10%  { opacity: 1; transform: translateY(0); }
  90%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(10px); }
}

@media (max-width: 992px) {
  .desktop-nav {
    display: none;
  }
  .mobile-nav-trigger {
    display: block;
  }
}