:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --sidebar: #0f172a;
  --sidebar-ink: #cbd5e1;
  --sidebar-active: #1d4ed8;
  --ok: #16a34a;
  --warn: #ca8a04;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px; flex: 0 0 248px; background: var(--sidebar); color: var(--sidebar-ink);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 10px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.07); margin-bottom: 10px; }
.brand-logo { width: 150px; height: auto; display: block; }
.brand-name b { color: #fff; font-size: 14.5px; letter-spacing: -.01em; }
.brand-name small { display: block; color: #94a3b8; font-size: 11px; margin-top: 1px; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav .group { color: #64748b; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px;
  padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px;
  color: var(--sidebar-ink); font-weight: 500;
}
.nav a:hover { background: #1e293b; text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav a .ic { width: 18px; text-align: center; opacity: .9; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 12px; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.content { padding: 22px 28px 48px; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.card .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .v.ok { color: var(--ok); } .card .v.warn { color: var(--warn); } .card .v.danger { color: var(--danger); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-top: 18px; }
.panel h2 { font-size: 14px; margin: 0 0 14px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .6px; font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }

/* ---------- Forms ---------- */
form.inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; min-width: 120px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { min-width: auto; width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; border-radius: 9px; padding: 8px 14px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #1d4ed8; text-decoration: none; }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.gray { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); margin-top: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: #f8fafc; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; z-index: 1; }
tbody tr:hover { background: #f8fafc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .h { font-size: 11px; color: var(--muted); text-transform: uppercase; text-align: center; padding: 4px; }
.cal .cell { min-height: 54px; border: 1px solid var(--line); border-radius: 9px; padding: 6px;
  background: #fff; font-size: 12px; }
.cal .cell.other { opacity: .35; }
.cal .cell .d { font-weight: 700; }
.cal .cell .s { font-size: 10.5px; margin-top: 3px; color: #fff; border-radius: 6px; padding: 1px 5px;
  display: inline-block; }

/* ---------- Flash ---------- */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.flash { padding: 10px 14px; border-radius: 10px; border: 1px solid; font-size: 13px; }
.flash.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 520px at 12% -12%, rgba(37, 99, 235, .30), transparent 60%),
    radial-gradient(760px 520px at 112% 118%, rgba(29, 78, 216, .18), transparent 60%),
    var(--sidebar);
}
.login-card {
  width: 100%; max-width: 380px; color: #e2e8f0;
  background: linear-gradient(180deg, #131e36, #0e1729);
  border: 1px solid rgba(255, 255, 255, .08); border-radius: 18px;
  padding: 32px 30px 24px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.login-brand { display: grid; place-items: center; gap: 6px; margin-bottom: 22px; }
.login-logo { width: 190px; max-width: 72%; height: auto; display: block; margin-bottom: 6px; }
.login-card h1 { font-size: 18px; margin: 0; color: #f1f5f9; letter-spacing: -.01em; }
.login-card p.sub { color: #94a3b8; margin: 0; font-size: 12.5px; text-align: center; }
.login-card .field { margin-bottom: 14px; }
.login-card label { color: #94a3b8; }
.login-card input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .12);
  color: #f8fafc;
}
.login-card input::placeholder { color: #64748b; }
.login-card input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .28);
}
.login-card input:-webkit-autofill {
  -webkit-text-fill-color: #f8fafc;
  -webkit-box-shadow: 0 0 0 40px #16233f inset;
  caret-color: #f8fafc;
}
.login-card .btn {
  width: 100%; justify-content: center; margin-top: 8px; padding: 10px 14px;
  border-radius: 10px; transition: transform .12s ease, background .15s ease;
}
.login-card .btn:active { transform: scale(.985); }
.login-card .btn[aria-busy="true"] { opacity: .85; pointer-events: none; }
.login-card .btn .spin {
  display: none; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: login-spin .7s linear infinite;
}
.login-card .btn[aria-busy="true"] .spin { display: inline-block; }
@keyframes login-spin { to { transform: rotate(360deg); } }
.login-error {
  background: rgba(220, 38, 38, .12); color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, .4);
  padding: 9px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px;
}
.login-foot { margin: 18px 0 0; text-align: center; color: #64748b; font-size: 11.5px; }

@media (prefers-reduced-motion: reduce) {
  .login-card .btn { transition: none; }
  .login-card .btn .spin { animation-duration: 0.01ms; }
}
@media (max-width: 420px) {
  .login-card { padding: 26px 20px 20px; }
  .login-logo { width: 160px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav .group { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

@media print {
  .sidebar, .topbar .userbox, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
  .panel, .table-wrap { box-shadow: none; border-color: #ccc; }
}
