/* ── Reset & Base ─────────────────────────────────────────────────────────── */

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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.52;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

ul, ol { list-style: none; }

button, input, select, textarea {
  font: inherit;
}

/* ── CSS Variables: Light Theme ───────────────────────────────────────────── */

:root {
  /* Colors */
  --color-accent:        #f0a500;
  --color-accent-hover:  #d99400;
  --color-accent-light:  rgba(240,165,0,0.10);
  --color-danger:        #e53e3e;
  --color-danger-hover:  #c53030;
  --color-danger-light:  #fff5f5;
  --color-success:       #38a169;
  --color-success-light: #f0fff4;
  --color-warning:       #d69e2e;
  --color-warning-light: #fffbeb;
  --color-info:          #3182ce;
  --color-info-light:    #ebf8ff;

  /* Backgrounds — slightly warmer, less “clinical” gray */
  --bg-primary:   #f3f4f8;
  --bg-secondary: #ffffff;
  --bg-tertiary:  #eceff5;
  --bg-hover:     #e8ebf2;

  /* Text — a bit softer contrast for long sessions */
  --text-primary:   #161822;
  --text-secondary: #5c6578;
  --text-muted:     #9199a8;
  --text-inverse:   #ffffff;

  /* Borders */
  --border-color:        #e4e8ef;
  --border-color-strong: #cfd6e0;

  /* Table: very subtle stripe (easier to scan rows) */
  --table-stripe: rgba(15, 23, 42, 0.028);
  --border-radius-sm:    3px;
  --border-radius:       5px;
  --border-radius-lg:    6px;
  --border-radius-xl:    8px;

  /* Shadows — lighter edge, less “floating card” */
  --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow:     0 4px 14px rgba(15, 23, 42, 0.07);
  --shadow-lg:  0 8px 28px rgba(15, 23, 42, 0.09);

  /* Sidebar */
  --sidebar-width:    220px;
  --sidebar-bg:       #1e2235;
  --sidebar-text:     #a8b1cc;
  --sidebar-active:   #f0a500;
  --sidebar-hover-bg: rgba(255,255,255,.06);

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Layout */
  --topbar-height: 56px;
}

/* ── CSS Variables: Dark Theme ────────────────────────────────────────────── */

[data-theme="dark"] {
  --color-accent-light:  rgba(240,165,0,0.10);
  --color-danger-light:  rgba(229,62,62,.12);
  --color-success-light: rgba(56,161,105,.12);
  --color-warning-light: rgba(214,158,46,.12);
  --color-info-light:    rgba(49,130,206,.12);

  --bg-primary:   #12141c;
  --bg-secondary: #1a1d2e;
  --bg-tertiary:  #22263a;
  --bg-hover:     #2a2f45;

  --text-primary:   #e8eaf0;
  --text-secondary: #949bb0;
  --text-muted:     #7d8499;
  --text-inverse:   #1a1d2e;

  --border-color:        #2f3448;
  --border-color-strong: #3d435c;

  --table-stripe: rgba(255, 255, 255, 0.034);

  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow:     0 4px 12px rgba(0,0,0,.4);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.5);

  --sidebar-bg:       #111320;
  --sidebar-text:     #9ba5c2;
  --sidebar-hover-bg: rgba(255,255,255,.04);
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.2s ease, width 0.2s ease;
}

/* Sidebar collapsed (hidden by default, open via menu button) */
.app-layout.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.app-layout.sidebar-collapsed .main-area {
  margin-left: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

@media (max-width: 899px) {
  .app-layout:not(.sidebar-collapsed) .sidebar-overlay {
    display: block;
  }
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-md);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.3px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-logo svg { flex-shrink: 0; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 9px var(--space-md);
  color: var(--sidebar-text);
  font-size: .9rem;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover-bg);
  color: #fff;
}

.sidebar-nav a.active {
  color: #fff;
  background: rgba(240,165,0,0.12);
  border-left: 3px solid var(--sidebar-active);
  padding-left: calc(var(--space-md) - 3px);
}

.sidebar-nav a svg { opacity: .7; flex-shrink: 0; }
.sidebar-nav a.active svg,
.sidebar-nav a:hover svg { opacity: 1; }

.sidebar-section-label {
  padding: var(--space-md) var(--space-md) var(--space-xs);
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.25);
}

.sidebar-footer {
  padding: var(--space-md);
  border-top: 1px solid rgba(255,255,255,.07);
}

/* Main area */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

/* Page content */
.page-content {
  flex: 1;
  padding: var(--space-lg);
}

/* ── Utilities ────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.flex-1 { flex: 1; }

.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.text-muted { color: var(--text-secondary); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.w-full { width: 100%; }

.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  margin-bottom: var(--space-md);
  opacity: .4;
}
