:root {
  --ink: #1d2b3a;
  --ink-2: #2c3e50;
  --paper: #f7f8fa;
  --surface: #ffffff;
  --line: #d9dee5;
  --line-soft: #e9edf1;
  --muted: #5d6b7a;
  --signal: #0f7b6c;
  --signal-soft: #e3f3f0;
  --alert: #b42318;
  --alert-soft: #fbeae8;
  --amber: #a86b12;
  --amber-soft: #fbf1df;
  --focus: #2f6fdb;
  --radius-s: 4px;
  --radius-m: 8px;
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* the hidden attribute always wins over component display rules */
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--focus); }
code, .mono { font-family: Consolas, "Cascadia Mono", "SFMono-Regular", Menlo, monospace; font-size: .86em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--ink) 232px, var(--paper) 232px); }
.rail {
  background: var(--ink);
  color: #dfe6ee;
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 1.02rem; padding: 0 6px; }
.brand img { width: 26px; height: 26px; }
.login-clock { margin-top: 28px; max-width: 260px; }
.login-clock .clock { margin: 0; }
.version-foot { font-size: .75rem; color: #6f8399; margin-bottom: 6px; }
.clock { margin: -6px 6px 0; padding: 10px 12px; border: 1px solid #3b5068; border-radius: var(--radius-s); }
.clock-time { color: #fff; font-size: 1.45rem; font-weight: 600; letter-spacing: .02em; line-height: 1.2; }
.clock-date { color: #9fb0c2; font-size: .8rem; margin-top: 2px; }
.tenant-pick label { display: block; font-size: .8rem; color: #9fb0c2; margin: 0 6px 4px; }
.tenant-pick select {
  width: 100%; background: var(--ink-2); color: #fff; border: 1px solid #3b5068;
  border-radius: var(--radius-s); padding: 7px 8px; font: inherit;
}
.tenant-flags { margin: 6px 6px 0; font-size: .78rem; color: #9fb0c2; }
nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: block; padding: 8px 10px; border-radius: var(--radius-s);
  color: #dfe6ee; text-decoration: none;
}
nav a:hover { background: var(--ink-2); }
nav a[aria-current="page"] { background: #fff; color: var(--ink); font-weight: 600; }
.rail-foot { margin-top: auto; font-size: .82rem; color: #9fb0c2; padding: 0 6px; }
.rail-foot button { margin-top: 6px; }

main { padding: 28px 36px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.panel + .panel { margin-top: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); gap: 12px; flex-wrap: wrap; }
.panel-body { padding: 16px 18px; }

/* ---------- buttons & forms ---------- */
button, .btn {
  font: inherit; cursor: pointer; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 6px 12px; line-height: 1.4; white-space: nowrap;
}
a.btn { text-decoration: none; display: inline-block; }
button:hover, a.btn:hover { border-color: #b8c1cc; }
button.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
button.primary:hover { background: #0c6a5d; }
button.danger { color: var(--alert); border-color: #e7b9b4; }
button.small { padding: 2px 8px; font-size: .85rem; margin-top: 4px; }
a.btn.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
button.quiet { border-color: transparent; background: transparent; color: inherit; }
button:disabled { opacity: .55; cursor: not-allowed; }
.rail button { background: transparent; color: #dfe6ee; border-color: #3b5068; }

label { font-size: .88rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 9px; min-width: 0;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--signal); }
.field { display: flex; flex-direction: column; gap: 4px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 16px; align-items: end; }
.grid-form .wide { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; }
.hint { font-size: .82rem; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { white-space: nowrap; font-weight: 600; color: var(--muted); font-size: .84rem; background: #fbfcfd; position: sticky; top: 0; }
tbody tr:hover { background: #f6f9fb; }
tr.clickable { cursor: pointer; }
td.right, th.right { text-align: right; }
td.num { white-space: nowrap; }
td.actions { white-space: nowrap; display: table-cell; }
td.actions > * + * { margin-left: 6px; }
td.actions .btn, td.actions button { padding: 3px 9px; font-size: .88rem; }
td[title] { white-space: nowrap; }
.trunc { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 18px; color: var(--muted); }

/* ---------- status ---------- */
.status { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; padding: 1px 8px; border-radius: 999px; background: var(--line-soft); color: var(--ink-2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ok { background: var(--signal-soft); color: var(--signal); }
.status.bad { background: var(--alert-soft); color: var(--alert); }
.status.warn { background: var(--amber-soft); color: var(--amber); }
.tag-deleted { color: var(--alert); font-size: .82rem; margin-left: 6px; }

/* ---------- dashboard ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); margin-bottom: 20px; }
.fact { padding: 14px 18px; border-right: 1px solid var(--line-soft); }
.fact:last-child { border-right: 0; }
.fact b { display: block; font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fact span { color: var(--muted); font-size: .86rem; }

/* freshness: the one memorable element */
.fresh-list { display: flex; flex-direction: column; }
.fresh-row { display: grid; grid-template-columns: minmax(180px, 280px) 1fr 140px; gap: 16px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.fresh-row:last-child { border-bottom: 0; }
.fresh-row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fresh-track { position: relative; height: 10px; background: var(--line-soft); border-radius: 5px; }
.fresh-track .due { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); opacity: .35; }
.fresh-track .bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: var(--signal); }
.fresh-track .bar.late { background: var(--amber); }
.fresh-track .bar.stale { background: var(--alert); }
.fresh-track .bar.none { background: repeating-linear-gradient(45deg, var(--line), var(--line) 4px, transparent 4px, transparent 8px); width: 100%; }
.fresh-row .when { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .88rem; }
.fresh-legend { display: flex; gap: 18px; font-size: .82rem; color: var(--muted); }
.fresh-legend i { display: inline-block; width: 18px; height: 8px; border-radius: 4px; margin-right: 6px; vertical-align: middle; }

.storage-bar { height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.storage-bar span { display: block; height: 100%; background: var(--ink-2); }

/* ---------- selection bar ---------- */
.selbar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: var(--ink); color: #fff; border-radius: 0 0 var(--radius-m) var(--radius-m); }
.selbar[hidden] { display: none; }
.selbar button { background: #fff; }
.selbar button.on-dark { background: transparent; color: #fff; border-color: #5b6f85; }

/* ---------- drawer / dialog ---------- */
.scrim { position: fixed; inset: 0; background: rgba(29, 43, 58, .35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 21; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer-body { padding: 16px 20px; overflow: auto; flex: 1; }
.meta-grid { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; font-size: .9rem; margin-bottom: 14px; }
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; word-break: break-word; }
.mail-frame { width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
pre.mail-text, pre.json { white-space: pre-wrap; word-break: break-word; background: #fbfcfd; border: 1px solid var(--line-soft); border-radius: var(--radius-s); padding: 12px; font-size: .86rem; max-height: 60vh; overflow: auto; }
.labels { display: flex; flex-wrap: wrap; gap: 4px; }
.label-chip { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0 6px; font-size: .8rem; color: var(--ink-2); }
.history li { margin-bottom: 6px; }
.dialog { position: fixed; z-index: 21; top: 12vh; left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.dialog .panel-body { display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 12px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--signal); font-weight: 600; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, 420px) 1fr; }
.login-side { background: var(--ink); color: #dfe6ee; padding: 48px 40px; display: flex; flex-direction: column; justify-content: space-between; }
.login-side h1 { color: #fff; font-size: 1.5rem; margin-top: 22px; }
.login-side p { color: #b8c6d4; max-width: 34ch; }
.login-form { align-self: center; justify-self: center; width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 14px; }
.login-form input { padding: 9px 11px; }
.otp { letter-spacing: .3em; font-variant-numeric: tabular-nums; }
.error { color: var(--alert); font-size: .9rem; }

/* live activity */
.act-row { display: grid; grid-template-columns: minmax(220px, 1.2fr) 2fr 150px; gap: 16px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.act-row:last-child { border-bottom: 0; }
.act-what b { font-weight: 600; }
.act-num { text-align: right; font-size: .9rem; }
.pbar { position: relative; height: 10px; border-radius: 5px; background: var(--line-soft); overflow: hidden; }
.pbar > span { position: absolute; inset: 0 auto 0 0; background: var(--signal); border-radius: 5px; transition: width .6s ease; }
.pbar > i { position: absolute; inset: 0 auto 0 0; background: var(--alert); }
.pbar.idle { background: repeating-linear-gradient(45deg, var(--line-soft), var(--line-soft) 4px, transparent 4px, transparent 8px); }
.pbar.busy > span { width: 30%; animation: wsb-busy 1.4s ease-in-out infinite; }
@keyframes wsb-busy { 0% { left: -30%; } 100% { left: 100%; } }
/* forms */
.stack { display: flex; flex-direction: column; gap: 16px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0 6px; color: var(--ink); font-weight: 600; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.check-result { min-height: 1.4em; font-size: .9rem; }
.ok-text { color: var(--signal); }
.smb[hidden] { display: none; }
.error { white-space: pre-line; }
.dialog { max-height: 86vh; overflow: auto; }

/* accounts */
.small-link { font-size: .9rem; }
.login-form.wide-form { width: min(440px, calc(100vw - 32px)); }
.qr { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; align-self: flex-start; }
.secret { word-break: break-all; background: #fbfcfd; padding: 6px 8px; border: 1px solid var(--line-soft); border-radius: var(--radius-s); }
pre.codes { columns: 2; font-size: 1rem; line-height: 1.9; background: #fbfcfd; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 14px; margin: 0; }
.tenant-boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; padding-left: 26px; }
.tenant-boxes[hidden] { display: none; }
fieldset[disabled] { opacity: .6; }
.user-tools { border-top: 1px solid var(--line-soft); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
table.matrix td.center { text-align: center; color: var(--signal); font-weight: 600; }
.narrow { max-width: 420px; }
.rail-foot .me-link { color: #fff; text-decoration: none; font-weight: 600; display: inline-block; }
.rail-foot .me-link:hover, .rail-foot .me-link[aria-current="page"] { text-decoration: underline; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.bad { background: var(--alert); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: var(--paper); }
  .rail { position: static; height: auto; }
  nav ul { flex-direction: row; flex-wrap: wrap; }
  .clock { margin: 0; }
  main { padding: 20px 16px 48px; }
  .fresh-row { grid-template-columns: 1fr; gap: 6px; }
  .fresh-row .when { text-align: left; }
  .act-row { grid-template-columns: 1fr; gap: 6px; }
  .act-num { text-align: left; }
  .inline { flex-direction: column; }
  .login { grid-template-columns: 1fr; }
  .login-side { padding: 28px 20px; gap: 18px; justify-content: flex-start; }
  .grid-form .wide { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
