/* ══════════════════════════════════════════════════════
   main.css — Dual-theme Design System
   Default: Light Cream  |  .dark: Deep Navy
   ══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Light Theme Tokens (default) ── */
:root {
  --bg:        #f7f4ef;
  --bg-2:      #edeae3;
  --bg-3:      #e5e0d6;
  --surface:   rgba(255,255,255,0.8);
  --surface-hover: rgba(255,255,255,0.95);
  --border:    rgba(0,0,0,0.09);
  --border-strong: rgba(0,0,0,0.15);

  --accent:    #4f46e5;
  --accent-glow: rgba(79,70,229,0.22);
  --accent-2:  #7c3aed;
  --accent-3:  #4f46e5;

  --math-color:     #b45309;
  --physics-color:  #0369a1;
  --business-color: #047857;
  --cs-color:       #be185d;

  --danger:       #dc2626;
  --danger-glow:  rgba(220,38,38,0.2);
  --warn:         #d97706;
  --success:      #059669;

  --text:       #1c1917;
  --text-muted: #6b7280;
  --text-subtle:#9ca3af;

  --radius:    16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow:    0 4px 20px rgba(0,0,0,0.10);
  --shadow-sm: 0 2px 10px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);

  --sidebar-w: 230px;
  --header-h:  60px;

  --font:      'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Flip clock */
  --flip-bg:   #ffffff;
  --flip-text: #1c1917;
  --flip-shadow: 0 4px 16px rgba(0,0,0,0.12);

  /* Charts */
  --chart-grid: rgba(0,0,0,0.06);
  --chart-tick: #9ca3af;
  --chart-tooltip-bg: rgba(255,255,255,0.97);
  --chart-tooltip-border: rgba(0,0,0,0.1);
  --chart-tooltip-text: #1c1917;
  --chart-tooltip-body: #6b7280;
}

/* ── Dark Theme Tokens ── */
body.dark {
  --bg:        #0a0f1e;
  --bg-2:      #0f172a;
  --bg-3:      #1a2235;
  --surface:   rgba(255,255,255,0.05);
  --surface-hover: rgba(255,255,255,0.08);
  --border:    rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);

  --accent:    #6366f1;
  --accent-glow: rgba(99,102,241,0.3);
  --accent-2:  #8b5cf6;
  --accent-3:  #a78bfa;

  --math-color:     #f59e0b;
  --physics-color:  #06b6d4;
  --business-color: #10b981;
  --cs-color:       #ec4899;

  --danger:       #ef4444;
  --danger-glow:  rgba(239,68,68,0.25);
  --warn:         #f59e0b;
  --success:      #10b981;

  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle:#64748b;

  --shadow:    0 8px 32px rgba(0,0,0,0.4);
  --shadow-sm: 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);

  --flip-bg:   #1e2a3a;
  --flip-text: #f1f5f9;
  --flip-shadow: 0 8px 24px rgba(0,0,0,0.6);

  --chart-grid: rgba(255,255,255,0.05);
  --chart-tick: #64748b;
  --chart-tooltip-bg: rgba(15,23,42,0.97);
  --chart-tooltip-border: rgba(255,255,255,0.1);
  --chart-tooltip-text: #f1f5f9;
  --chart-tooltip-body: #94a3b8;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background .3s ease, color .3s ease;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; outline: none; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
select option { background: var(--bg-2); color: var(--text); }
textarea { resize: vertical; }
h1,h2,h3,h4 { font-weight: 700; line-height: 1.2; }

/* ── Utilities ── */
.hidden { display: none !important; }
.optional { color: var(--text-subtle); font-size: 12px; font-weight: 400; }
.helper-text { color: var(--text-subtle); font-size: 12px; margin-top: 5px; }
.modal-body-text { color: var(--text-muted); padding: 0 0 16px; }

/* ── Buttons ── */
.btn {
  align-items: center; border: none; border-radius: var(--radius-sm);
  cursor: pointer; display: inline-flex; font-weight: 600; gap: 6px;
  justify-content: center; padding: 10px 20px; transition: all .2s; white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  box-shadow: 0 2px 12px var(--accent-glow);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 4px 18px var(--accent-glow); }
.btn-primary:active { transform: none; }
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 2px 12px var(--danger-glow); }
.btn-danger:hover { filter: brightness(1.08); }
.btn-full { width: 100%; }
.btn-sm { font-size: 13px; padding: 7px 13px; border-radius: var(--radius-xs); }
.btn-large { font-size: 16px; padding: 13px 28px; border-radius: var(--radius); }
.btn-add { font-size: 15px; }

/* ── Pages ── */
.page { display: none; }
.page.active { display: flex; }
.app-page { display: none; width: 100%; }
.app-page.active { display: block; }

/* ── App shell ── */
#app-shell { display: flex; min-height: 100vh; }
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 32px 36px;
  max-width: calc(100vw - var(--sidebar-w));
  overflow-y: auto;
}

/* ── Page header ── */
.page-header {
  align-items: flex-start; display: flex; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -.4px; }
.page-sub { color: var(--text-muted); font-size: 14px; margin-top: 3px; }
.section-header {
  align-items: center; display: flex; justify-content: space-between;
  margin: 26px 0 12px;
}
.section-title {
  align-items: center; display: flex; font-size: 15px; font-weight: 600;
  gap: 7px; color: var(--text);
}
.section-title svg { width: 16px; height: 16px; color: var(--accent); }
.link-all { color: var(--accent); font-size: 13px; font-weight: 500; }
.link-all:hover { text-decoration: underline; }

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  bottom: 0; display: flex; flex-direction: column; left: 0;
  padding: 20px 14px; position: fixed; top: 0; width: var(--sidebar-w); z-index: 100;
  transition: background .3s, border-color .3s;
}
.sidebar-logo {
  align-items: center; display: flex; gap: 10px; margin-bottom: 28px; padding: 8px 10px;
}
.sidebar-logo-icon { width: 24px; height: 24px; color: var(--accent); flex-shrink: 0; }
.sidebar-logo-text { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.nav-links { list-style: none; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-link {
  align-items: center; border-radius: var(--radius-sm); color: var(--text-muted);
  display: flex; font-weight: 500; gap: 10px; padding: 10px 12px; transition: all .2s;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent);
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { font-size: 14px; }

.sidebar-bottom { padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }

.btn-theme-toggle {
  align-items: center; background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text-muted); cursor: pointer;
  display: flex; font-size: 13px; font-weight: 500; gap: 8px; padding: 9px 12px;
  transition: all .2s; width: 100%;
}
.btn-theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-icon { width: 15px; height: 15px; }

.btn-logout {
  align-items: center; background: none; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text-muted); cursor: pointer;
  display: flex; font-size: 14px; font-weight: 500; gap: 8px; padding: 10px 12px;
  transition: all .2s; width: 100%;
}
.btn-logout:hover { background: rgba(220,38,38,.08); border-color: var(--danger); color: var(--danger); }
.btn-logout svg, .btn-theme-toggle svg { width: 15px; height: 15px; }

/* ── Mobile header ── */
.mobile-header {
  display: none; align-items: center; background: var(--surface);
  border-bottom: 1px solid var(--border); height: var(--header-h);
  justify-content: space-between; left: 0; padding: 0 16px;
  position: fixed; right: 0; top: 0; z-index: 99; backdrop-filter: blur(12px);
}
.mobile-icon-btn { background: none; border: none; color: var(--text); cursor: pointer; font-size: 20px; padding: 6px; display: flex; }
.mobile-title { font-size: 16px; font-weight: 700; }

/* ── Modals ── */
.modal-overlay {
  align-items: center; background: rgba(0,0,0,0.3); backdrop-filter: blur(6px);
  bottom: 0; display: flex; justify-content: center; left: 0; padding: 20px;
  position: fixed; right: 0; top: 0; z-index: 200; animation: fadeIn .2s ease;
}
body.dark .modal-overlay { background: rgba(0,0,0,0.6); }

.modal {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto; padding: 28px;
  width: 100%; max-width: 500px; animation: slideUp .25s ease;
}
.modal-sm { max-width: 380px; }
.modal-header { align-items: center; display: flex; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 17px; }
.modal-close {
  background: none; border: none; border-radius: var(--radius-xs); color: var(--text-muted);
  cursor: pointer; display: flex; padding: 5px; transition: all .15s;
}
.modal-close:hover { background: var(--bg-2); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px;
  color: var(--text-muted); letter-spacing: .4px; text-transform: uppercase;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.login-error {
  background: rgba(220,38,38,.08); border: 1px solid rgba(220,38,38,.25);
  border-radius: var(--radius-sm); color: var(--danger); font-size: 13px;
  margin-bottom: 14px; padding: 10px 14px;
}

/* Input with icon */
.input-icon-wrap { position: relative; }
.input-icon-wrap input { padding-left: 40px; }
.input-icon {
  left: 13px; position: absolute; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-subtle); pointer-events: none;
}

/* ── Toast ── */
.toast-container {
  bottom: 24px; display: flex; flex-direction: column; gap: 10px;
  position: fixed; right: 24px; z-index: 500;
}
.toast {
  align-items: center; background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); color: var(--text);
  display: flex; font-size: 14px; font-weight: 500; gap: 10px;
  padding: 12px 18px; min-width: 250px; animation: slideLeft .3s ease;
}
.toast svg { width: 17px; height: 17px; }
.toast.success { border-color: rgba(5,150,105,.35); }
.toast.success svg { color: var(--success); }
.toast.error { border-color: rgba(220,38,38,.35); }
.toast.error svg { color: var(--danger); }

/* ── Filters row ── */
.filters-row {
  align-items: center; display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
}
.filter-select { max-width: 180px; width: auto; }
.filter-input { max-width: 155px; }

/* ── Empty state ── */
.empty-state {
  align-items: center; color: var(--text-subtle); display: flex; flex-direction: column;
  gap: 10px; padding: 48px; text-align: center;
}
.empty-icon-svg { width: 38px; height: 38px; opacity: .5; }

/* ── Animations ── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes slideLeft { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .3s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; max-width: 100%; padding: 76px 16px 24px; }
  .form-row { grid-template-columns: 1fr; }
}
