/* memoratu admin — hand-written, no framework, no inline styles (CSP
   style-src 'self'). Colours are tokens; dark follows the OS unless the theme
   button sets data-scheme on <html>. Usable at phone width: the side nav
   becomes a scrolling strip and tables become cards below 720px. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --ink: #111827; --muted: #6b7280; --line: #e3e5ea;
  --accent: #4f46e5; --accent-ink: #ffffff; --danger: #c62828; --danger-ink: #ffffff;
  --ok-bg: #e7f6ec; --ok-ink: #14532d; --warn-bg: #fff3d6; --warn-ink: #6a4a00;
  --info-bg: #e8f0fe; --info-ink: #17407f; --err-bg: #fdecec; --err-ink: #8a1c1c;
  --radius: 10px; --touch: 44px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --bg: #0f1115; --surface: #181b22; --ink: #eef0f4; --muted: #9aa1ad; --line: #2a2f39;
    --accent: #8b85ff; --accent-ink: #0b0d2a; --danger: #ff7b72; --danger-ink: #2a0606;
    --ok-bg: #12301d; --ok-ink: #a6e9bd; --warn-bg: #3a2e0a; --warn-ink: #ffd98a;
    --info-bg: #14233f; --info-ink: #a9c6ff; --err-bg: #3a1414; --err-ink: #ffb4ad;
    color-scheme: dark;
  }
}
:root[data-scheme="dark"] {
  --bg: #0f1115; --surface: #181b22; --ink: #eef0f4; --muted: #9aa1ad; --line: #2a2f39;
  --accent: #8b85ff; --accent-ink: #0b0d2a; --danger: #ff7b72; --danger-ink: #2a0606;
  --ok-bg: #12301d; --ok-ink: #a6e9bd; --warn-bg: #3a2e0a; --warn-ink: #ffd98a;
  --info-bg: #14233f; --info-ink: #a9c6ff; --err-bg: #3a1414; --err-ink: #ffb4ad;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
#app { min-height: 100vh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.35rem; margin: 4px 0 16px; }
h3 { font-size: 1.1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.mono { font-family: var(--mono); }
.prewrap { white-space: pre-wrap; }
.wrap { overflow-wrap: anywhere; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row.end { justify-content: flex-end; }
.row.spread { justify-content: space-between; margin: 0 0 6px; }

/* ---- controls */
.btn {
  min-height: var(--touch); padding: 0 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 0.86rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; min-height: var(--touch); width: 100%;
}
.field.inline input, .field.inline select { width: auto; }
input.short { max-width: 10rem; }
input.code { font-family: var(--mono); font-size: 1.3rem; letter-spacing: 0.25em; max-width: 12rem; }
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- messages */
.error { color: var(--err-ink); background: var(--err-bg); padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.notice { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; }
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice.info { background: var(--info-bg); color: var(--info-ink); }
.notice.error { background: var(--err-bg); color: var(--err-ink); }

/* ---- sign-in and setup */
main.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.auth { width: 100%; max-width: 420px; padding: 24px; }
.brand { font-weight: 700; font-size: 1.25rem; }
.qr-wrap { display: flex; justify-content: center; }
svg.qr { width: 220px; height: 220px; border-radius: 6px; }
.secret { font-size: 1rem; letter-spacing: 0.08em; overflow-wrap: anywhere; user-select: all; }
summary { cursor: pointer; color: var(--accent); }

/* ---- shell */
header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.who .name { font-weight: 600; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.badge.soft { background: var(--info-bg); color: var(--info-ink); }
.expiry { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 16px; }
.body { flex: 1; display: flex; min-height: 0; }
nav.side { width: 210px; flex: none; padding: 12px 8px; border-right: 1px solid var(--line); }
nav.side a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
nav.side a:hover { background: var(--bg); }
nav.side a.on { background: var(--accent); color: var(--accent-ink); }
.content { flex: 1; min-width: 0; padding: 20px 24px 64px; max-width: 1100px; }

/* ---- lists */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.status { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.s-active, .s-approved, .s-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.s-invited, .s-pending, .s-requested { background: var(--info-bg); color: var(--info-ink); border-color: transparent; }
.s-removed, .s-rejected, .s-denied, .s-failed { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }
.cards { display: grid; gap: 12px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 8px; }
.audit-row { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.audit-row.o-denied { border-left: 3px solid var(--danger); }
.chips { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; }
.chip-x { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; min-width: 32px; min-height: 32px; cursor: pointer; }

/* ---- customers (phase C) */
.gap { margin-top: 12px; }
.row.search input { flex: 1 1 260px; width: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 12px; }
.content section.card { margin-bottom: 12px; }
.content section.card h3 { margin-bottom: 10px; }
.actions-bar { margin: 0 0 12px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
ul.plain li:last-child { border-bottom: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile-n { font-size: 1.6rem; font-weight: 700; }
.grant-banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-weight: 600; }
.crumbs { margin: 0 0 8px; overflow-wrap: anywhere; }
.granted-body h4 { margin: 4px 0 8px; font-size: 1rem; }
.todo-detail .notes { background: var(--bg); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }

/* ---- modal */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-back.top { z-index: 20; }
.modal { background: var(--surface); color: var(--ink); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; }

/* ---- phone width */
@media (max-width: 720px) {
  .body { flex-direction: column; }
  nav.side { width: auto; display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  nav.side a { white-space: nowrap; }
  .content { padding: 16px 16px 64px; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list thead { display: none; }
  table.list { border: 0; background: transparent; }
  table.list tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  table.list td { border: 0; padding: 4px 12px; }
  table.list td[data-label]::before { content: attr(data-label); display: block; font-size: 0.78rem; color: var(--muted); }
  td.actions { text-align: left; white-space: normal; }
  .who .name { max-width: 10rem; }
}
