/* ---- KOZ Hub theme: KOZ paper & ink with the KOZ orange, hub-style density ---- */
:root {
  color-scheme: light;
  --bg: #f6f4ef;             /* KOZ manifest paper, softened */
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --border: #e5e2d8;
  --text: #191d23;           /* KOZ ink */
  --text-2: #4b5260;
  --muted: #8a8f99;
  --brand: #e36314;          /* KOZ orange */
  --accent: var(--brand);
  --accent-ink: #ffffff;
  --navy: #0b1f3a;
  --danger: #d64545;
  --ok: #178a4c;
  --shadow: 0 1px 2px rgba(25,29,35,.05), 0 10px 28px -16px rgba(25,29,35,.15);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11141a; --surface: #181c23; --surface-2: #20252e; --border: #2b313c;
    --text: #edeef1; --text-2: #b3b8c2; --muted: #7d828c;
    --accent: #f07a33; --accent-ink: #11141a;
    --danger: #ef6a6a; --ok: #37b06b; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11141a; --surface: #181c23; --surface-2: #20252e; --border: #2b313c;
  --text: #edeef1; --text-2: #b3b8c2; --muted: #7d828c;
  --accent: #f07a33; --accent-ink: #11141a;
  --danger: #ef6a6a; --ok: #37b06b; --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { padding: 40px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }

/* ---- header ---- */
header { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.side-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.brand { flex: none; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand img { width: 22px; height: 22px; border-radius: 5px; }
.brand .ver { color: var(--muted); font-weight: 400; font-size: 11px; }
.spacer { flex: 1; }
.page-ref { background: none; border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; color: var(--text-2); display: grid; place-items: center; }
.page-ref svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.page-ref:hover { background: var(--surface-2); }
.usermenu { position: relative; }
.usermenu > button { background: none; border: 1px solid var(--border); border-radius: 18px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.usermenu .menu { position: absolute; right: 0; top: 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); min-width: 210px; padding: 6px; z-index: 9; }
.usermenu .menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.usermenu .menu button:hover { background: var(--surface-2); }
.usermenu .menu .who { padding: 6px 10px 8px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dev-pill { background: #c22; color: #fff; border-radius: 6px; font-size: 11px; font-weight: 700; padding: 2px 7px; }

/* ---- layout: left menu + page ---- */
.layout { display: flex; min-height: calc(100vh - 52px); }
.side { width: 190px; flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: 12px 8px; }
.side a { display: block; padding: 8px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; margin-bottom: 2px; border-left: 3px solid transparent; }
.side a:hover { background: var(--surface-2); }
.side a.on { background: var(--surface-2); color: var(--text); font-weight: 600; border-left-color: var(--accent); }
main { flex: 1; min-width: 0; padding: 18px 20px 40px; }
h1 { font-size: 19px; margin: 0; }
h2 { font-size: 14px; margin: 0 0 10px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.bar h1 { margin-right: auto; }
.bar .back { text-decoration: none; font-size: 18px; color: var(--text-2); }

/* ---- controls ---- */
.btn { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  background-color: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px; min-height: 36px;
  outline: 0; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
label { display: block; margin: 10px 0 4px; color: var(--text-2); font-size: 13px; }

/* ---- cards & tables ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.stat { text-align: left; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 12px; }
/* every wide or long table sits in a box no taller than the window: both scrollbars stay on screen */
.tbl-wrap { max-height: calc(100vh - 170px); overflow: auto; padding: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-size: 12px; color: var(--text-2); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.pill { display: inline-block; border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; font-size: 12px; background: var(--surface-2); }
.pill.on { border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.pill.off { color: var(--muted); }

/* ---- read card (a record's page: values read only, ✎ Edit to change) ---- */
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; }
.kv .k { color: var(--muted); font-size: 12px; padding-top: 2px; }
.kv .v { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

/* ---- login ---- */
.login { max-width: 400px; margin: 9vh auto; padding: 26px 28px; }
.login h1 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin-bottom: 4px; }
.login h1 img { width: 26px; height: 26px; border-radius: 6px; }
.login form { margin-top: 10px; }
.login input { width: 100%; }
.login .btn { margin-top: 14px; }
.twostep li { margin-bottom: 10px; }
.ts-qr { margin: 10px 0; } .ts-qr svg { border: 1px solid var(--border); border-radius: 8px; background: #fff; }
code { background: var(--surface-2); border-radius: 6px; padding: 1px 6px; }

/* ---- dialogs ---- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; max-width: 480px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog input { width: 100%; }

/* ---- new-version banner ---- */
.stale { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-bottom: 1px solid var(--border); padding: 8px 16px; font-size: 13px; }

/* ---- phone / tablet: the menu hides behind ☰ ---- */
@media (max-width: 800px) {
  .side-toggle { display: block; }
  .side { position: fixed; left: 0; top: 52px; bottom: 0; z-index: 8; transform: translateX(-100%); transition: transform .15s; }
  body.side-open .side { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  main { padding: 14px 12px 40px; }
  .kv { grid-template-columns: 1fr; }
}
