:root {
  --navy: #0d2b45;
  --blue: #1E6FC0;
  --blue2: #2F8FE0;
  --tint: #eaf3fc;
  --text: #1a2233;
  --muted: #6b7280;
  --faint: #8a93a0;
  --border: #e2e5ea;
  --bg: #f5f6f8;
  --green: #1a9e4a;
  --amber: #b7791f;
  --red: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 8px; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; }
.error { color: var(--red); min-height: 1.2em; margin: 6px 0; }

.btn { height: 34px; padding: 0 14px; font: inherit; font-size: 13px; color: var(--blue); background: #fff; border: 1px solid #cfd5dd; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--blue2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn.primary:hover { background: #185ea5; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { color: #cfd9e6; background: transparent; border-color: rgba(255,255,255,0.25); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.wide { width: 100%; height: 40px; font-size: 14px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--blue2); outline-offset: 2px; }

input, select, textarea { height: 34px; padding: 0 10px; font: inherit; font-size: 13px; color: var(--text); background: #fff; border: 1px solid #cfd5dd; border-radius: 6px; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input[type=checkbox] { height: auto; }

/* Sign in */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #0d2b45, #1E6FC0); }
.login-card { width: 100%; max-width: 380px; padding: 28px; background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); display: flex; flex-direction: column; }
.login-logo { width: 200px; align-self: center; margin-bottom: 12px; }
.login-card h1, .login-card .muted { text-align: center; }
.login-card label { font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.login-card input { height: 40px; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 230px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; padding: 16px 12px; color: #fff; background: linear-gradient(180deg, #0d2b45, #12588f); position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 10px; border-bottom: 1px solid rgba(255,255,255,0.15); }
.brand img { width: 30px; }
.brand span { display: block; font-size: 11.5px; color: #b9c8da; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side nav a { padding: 9px 10px; color: #d7dcec; text-decoration: none; border-radius: 6px; }
.side nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.side nav a.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 600; }
.main { flex: 1; min-width: 0; padding: 22px 26px 40px; outline: none; }

.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { min-width: 220px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.card .num { font-size: 22px; font-weight: 700; margin-top: 4px; }
.card .lbl { color: var(--muted); font-size: 12.5px; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }

.table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; padding: 9px 10px; text-align: left; font-weight: 600; white-space: nowrap; color: var(--text); background: #f0f2f5; border-bottom: 1px solid #dfe3e8; }
td { padding: 8px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7fafd; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--faint); }

.tag { display: inline-block; padding: 1px 8px; font-size: 11.5px; font-weight: 600; border-radius: 10px; background: #eef0f3; color: var(--muted); white-space: nowrap; }
.tag.green { background: #e6f6ec; color: #146c36; }
.tag.red { background: #fde8e8; color: var(--red); }
.tag.amber { background: #fff4d6; color: #8a5a00; }
.tag.blue { background: var(--tint); color: var(--blue); }
.neg { color: var(--red); font-weight: 600; }
.pos { color: var(--green); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 6px 0 14px; flex-wrap: wrap; }
.tabs button { padding: 9px 14px; font: inherit; color: var(--muted); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

.form { display: grid; grid-template-columns: 170px 1fr; gap: 10px 14px; align-items: center; }
.form label { color: var(--text); }
.form .full { grid-column: 1 / -1; }
.form input, .form select, .form textarea { width: 100%; max-width: 420px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; }
.checks label { display: flex; align-items: center; gap: 6px; }
.req { color: var(--red); }

.modal-back { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(13,27,45,0.5); }
.modal { width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.x { font-size: 22px; line-height: 1; color: var(--faint); background: none; border: none; cursor: pointer; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 60; max-width: 420px; padding: 12px 16px; color: #fff; background: #1a2233; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.toast.err { background: var(--red); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details.json summary { cursor: pointer; color: var(--blue); font-size: 12px; }
details.json pre { margin: 6px 0 0; padding: 8px; max-width: 520px; overflow: auto; font-size: 11.5px; background: #f7f8fa; border-radius: 6px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 16px; }
  .form, .kv { grid-template-columns: 1fr; }
}

/* ---- Client access ---- */
.access-edit { display: flex; flex-direction: column; gap: 6px; }
.access-edit > label { display: flex; align-items: center; gap: 8px; }
.access-edit > label input, .access-edit .checks input { height: auto; }
.access-edit .checks[hidden] { display: none; }
.access-grid th.svc { width: 34px; padding: 6px 2px; vertical-align: bottom; height: 96px; }
.access-grid th.svc span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-size: 12px; }
.access-grid td.svc { text-align: center; width: 34px; padding: 6px 2px; font-weight: 700; }
.access-grid td.svc.on { color: var(--green); }
.access-grid td.svc.off { color: #c3c9d2; }.form input[type="checkbox"], .form input[type="radio"] { width: auto; max-width: none; }
.access-edit { max-width: 640px; }.notice { background: #fff8e6; border: 1px solid #f0d9a0; color: #7a5a12; border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; }
.toolbar label { color: var(--muted); font-size: 13px; }
td.actions .btn.small + .btn.small { margin-left: 4px; }