:root {
  --bg: #f3f4f6;
  --bg-card: #fff;
  --sidebar: #fff;
  --surface: #f8fafc;
  --header: rgba(255,255,255,.86);
  --text: #0f172a;
  --muted: #475569;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --accent: #14b8a6;
  --accent-light: #ccfbf1;
  --accent-dark: #0d9488;
  --blue: #3b82f6;
  --green: #10b981;
  --coral: #f43f5e;
  --amber: #f59e0b;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  --sidebar-width: 240px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1118;
  --bg-card: #121c26;
  --sidebar: #0f1720;
  --surface: #172330;
  --header: rgba(15,23,32,.9);
  --text: #f1f5f9;
  --muted: #cbd5e1;
  --faint: #8fa2b8;
  --border: #263442;
  --border-light: #1b2835;
  --accent-light: #123936;
  --accent-dark: #5eead4;
  --shadow: 0 1px 2px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font); }
a { color: inherit; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); height: 100vh;
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 20px 12px;
  display: flex; flex-direction: column; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--accent-light); color: var(--accent-dark); font-weight: 800; font-size: 12px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--faint); font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.sidebar nav a:hover { background: var(--border-light); color: var(--text); }
.sidebar nav a.active { background: var(--accent-light); color: var(--accent-dark); }
.sidebar nav span { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 5px; background: var(--surface); color: var(--faint); font-size: 10px; font-weight: 800; }
.sidebar-footer { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border-light); display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--blue)); color: white; font-size: 12px; font-weight: 800; }
.sidebar-footer strong { display: block; font-size: 12px; }
.sidebar-footer small { display: block; color: var(--faint); font-size: 10px; }

.main { margin-left: var(--sidebar-width); min-height: 100vh; padding: 24px 32px; }
.main-auth { margin-left: 0; padding: 24px; }
.topbar { height: 64px; margin: -24px -32px 24px; padding: 0 32px; position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--header); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.topbar p { margin: 2px 0 0; color: var(--faint); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.theme-switch { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); }
.theme-switch button { width: 32px; height: 32px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.theme-switch button.active { background: var(--accent-light); color: var(--accent-dark); }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 14px; border: 1px solid transparent; border-radius: var(--radius-sm); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn-primary { background: #0f172a; color: #fff; }
[data-theme="dark"] .btn-primary { background: var(--accent); color: #062522; }
.btn-secondary { border-color: var(--border); background: var(--bg-card); color: var(--muted); }
.alert { padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text); }
.alert.success { border-color: rgba(16,185,129,.35); }
.alert.warning { border-color: rgba(245,158,11,.45); }
.alert.danger { border-color: rgba(244,63,94,.45); }

.auth-shell { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth-brand { padding: 0 0 12px; }
.muted { color: var(--faint); font-size: 12px; }

label { color: var(--muted); font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 36px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text); font: inherit; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.check { display: inline-flex; align-items: center; gap: 6px; }
.check input { width: auto; min-height: auto; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { min-height: 118px; padding: 20px; position: relative; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi strong { display: block; margin-top: 8px; font-size: 30px; line-height: 1; }
.kpi i { position: absolute; right: 20px; top: 20px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--accent-light); color: var(--accent-dark); font-style: normal; font-weight: 800; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 16px; }
.section-head h2, .form-card h2, .table-card h2 { margin: 0; font-size: 18px; }
.section-head p { margin: 4px 0 0; color: var(--faint); font-size: 13px; }
.system-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.system-card { min-height: 190px; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; gap: 16px; }
.system-code { color: var(--accent-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.system-card h3 { margin: 8px 0 6px; font-size: 18px; }
.system-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.form-card, .filters-card { padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 520px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 14px; }
.table-card { overflow: hidden; }
.table-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-light); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 12px 16px; text-align: left; color: var(--faint); font-size: 11px; font-weight: 800; text-transform: uppercase; border-bottom: 1px solid var(--border-light); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
tr:hover td { background: var(--border-light); }
td input, td select { min-width: 140px; margin-bottom: 6px; }
.badge { display: inline-flex; padding: 3px 10px; border-radius: 999px; background: var(--accent-light); color: var(--accent-dark); font-size: 11px; font-weight: 800; }
.empty { color: var(--faint); text-align: center; padding: 28px; }

.toggle { display: inline-flex; margin-bottom: 4px; }
.toggle input { display: none; }
.toggle span { width: 34px; height: 20px; border-radius: 999px; background: var(--border); position: relative; }
.toggle span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 2px; left: 2px; border-radius: 50%; background: white; transition: transform .15s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); }

.mobile-nav, .overlay { display: none; }
@media (max-width: 800px) {
  .mobile-nav { display: grid; place-items: center; position: fixed; top: 14px; left: 12px; z-index: 180; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text); }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .overlay { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.42); z-index: 90; }
  .main { margin-left: 0; padding: 16px; }
  .topbar { margin: -16px -16px 16px; padding: 0 16px 0 56px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
}
