:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2f5bea;
  --brand-dark: #1e3fb8;
  --brand-soft: #eaefff;
  --ok: #128a5b;
  --ok-soft: #e4f6ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --bad: #c2352b;
  --bad-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1,h2,h3,h4 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

/* ---------------------------------------------------------------- login -- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, #23306b 0%, #2f5bea 55%, #5b83f5 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border-radius: 18px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.28);
}
.login-card .logo { font-size: 30px; }
.login-card h1 { font-size: 20px; margin-top: 8px; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 14px; text-align: center; }

/* --------------------------------------------------------------- layout -- */
.app { display: none; min-height: 100vh; }
.app.show { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
}
.topbar .brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: var(--muted); text-align: right; }
.topbar .who b { display: block; color: var(--ink); font-size: 14px; }

.shell { display: flex; align-items: flex-start; }
.sidebar {
  width: 216px; flex: 0 0 216px; padding: 14px 10px; position: sticky; top: 47px;
  height: calc(100vh - 47px); overflow: auto; border-right: 1px solid var(--line); background: #fff;
}
.sidebar button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: #444; font-family: inherit; margin-bottom: 2px;
}
.sidebar button:hover { background: #f1f3f9; }
.sidebar button.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.sidebar .ico { width: 20px; text-align: center; }
.sidebar .badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }

.main { flex: 1; min-width: 0; padding: 18px 20px 90px; }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }

.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 12px 84px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: #fff; border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav button {
    flex: 1; border: 0; background: none; font-family: inherit; font-size: 10.5px; color: #6b7280;
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; cursor: pointer;
  }
  .bottom-nav button .ico { font-size: 17px; }
  .bottom-nav button.active { color: var(--brand); font-weight: 600; }
  .topbar .who b { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------------------------------------------------------------- cards -- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card > h3 { display: flex; align-items: center; gap: 8px; }
.card .card-sub { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }

.grid { display: grid; gap: 12px; }
.grid.k2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.k4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 900px) { .grid.k4, .grid.k3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 520px) { .grid.k2, .grid.k3, .grid.k4 { grid-template-columns: 1fr; } }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { background: linear-gradient(135deg, #2f5bea, #5b83f5); color: #fff; border-color: transparent; }
.stat.accent .label, .stat.accent .foot { color: rgba(255,255,255,.85); }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 540px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfd; position: sticky; top: 0; }
tbody tr:hover { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.money { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

/* --------------------------------------------------------------- inputs -- */
label.f { display: block; margin-bottom: 10px; font-size: 13px; color: #374151; }
label.f span { display: block; margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 14.5px; color: var(--ink);
  padding: 9px 11px; border: 1px solid #d5d9e2; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; background: var(--brand); color: #fff;
  padding: 9px 16px; border-radius: 10px; font-size: 14px; font-family: inherit;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: #374151; border-color: #d5d9e2; }
.btn.ghost:hover { background: #f4f6fb; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.xl { padding: 16px; font-size: 17px; border-radius: 14px; }
.row-actions { display: flex; gap: 6px; }

/* --------------------------------------------------------------- chips --- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.neutral { background: #eef0f4; color: #4b5563; }
.chip.brand { background: var(--brand-soft); color: var(--brand-dark); }

/* -------------------------------------------------------------- clock ---- */
.clock-card { text-align: center; background: linear-gradient(135deg, #23306b, #2f5bea); color: #fff; border: 0; }
.clock-card .time { font-size: 46px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.clock-card .date { opacity: .85; font-size: 14px; margin-bottom: 14px; }
.clock-card .btn { background: #fff; color: var(--brand-dark); }
.clock-card .btn.bad { background: #ffe6e4; color: var(--bad); }
.clock-card .status { margin-top: 12px; font-size: 13.5px; opacity: .92; }

.bar { height: 8px; background: #eceff5; border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 8px; font-size: 13.5px; }
.alert.up { background: var(--ok-soft); color: #0b6b47; }
.alert.down { background: var(--bad-soft); color: #9c2b22; }
.alert .ico { font-size: 18px; }
.spark { display: inline-flex; gap: 3px; align-items: flex-end; height: 22px; margin-left: 6px; }
.spark i { width: 7px; background: currentColor; opacity: .45; border-radius: 2px; }
.spark i:last-child { opacity: 1; }

/* -------------------------------------------------------------- modal ---- */
.modal-back { position: fixed; inset: 0; background: rgba(15,20,35,.45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 88vh; overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal header { padding: 16px 18px 6px; display: flex; align-items: center; }
.modal header h3 { margin: 0; flex: 1; }
.modal header .x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal .body { padding: 8px 18px 4px; }
.modal footer { padding: 12px 18px 18px; display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
  background: #16181d; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; z-index: 90; box-shadow: 0 8px 28px rgba(0,0,0,.3); max-width: 90vw; text-align: center;
}
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.right { text-align: right; }
.mt { margin-top: 12px; }
.nowrap { white-space: nowrap; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notif { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.notif:last-child { border-bottom: 0; }
.notif .t { font-weight: 600; }
.print-only { display: none; }
@media print {
  .topbar, .sidebar, .bottom-nav, .btn, .page-head .spacer { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
