/* ==========================================================================
   CRUD Admin Starter - stylesheet
   Original design, no third-party CSS framework. Colours live in the tokens
   below; change --accent to re-brand the whole app.
   ========================================================================== */

:root {
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ink: #ffffff;

  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e7ef;
  --border-strong: #d3d8e4;
  --text: #171a26;
  --text-2: #4b5165;
  --muted: #7a8196;

  --sidebar-bg: #11131c;
  --sidebar-text: #aeb3c5;
  --sidebar-hover: #1b1e2b;
  --sidebar-active: #252a3d;

  --green: #16a34a;  --green-soft: #e8f7ee;
  --amber: #c2780a;  --amber-soft: #fdf3e2;
  --red: #dc2626;    --red-soft: #fdecec;
  --blue: #0284c7;   --blue-soft: #e5f4fb;
  --gray-soft: #eef0f4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 40, .04), 0 4px 16px rgba(16, 20, 40, .05);
  --shadow-lg: 0 20px 50px rgba(16, 20, 40, .18);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --sidebar-w: 248px;
}

:root[data-theme="dark"] {
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: #23264a;
  --accent-ink: #0d0f1a;

  --bg: #0d0f16;
  --surface: #151823;
  --surface-2: #1a1e2b;
  --border: #262b3b;
  --border-strong: #333a4f;
  --text: #e8eaf2;
  --text-2: #b6bbcc;
  --muted: #858ca3;

  --sidebar-bg: #0a0b11;
  --sidebar-hover: #141722;
  --sidebar-active: #1d2131;

  --green: #4ade80;  --green-soft: #13291d;
  --amber: #fbbf24;  --amber-soft: #2d2410;
  --red: #f87171;    --red-soft: #321518;
  --blue: #38bdf8;   --blue-soft: #0f2533;
  --gray-soft: #222736;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);
}

:root[data-theme="dark"] { color-scheme: dark; }
.only-dark { display: none; }
:root[data-theme="dark"] .only-dark { display: block; }
:root[data-theme="dark"] .only-light { display: none; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none;
        stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; }
.nav { padding: 6px 12px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #646a80; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; margin: 2px 0;
  border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #6366f1; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid #1f2230; font-size: 12px; color: #646a80; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: 64px;
  display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.menu-btn { display: none; }

.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
  font: inherit;
}
.user-chip small { display: block; color: var(--muted); font-size: 11px; line-height: 1.1; text-align: left; }
.user-chip strong { display: block; font-size: 13px; line-height: 1.2; text-align: left; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); display: none;
}
.dropdown.open { display: block; }
.dropdown button, .dropdown a {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0;
  background: none; color: var(--text); font: inherit; border-radius: 8px; cursor: pointer; text-align: left;
}
.dropdown button:hover, .dropdown a:hover { background: var(--surface-2); }

.content { padding: 28px; max-width: 1320px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Avatars ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: 12px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #6366f1, #0ea5e9);
}
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card-body { padding: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; }
.stat-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.stat-icon svg { width: 20px; height: 20px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tone-indigo { background: var(--accent-soft); color: var(--accent); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }

/* Bar chart made of plain HTML, no chart library needed */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 36px; align-items: center; gap: 12px; font-size: 13px; }
.bar-row .name { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; border-radius: 99px; background: var(--gray-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; min-width: 4px; }
.bar-row .num { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: 12px; color: var(--muted); }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 34px; }
.toolbar .select { width: auto; min-width: 150px; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Forms ---------- */
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 104px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--red); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field .req { color: var(--red); margin-left: 2px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field .error { font-size: 12px; color: var(--red); margin-top: 5px; }
.input-group { display: flex; }
.input-group .addon {
  display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--border-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface-2); color: var(--muted);
}
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.color-field { display: flex; gap: 10px; align-items: center; }
.color-field input[type=color] { width: 44px; height: 40px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap; }
.meta { font-size: 12px; color: var(--muted); }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  font: 600 14px var(--font); border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.btn svg.i { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); color: var(--accent-ink); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--muted); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.92); color: #fff; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .icon-btn { width: 32px; height: 32px; border-radius: 8px; border-color: transparent; background: transparent; }
.row-actions .icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.row-actions .icon-btn.danger:hover { color: var(--red); }
.row-actions svg.i { width: 16px; height: 16px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover { color: var(--text); }
.table th .arrow { font-size: 10px; opacity: .9; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .wrap { white-space: normal; min-width: 220px; }
.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-person { display: flex; align-items: center; gap: 10px; }
.code { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 8px; }
.text-red { color: var(--red); font-weight: 600; }
.text-muted { color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-gray { background: var(--gray-soft); color: var(--muted); }
.badge-indigo { background: var(--accent-soft); color: var(--accent); }

.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; }
.pager a, .pager span {
  min-width: 34px; height: 34px; padding: 0 10px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-weight: 600;
}
.pager a:hover { border-color: var(--border-strong); color: var(--text); }
.pager .current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pager .disabled { opacity: .45; }
.page-size { display: inline-flex; align-items: center; gap: 8px; }
.page-size .select { height: 34px; width: auto; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- Alerts / toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; min-width: 280px; max-width: 420px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--green);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); animation: toast-in .25s ease;
}
.toast.error { border-left-color: var(--red); }
.toast .grow { flex: 1; }
.toast button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
.toast.hide { opacity: 0; transform: translateY(8px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-info { background: var(--blue-soft); color: var(--blue); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70; display: none; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10, 12, 20, .55); backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal { width: 100%; max-width: 420px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px; animation: toast-in .2s ease; }
.modal-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--red-soft); color: var(--red); margin-bottom: 14px; }
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal p { color: var(--text-2); margin: 0 0 20px; }
.modal .actions { justify-content: flex-end; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art {
  position: relative; overflow: hidden; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at 10% 10%, #312e81 0%, transparent 60%),
              radial-gradient(900px 500px at 90% 90%, #0e7490 0%, transparent 55%), #0b0d17;
}
.auth-art .brand { padding: 0; }
.auth-art h2 { font-size: 34px; letter-spacing: -.02em; max-width: 460px; }
.auth-art p { color: #b8bdd4; max-width: 440px; font-size: 15px; }
.auth-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; }
.auth-points li { display: flex; gap: 10px; align-items: center; color: #d7dbeb; }
.auth-points svg { color: #67e8f9; }
.auth-grid { position: absolute; inset: 0; opacity: .12; pointer-events: none;
  background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(circle at 70% 40%, #000, transparent 70%); }
.auth-art > * { position: relative; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { font-size: 26px; margin-bottom: 6px; }
.auth-box .lead { color: var(--muted); margin: 0 0 26px; }
.auth-box .field { margin-bottom: 16px; }
.auth-box .btn { width: 100%; height: 44px; margin-top: 6px; }
.demo-box { margin-top: 24px; padding: 12px 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; color: var(--text-2); }
.demo-box code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* ---------- Error pages ---------- */
.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 24px; }
.error-code { font-size: 96px; font-weight: 800; letter-spacing: -.04em; line-height: 1;
  background: linear-gradient(135deg, var(--accent), #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-page p { color: var(--muted); max-width: 420px; margin: 12px auto 24px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .form-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .user-chip .who { display: none; }
}
@media (max-width: 600px) {
  .stats, .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 30px; }
  .search { max-width: none; }
  .toolbar .select { flex: 1; }
}
