:root {
  --ink: #1d2433;
  --muted: #5b6475;
  --surface: #f5f7fa;
  --panel: #ffffff;
  --line: #dde2ea;
  --accent: #2f5bd3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7ebf2;
    --muted: #a1a9b8;
    --surface: #12161e;
    --panel: #1a1f2a;
    --line: #2a3140;
    --accent: #8aa6ff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--surface);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { color: var(--ink); font-weight: 700; font-size: 1.15rem; text-decoration: none; letter-spacing: -0.01em; }
.page { flex: 1; width: 100%; max-width: 68rem; margin: 0 auto; padding: 2.5rem 1.5rem; }
.page h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 .75rem; letter-spacing: -0.02em; }
.lede { font-size: 1.125rem; color: var(--muted); max-width: 38rem; }
.site-footer { padding: 1.25rem 1.5rem; color: var(--muted); font-size: .875rem; border-top: 1px solid var(--line); }
.site-footer a { color: var(--muted); }

/* --- Phase 1: navigation, forms, tables ------------------------------------- */
:root { --danger: #b42318; --ok: #1a7f37; --warn-bg: #fff4e5; --err-bg: #fdecea; --ok-bg: #e9f6ec; }
@media (prefers-color-scheme: dark) {
  :root { --danger: #ff8a80; --ok: #6fdc8c; --warn-bg: #3a2e14; --err-bg: #3d1d1b; --ok-bg: #16301f; }
}
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
.site-nav a { color: var(--ink); text-decoration: none; }
.site-nav a:hover { color: var(--accent); }
form.inline { display: inline; margin: 0; }
h2 { font-size: 1.3rem; margin: 2rem 0 .75rem; }
.narrow { max-width: 32rem; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
.title-row h1, .title-row h2 { margin-bottom: .5rem; }

.form { display: grid; gap: 1rem; margin: 1rem 0; }
.form > button, .form > a { justify-self: start; }
.field { display: grid; gap: .3rem; }
.field label { font-weight: 600; font-size: .95rem; }
.field.check { display: flex; align-items: center; gap: .5rem; }
.field.check label { font-weight: 400; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; }
input:not([type=checkbox]), select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: .55rem .7rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: .875rem; margin: 0; }
.error { color: var(--danger); font-size: .875rem; margin: 0; }

button, .button {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  color: #fff; background: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: .5rem 1rem;
}
@media (prefers-color-scheme: dark) { button, .button { color: #0b1020; } }
button.secondary, .button.secondary { color: var(--accent); background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.link {
  color: var(--accent); background: none; border: 0; padding: 0; font-weight: 400; text-decoration: underline;
}
.site-nav button.link { color: var(--ink); text-decoration: none; }
.button-row { display: flex; flex-wrap: wrap; gap: .75rem; }
.button-row form { margin: 0; }

.flash { padding: .7rem 1rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); }
.flash-error { background: var(--err-bg); border-color: var(--danger); }
.flash-success { background: var(--ok-bg); border-color: var(--ok); }
.flash-info { background: var(--warn-bg); }

.search { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0; }
.search input { flex: 1 1 16rem; width: auto; }
.search select { width: auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
td.actions { white-space: nowrap; display: flex; gap: .75rem; }
td.details { font-size: .85rem; color: var(--muted); word-break: break-word; }
.nowrap { white-space: nowrap; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge-active, .badge-sent { color: var(--ok); border-color: var(--ok); }
.badge-failed { color: var(--danger); border-color: var(--danger); }
.pager { display: flex; gap: 1rem; margin: 1rem 0; color: var(--muted); }

.stats { display: flex; flex-wrap: wrap; gap: 1rem; margin: 1rem 0 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.25rem; color: var(--muted); }
.stat-value { display: block; font-size: 1.8rem; font-weight: 700; color: var(--ink); }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0 2rem; }
address { font-style: normal; }
.notes { white-space: pre-wrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.steps li { margin-bottom: .75rem; }
.qr { margin: .75rem 0; }
.qr svg { display: block; background: #fff; border-radius: 6px; }
code.secret { word-break: break-all; }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, max-content); gap: .4rem 2rem; font-size: 1.1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Phase 2: tickets ----------------------------------------------------------- */
.tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.tabs a { padding: .4rem 0; text-decoration: none; color: var(--muted); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom: 2px solid var(--accent); }
.ticket-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; color: var(--muted); }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 18rem; gap: 2rem; align-items: start; }
@media (max-width: 52rem) { .ticket-layout { grid-template-columns: minmax(0, 1fr); } }
.ticket-side h2:first-child { margin-top: 0; }
.message { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.message.author-staff { border-left: 4px solid var(--accent); }
.message.message-note { background: var(--warn-bg); }
.message.author-system { background: transparent; border-style: dashed; color: var(--muted); font-size: .9rem; }
.message-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.original { margin-top: .75rem; }
.original summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.html-body { margin-top: .5rem; padding: .75rem; border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; overflow-wrap: anywhere; }
.html-body table { width: auto; }
.attachments { margin: .75rem 0 0; padding-left: 1.25rem; }
.badge-note { color: var(--ink); }
.status-open, .status-customer-reply { color: var(--danger); border-color: var(--danger); }
.status-answered { color: var(--ok); border-color: var(--ok); }
input[type=color] { padding: .2rem; height: 2.6rem; }
input[type=file] { padding: .4rem; }
