:root {
  --brand: #2563eb;
  --brand-dark: color-mix(in srgb, var(--brand) 80%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, #fff);
  --bg: #f4f6fb;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --ok: #16a34a;
  --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; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.offline-banner {
  position: sticky; top: 0; z-index: 50; background: #b45309; color: #fff;
  padding: .6rem 1rem; text-align: center; font-size: .9rem; font-weight: 600;
}
.offline-banner[hidden] { display: none; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem;
  background: radial-gradient(1200px 500px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--card); border-radius: 20px; padding: 2rem; box-shadow: var(--shadow); }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; margin-bottom: 1rem; }
.auth-card h1 { font-size: 1.6rem; }
.auth-card p.tag { color: var(--muted); margin: .25rem 0 1.25rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 1rem; }
.tabs button { border: 0; background: transparent; padding: .55rem; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: .8rem 0 .3rem; }
input, select, textarea {
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; margin-top: .9rem; font-weight: 500; }
.checkbox input { width: auto; }
.field-error { color: var(--danger); font-size: .8rem; margin-top: .25rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 0; border-radius: 10px;
  padding: .65rem 1rem; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; transition: background .15s, transform .05s; }
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 1.1rem; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.small { padding: .35rem .65rem; font-size: .85rem; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: .7rem 1.25rem; }
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; }
.topbar .brand .logo { width: 34px; height: 34px; font-size: 1rem; margin: 0; border-radius: 10px; }
.topbar .spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.pill { background: var(--brand-soft); color: var(--brand-dark); border-radius: 999px; padding: .15rem .6rem; font-size: .75rem; font-weight: 700; }
.nav { display: flex; gap: .25rem; padding: .5rem 1.25rem 0; max-width: 1100px; margin: 0 auto; overflow-x: auto; }
.nav button { border: 0; background: transparent; padding: .6rem .9rem; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.nav button.active { background: var(--card); color: var(--brand-dark); box-shadow: var(--shadow); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.head h2 { font-size: 1.3rem; }
.tools { display: flex; gap: .5rem; flex-wrap: wrap; }
.tools input, .tools select { width: auto; min-width: 150px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--brand-dark); }
.stat .l { color: var(--muted); font-size: .85rem; }
.bars { display: grid; gap: .6rem; }
.bar { display: grid; grid-template-columns: 110px 1fr 36px; gap: .6rem; align-items: center; font-size: .9rem; }
.bar .track { background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; }
.bar .fill { background: var(--brand); height: 100%; border-radius: 999px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: middle; }
th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
td.actions { white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--brand-soft); color: var(--brand-dark); text-transform: capitalize; }
.badge.off { background: #fee2e2; color: #991b1b; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ---------- modal & toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 1rem; z-index: 60; }
.modal { background: var(--card); border-radius: 18px; width: min(520px, 100%); max-height: 92vh; overflow: auto; padding: 1.4rem; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h3 { font-size: 1.2rem; margin-bottom: .25rem; }
.modal .foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 80; }
.toast { background: #0f172a; color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 320px; animation: pop .2s ease; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 680px) {
  .topbar { padding: .6rem .8rem; }
  .userbox .name { display: none; }
  main { padding: .75rem .8rem 3rem; }
  .row2 { grid-template-columns: 1fr; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { border: 1px solid var(--border); border-radius: 12px; padding: .5rem .75rem; margin-bottom: .6rem; }
  td { border: 0; padding: .25rem 0; display: flex; justify-content: space-between; gap: 1rem; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; text-transform: uppercase; }
  td.actions { justify-content: flex-end; }
  td.actions::before { content: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
