/* Belegbot UI — hand-written CSS, no build step.
 *
 * Why not Tailwind although CLAUDE.md lists it in the stack: both ways of
 * using it here cost more than they pay. The Play CDN is explicitly not for
 * production, compiles in the browser on every load and makes an internal
 * accounting UI depend on a third-party host. The standalone CLI would need a
 * Node binary in the Docker build plus a watch process — for a dozen
 * templates. So: one file, served from /static, no network, no build.
 *
 * Design direction (docs/superpowers/specs/2026-08-05-ui-redesign-design.md):
 * light SaaS look, deep blue accent, sidebar navigation. Keyboard-first
 * review flow stays the priority (PLAN.md, Phase 10) — the CSS serves it,
 * never fights it. Class names are unchanged where app.js or tests rely on
 * structure (.viewer, .bbox, .kbd-legend, data-key targets).
 */

:root {
  /* Farbtöne */
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --border: #e4e8f1;
  --border-strong: #c9d2e3;
  --text: #131b2e;
  --muted: #5d6579;
  --accent: #1d3fc4;
  --accent-hover: #162f97;
  --accent-weak: #e9eeff;
  --accent-ring: rgba(29, 63, 196, 0.3);
  --error: #b42318;
  --error-weak: #fdecec;
  --warn: #8a5a00;
  --warn-weak: #fff4dc;
  --ok: #0f7a4d;
  --ok-weak: #e5f6ee;

  /* Geometrie */
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-2: 0 8px 24px rgba(16, 24, 40, 0.1);
  --sidebar-w: 236px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { letter-spacing: -0.015em; }

::selection { background: var(--accent-weak); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------------ Shell
 * Sidebar links, Inhalt rechts — gleiche DOM-Reihenfolge wie vorher (Header
 * vor Main), nur als Grid statt Topbar. Auf schmalen Schirmen wird die
 * Sidebar wieder zur Leiste oben.
 */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.1rem 0.8rem 1rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.1rem 0.55rem 0.9rem;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* Signatur: das Beleg-Glyph — ein Kassenbon mit perforierter Unterkante,
 * rein aus CSS (Maske), taucht im Brand und auf der Login-Karte auf. */
.brand::before {
  content: "";
  flex: 0 0 auto;
  width: 17px;
  height: 21px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  -webkit-mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 4px) no-repeat,
    conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) bottom / 25% 4px repeat-x;
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 4px) no-repeat,
    conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) bottom / 25% 4px repeat-x;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.92rem;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active {
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 600;
}

.sidebar .spacer { margin-top: auto; }

.userbox {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.55rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.85rem;
}

.main { min-width: 0; padding: 1.4rem 1.75rem 2.5rem; }
.wrap { max-width: 1400px; margin: 0 auto; }
.wrap-narrow { max-width: 640px; margin: 0 auto; padding: 1rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding-bottom: 0.1rem; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer { margin-top: 0; margin-left: auto; }
  .userbox {
    border-top: 0;
    padding: 0;
    flex-direction: row;
    align-items: center;
  }
  .main { padding: 1rem; }
}

/* ---------------------------------------------------------------- Layout */

.split {
  display: grid;
  grid-template-columns: minmax(320px, 45%) 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 980px) { .split { grid-template-columns: 1fr; } }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row-end { margin-left: auto; }
.stack > * + * { margin-top: 0.85rem; }

/* ------------------------------------------------------------ Components */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-1);
}
.card h2, .card h3 {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.tile { display: block; transition: border-color 120ms ease, box-shadow 120ms ease; }
a.tile:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-2); }
.tile .value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.tile .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.tile.is-error .value { color: var(--error); }
.tile.is-ok .value { color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
/* Breite Tabellen scrollen in ihrer Karte, nicht die ganze Seite. */
.table-scroll { overflow-x: auto; }
th, td { text-align: left; padding: 0.5rem 0.55rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child > td { border-bottom: 0; }
th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-current { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Summenzeile: kräftige Oberkante, volle Schrift — die Summe darf nicht
 * schwächer wirken als ihre Posten. */
tbody tr.is-total > td { border-top: 1px solid var(--border-strong); font-weight: 600; }

hr { border: 0; border-top: 1px solid var(--border); margin: 0.9rem 0; }

.badge {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}
.badge.is-error { background: var(--error-weak); color: var(--error); border-color: currentColor; }
.badge.is-warn { background: var(--warn-weak); color: var(--warn); border-color: currentColor; }
.badge.is-ok { background: var(--ok-weak); color: var(--ok); border-color: currentColor; }
.badge.is-accent { background: var(--accent-weak); color: var(--accent); border-color: currentColor; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent); text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--surface); border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error-weak); border-color: var(--error); }

.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
summary:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: 1px;
}

input:not([type]), input[type="text"], input[type="password"], input[type="date"],
input[type="search"], input[type="number"], input[type="email"], select, textarea {
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  outline: none;
}
label { font-weight: 500; }

/* Feldgruppe: Label über dem Input, feste Mindestbreite in Filterzeilen. */
.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 10rem; }

.note {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 3px;
  background: var(--surface);
  font-size: 0.88rem;
}
.note.is-error { background: var(--error-weak); border-color: var(--error); color: var(--error); }
.note.is-warn { background: var(--warn-weak); border-color: var(--warn); color: var(--warn); }
.note.is-ok { background: var(--ok-weak); border-color: var(--ok); color: var(--ok); }

/* -------------------------------------------------------------- Belegbild */

.viewer {
  position: relative;
  overflow: auto;
  max-height: 78vh;
  background: #1b2033;
  border-radius: var(--radius-sm);
}
.viewer img { display: block; width: 100%; transform-origin: top left; }
.viewer-canvas { position: relative; }
.viewer .bbox {
  position: absolute;
  border: 2px solid #ffd400;
  box-shadow: 0 0 0 9999px rgba(16, 20, 40, 0.45);
  pointer-events: none;
}
.viewer-bar { display: flex; gap: 0.4rem; align-items: center; padding: 0.35rem 0; }
.caption { font-size: 0.82rem; color: var(--muted); margin: 0.35rem 0 0; }

/* ------------------------------------------------------------ Feldeditor */

.field-row { display: grid; grid-template-columns: 11rem 1fr auto; gap: 0.5rem; align-items: center; }
.field-row + .field-row { margin-top: 0.35rem; }
.field-row label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.field-row.is-doubtful input { border-color: var(--warn); background: var(--warn-weak); }
.field-row.is-flagged input { border-color: var(--error); background: var(--error-weak); }
.field-row .meta { font-size: 0.74rem; color: var(--muted); white-space: nowrap; }
.field-hint { font-size: 0.78rem; color: var(--error); grid-column: 2 / -1; }

/* ----------------------------------------------------------------- Modal */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 1.1rem 1.25rem;
  max-width: 32rem;
  width: 90%;
}
dialog::backdrop { background: rgba(19, 27, 46, 0.5); }

/* ------------------------------------------------------- Tastatur-Legende
 * Einklappbar (<details>), aber per .kbd-legend weiterhin das Ziel der
 * "?"-Taste in app.js. Der Verantwortungs-Hinweis bleibt immer sichtbar.
 */

.kbd-legend {
  margin-top: 1.75rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}
.kbd-legend summary { cursor: pointer; user-select: none; }
.kbd-legend .keys {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}
kbd {
  font: 0.78rem var(--mono);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 0.3rem;
  background: var(--surface);
}

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.text-error { color: var(--error); }
.htmx-request { opacity: 0.55; }
/* HTMX-Standardregeln — sonst injiziert htmx sie als Inline-Stylesheet, was
 * die CSP blockt (deshalb includeIndicatorStyles:false in base.html). */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ------------------------------------------------------------------ Login
 * Kein Chrome, nur die Karte: großzügig zentriert, Bon-Glyph über dem
 * Wortmarken-Titel, perforierte Unterkante der Karte als stiller Gruß an den
 * Gegenstand des Systems.
 */

.login-main { margin-top: 14vh; }
.login-card {
  position: relative;
  box-shadow: var(--shadow-2);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 0;
  padding: 1.75rem 1.9rem 1.5rem;
}
/* Perforation unten — die Abrisskante eines Bons. Eigener Streifen statt
 * einer Maske auf der Karte: eine Maske würde auch den Schatten kappen. */
.login-card::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 7px;
  background: var(--surface);
  -webkit-mask: conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) top / 18px 7px repeat-x;
  mask: conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) top / 18px 7px repeat-x;
}
.login-title {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.login-title::before {
  content: "";
  width: 20px;
  height: 25px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  -webkit-mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 5px) no-repeat,
    conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) bottom / 25% 5px repeat-x;
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 5px) no-repeat,
    conic-gradient(from 135deg at 50% 0, #000 90deg, #0000 0) bottom / 25% 5px repeat-x;
}

/* ------------------------------------------------------------- Utilities
 * Ersetzen style="…"-Attribute: die CSP (belegbot/web/middleware.py) sagt
 * `style-src 'self'` — Inline-Styles sind genauso blockiert wie
 * Inline-Skripte. Die eine dynamische Positionierung (.bbox) setzt app.js
 * über das CSSOM.
 */

.flush { margin: 0; }
.flush-top { margin-top: 0; }
.flush-bottom { margin-bottom: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 0.6rem; }
.mt-3 { margin-top: 0.7rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.6rem; }
.mb-3 { margin-bottom: 0.75rem; }
.self-end { align-self: flex-end; }
.row-tight { gap: 0.4rem; }
.input-wide { width: 18rem; }
.input-narrow { width: 10rem; }
.col-severity { width: 6rem; }
.col-code { width: 12rem; }
.col-actions { width: 14rem; }
.page-title { margin: 0; font-size: 1.25rem; font-weight: 700; }

/* --------------------------------------------- Mandanten-Umschalter
 * <details>-Element: die CSP verbietet Inline-Skripte, und ein Menü, das
 * ohne JavaScript nicht aufgeht, wäre genau dann kaputt, wenn ohnehin etwas
 * kaputt ist. Sitzt jetzt oben in der Sidebar.
 */

.switcher { position: relative; margin-bottom: 0.6rem; }
.switcher > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.switcher > summary::-webkit-details-marker { display: none; }
.switcher > summary::after { content: " ▾"; color: var(--muted); }
.switcher-menu {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  min-width: 0;
  margin-top: 0.3rem;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
}
.switcher-menu a { padding: 0.35rem 0.5rem; border-radius: 6px; color: var(--text); }
.switcher-menu a:hover { background: var(--surface-2); text-decoration: none; }
.switcher-menu a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

.grow { flex: 1 1 auto; }

/* Sichtbar für Screenreader, unsichtbar auf dem Schirm. Ein Feld ohne Label
 * ist für jemanden mit Screenreader ein Feld ohne Bedeutung. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Upload-Karte (Phase 16). Die Zone ist ein <label> um das <input type="file">:
 * Klick öffnet den Dateidialog ganz ohne JavaScript, upload.js ergänzt nur
 * Drag & Drop. Das Input bleibt sichtbar fokussierbar, aber optisch versteckt
 * (.visually-hidden wäre display-fremd — hier reicht die Null-Fläche). */
.dropzone {
  display: block;
  padding: 1.5rem 1rem;
  border: 2px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); color: var(--text); }
.dropzone.is-dragover { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); }
.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.upload-results { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.25rem; }
