:root {
  --bg: #f5f8f9;
  --surface: #ffffff;
  --text: #13262c;
  --muted: #5b7078;
  --border: #dbe5e8;
  --primary: #0f4c5c;
  --primary-soft: #e3f1f4;
  --accent: #f4b942;
  --ok: #2e9e5b;
  --ok-soft: #e4f5eb;
  --bad: #c0392b;
  --bad-soft: #fbe9e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 76, 92, 0.06), 0 4px 16px rgba(15, 76, 92, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1719;
    --surface: #152226;
    --text: #e3eef1;
    --muted: #93a8ae;
    --border: #253a40;
    --primary: #7fc8d6;
    --primary-soft: #1b3940;
    --ok-soft: #173826;
    --bad-soft: #3d1c18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center;
}
.login-card label { text-align: left; }
.login-card img { justify-self: center; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 0 6px; }
.sidebar nav { display: grid; gap: 2px; flex: 1; align-content: start; }
.sidebar nav a {
  text-decoration: none; color: var(--text); padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--primary-soft); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .sidebar nav a.active { color: #0e1719; } }
.view { padding: 28px clamp(16px, 4vw, 40px); max-width: 1200px; width: 100%; outline: none; }

.me { display: grid; gap: 4px; border-top: 1px solid var(--border); padding-top: 14px; }
.me > div { display: grid; padding: 0 6px 6px; font-size: 0.9rem; }
.me .btn { justify-self: stretch; text-align: left; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  .sidebar nav { display: flex; flex: 1 1 100%; order: 3; overflow-x: auto; }
  .sidebar nav a { white-space: nowrap; }
  .brand span { display: none; }
  .me { border: none; padding: 0; margin-left: auto; display: flex; align-items: center; }
  .me > div, #change-pw { display: none; }
  .view { padding: 20px 16px; }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }

/* Controls */
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { min-height: 160px; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0e1719; } }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card .label { color: var(--muted); font-size: 0.85rem; }
.card .value { font-size: 2rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .hint { font-size: 0.85rem; color: var(--muted); }
.card.warn { border-color: var(--accent); }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; background: var(--bg); }
tr:last-child td { border-bottom: none; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--primary-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: #fdf1d6; color: #8a5a00; }
.pill.neutral { background: var(--primary-soft); color: var(--primary); }

.bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; min-width: 90px; }
.bar > span { display: block; height: 100%; background: var(--ok); }

/* Modal */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 25, 30, 0.45); }
#modal-form { padding: 24px; display: grid; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-width: calc(100% - 32px);
}
.toast.error { background: var(--bad); color: #fff; }
.note { background: var(--primary-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; font-size: 0.9rem; }
