:root {
  --brand:          #534AB7;
  --brand-light:    #7F77DD;
  --brand-dark:     #3C3489;
  --brand-bg:       #EEEDFE;
  --brand-border:   #CECBF6;

  --bg-page:        #f5f5f8;
  --bg-card:        #ffffff;
  --bg-inner:       #f0f0f5;
  --border:         #e0dff0;
  --border-strong:  #c8c7e0;

  --text-primary:   #1a1a2e;
  --text-secondary: #555570;
  --text-muted:     #888899;
  --text-brand:     #534AB7;

  --green-bg:       #0F6E56;
  --green-text:     #9FE1CB;
  --red-bg:         #A32D2D;
  --red-text:       #F7C1C1;
  --amber-bg:       #854F0B;
  --amber-text:     #FAC775;

  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      14px;
  --radius-pill:    999px;

  --shadow-sm:      0 1px 3px rgba(0,0,0,0.06);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.08);

  --nav-h:          52px;
  --sidebar-w:      220px;
  --font:           'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg-page:        #12111f;
  --bg-card:        #1c1b30;
  --bg-inner:       #0e0d1e;
  --border:         #2e2d4a;
  --border-strong:  #3e3d5a;

  --text-primary:   #e8e8f4;
  --text-secondary: #9999bb;
  --text-muted:     #666688;
  --text-brand:     #AFA9EC;

  --brand-bg:       #26215C;
  --brand-border:   #3C3489;
}

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

html { font-size: 15px; }

body {
  font-family:      var(--font);
  background:       var(--bg-page);
  color:            var(--text-primary);
  line-height:      1.6;
  min-height:       100vh;
  transition:       background 0.2s, color 0.2s;
}

/* ── Typography ───────────────────────────────── */
h1 { font-size: 1.5rem;  font-weight: 600; }
h2 { font-size: 1.2rem;  font-weight: 600; }
h3 { font-size: 1rem;    font-weight: 600; }
p  { color: var(--text-secondary); }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--nav-h) 1fr;
  min-height: 100vh;
}

/* ── Nav ──────────────────────────────────────── */
.nav {
  grid-column: 1 / -1;
  background:    var(--brand);
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  padding:       0 1.25rem;
  height:        var(--nav-h);
  position:      sticky;
  top:           0;
  z-index:       100;
}
.nav-brand {
  display:     flex;
  align-items: center;
  gap:         10px;
  color:       #EEEDFE;
  font-weight: 600;
  font-size:   0.95rem;
}
.nav-brand .icon {
  width:           28px;
  height:          28px;
  border-radius:   var(--radius-sm);
  background:      rgba(255,255,255,0.15);
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       15px;
}
.nav-right {
  display:     flex;
  align-items: center;
  gap:         14px;
}
.nav-user {
  font-size: 0.85rem;
  color:     #CECBF6;
}
.nav-avatar {
  width:           32px;
  height:          32px;
  border-radius:   50%;
  background:      rgba(255,255,255,0.15);
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       12px;
  font-weight:     600;
  color:           #EEEDFE;
}
.theme-toggle {
  background:    none;
  border:        1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  color:         #EEEDFE;
  padding:       4px 8px;
  font-size:     13px;
  cursor:        pointer;
}

/* ── Sidebar ──────────────────────────────────── */
.sidebar {
  background:   var(--bg-card);
  border-right: 1px solid var(--border);
  padding:      1rem 0;
  position:     sticky;
  top:          var(--nav-h);
  height:       calc(100vh - var(--nav-h));
  overflow-y:   auto;
}
.sidebar-section {
  padding: 0.5rem 0;
}
.sidebar-label {
  font-size:      0.7rem;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color:          var(--text-muted);
  padding:        0.5rem 1rem 0.25rem;
}
.sidebar a {
  display:       flex;
  align-items:   center;
  gap:           8px;
  padding:       0.5rem 1rem;
  color:         var(--text-secondary);
  font-size:     0.9rem;
  border-radius: 0;
  transition:    background 0.15s, color 0.15s;
}
.sidebar a:hover { background: var(--bg-inner); color: var(--text-primary); text-decoration: none; }
.sidebar a.active { background: var(--brand-bg); color: var(--brand); font-weight: 500; }
.sidebar a i { font-size: 16px; width: 18px; }
.sidebar-divider { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0; }

/* ── Main content ─────────────────────────────── */
.main {
  padding:    1.5rem;
  overflow-y: auto;
}
.page-header {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { color: var(--text-primary); }
.page-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ────────────────────────────────────── */
.card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       1.25rem;
  box-shadow:    var(--shadow-sm);
}
.card-title {
  font-size:     0.7rem;
  font-weight:   600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color:         var(--text-brand);
  margin-bottom: 0.5rem;
}

/* ── Stat cards ───────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background:    var(--bg-inner);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  padding:       1rem 1.25rem;
}
.stat-label {
  font-size:      0.7rem;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color:          var(--text-brand);
  margin-bottom:  4px;
}
.stat-value {
  font-size:   1.6rem;
  font-weight: 600;
  color:       var(--text-primary);
  line-height: 1;
}
.stat-sub {
  font-size:   0.8rem;
  color:       var(--text-muted);
  margin-top:  4px;
}

/* ── Tables ───────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border:     1px solid var(--border);
  border-radius: var(--radius-lg);
}
table {
  width:           100%;
  border-collapse: collapse;
  font-size:       0.875rem;
}
thead th {
  background:     var(--bg-inner);
  padding:        0.65rem 1rem;
  text-align:     left;
  font-size:      0.7rem;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color:          var(--text-muted);
  border-bottom:  1px solid var(--border);
}
tbody td {
  padding:       0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color:         var(--text-primary);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-inner); }

/* ── Badges ───────────────────────────────────── */
.badge {
  display:       inline-flex;
  align-items:   center;
  gap:           4px;
  padding:       3px 10px;
  border-radius: var(--radius-pill);
  font-size:     0.75rem;
  font-weight:   500;
}
.badge-green  { background: var(--green-bg);  color: var(--green-text); }
.badge-red    { background: var(--red-bg);    color: var(--red-text); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber-text); }
.badge-brand  { background: var(--brand-bg);  color: var(--text-brand); border: 1px solid var(--brand-border); }
.badge-gray   { background: var(--bg-inner);  color: var(--text-muted); border: 1px solid var(--border); }

/* ── Buttons ──────────────────────────────────── */
.btn {
  display:       inline-flex;
  align-items:   center;
  gap:           6px;
  padding:       0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size:     0.875rem;
  font-weight:   500;
  cursor:        pointer;
  border:        none;
  transition:    opacity 0.15s, transform 0.1s;
}
.btn:hover   { opacity: 0.88; }
.btn:active  { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-brand); border: 1px solid var(--brand-border); }
.btn-danger  { background: var(--red-bg); color: var(--red-text); }
.btn-sm      { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* ── Forms ────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display:     block;
  font-size:   0.8rem;
  font-weight: 500;
  color:       var(--text-secondary);
  margin-bottom: 5px;
}
.form-control {
  width:         100%;
  padding:       0.5rem 0.75rem;
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-md);
  color:         var(--text-primary);
  font-size:     0.9rem;
  font-family:   var(--font);
  transition:    border-color 0.15s;
}
.form-control:focus {
  outline:      none;
  border-color: var(--brand);
}
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 80px; resize: vertical; }

/* ── Alerts ───────────────────────────────────── */
.alert {
  padding:       0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size:     0.875rem;
  margin-bottom: 1rem;
}
.alert-info    { background: var(--brand-bg); color: var(--text-brand); border: 1px solid var(--brand-border); }
.alert-success { background: #0F6E5620; color: var(--green-text); border: 1px solid #0F6E56; }
.alert-danger  { background: #A32D2D20; color: var(--red-text); border: 1px solid var(--red-bg); }

/* ── Utilities ────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.gap-sm       { gap: 0.5rem; }
.gap-md       { gap: 1rem; }
.mt-1         { margin-top: 0.5rem; }
.mt-2         { margin-top: 1rem; }
.mt-3         { margin-top: 1.5rem; }
.mb-2         { margin-bottom: 1rem; }
.text-muted   { color: var(--text-muted); font-size: 0.85rem; }
.text-right   { text-align: right; }
.w-100        { width: 100%; }
.key-display  {
  font-family:   monospace;
  font-size:     0.85rem;
  background:    var(--bg-inner);
  padding:       2px 8px;
  border-radius: var(--radius-sm);
  border:        1px solid var(--border);
  color:         var(--text-primary);
}
