/* Kundenportal (INT-42) -- design tokens first, then components.
   Every value below the token block is a token. Mobile-first; breakpoints
   at 48rem (768px) and 64rem (1024px) -- literal, because media queries
   cannot read custom properties. No web fonts: system stack only.
   Brand colours are placeholders (neutral + one accent) until Matteo
   supplies the Zorn Technik Support CI. */

:root {
  color-scheme: light dark;

  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --leading: 1.5;
  --leading-tight: 1.25;
  --weight-normal: 400;
  --weight-medium: 550;
  --weight-bold: 650;

  /* space */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* shape */
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;
  --border-width: 1px;
  --focus-width: 3px;
  --focus-offset: 2px;
  --touch: 2.75rem;          /* 44px minimum target */
  --content: 56rem;
  --form: 36rem;
  --auth: 26rem;
  --space-0: 0.125rem;
  --radius-pill: 999px;
  --rule: 2px;               /* timeline line, focus ring of the timeline dot */
  --control-s: 2.25rem;      /* small buttons */
  --control-m: 2.5rem;       /* segmented tabs */
  --check: 1.25rem;
  --check-nudge: 0.15rem;    /* aligns the box with the first text line */
  --textarea: 8rem;
  --dot: 0.7rem;
  --dot-left: -0.4rem;       /* centres the dot on the timeline rule */
  --dot-top: 0.45rem;
  --log-time: 11rem;         /* audit view columns (A7) */
  --log-person: 12rem;

  /* colour, light */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1a1e24;
  --muted: #555e6b;
  --border: #d5d9e0;
  --accent: #1d5bb8;
  --accent-hover: #174a97;
  --on-accent: #ffffff;
  --focus: #1d5bb8;

  --open-fg: #1d4f99;   --open-bg: #e6eefb;
  --work-fg: #7a4d00;   --work-bg: #fdf1d8;
  --done-fg: #16692d;   --done-bg: #e4f4e8;
  --stop-fg: #4d5561;   --stop-bg: #eceef1;
  --danger-fg: #a4231a; --danger-bg: #fcebe9;
  --notice-fg: #16692d; --notice-bg: #e4f4e8;

  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --text: #e7eaef;
    --muted: #a3acb8;
    --border: #2e3540;
    --accent: #7aaeff;
    --accent-hover: #9cc2ff;
    --on-accent: #0b1422;
    --focus: #7aaeff;

    --open-fg: #a9c8ff;   --open-bg: #16294a;
    --work-fg: #f5cd72;   --work-bg: #3a2c0c;
    --done-fg: #86e0a0;   --done-bg: #123321;
    --stop-fg: #c3cad4;   --stop-bg: #262c35;
    --danger-fg: #ffaaa2; --danger-bg: #3d1916;
    --notice-fg: #86e0a0; --notice-bg: #123321;

    --shadow: none;
  }
}

/* -- base ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading);
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { line-height: var(--leading-tight); margin: 0 0 var(--space-3); }
h1 { font-size: var(--text-xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-lg); font-weight: var(--weight-bold); }
p { margin: 0 0 var(--space-3); }

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* -- layout ---------------------------------------------------------------- */

.topbar {
  background: var(--surface);
  border-bottom: var(--border-width) solid var(--border);
}

.topbar-inner, .wrap {
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.brand { font-weight: var(--weight-bold); color: var(--text); text-decoration: none; }
.brand-firma { display: block; font-size: var(--text-sm); font-weight: var(--weight-normal); color: var(--muted); }

.who { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-sm); color: var(--muted); }
.who form { margin: 0; }

.wrap { padding-top: var(--space-5); padding-bottom: var(--space-7); }

.narrow { max-width: var(--form); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-head h1 { margin: 0; }

/* -- buttons & forms --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: var(--space-2) var(--space-4);
  font: inherit;
  font-weight: var(--weight-medium);
  color: var(--text);
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-m);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-primary { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { color: var(--on-accent); background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger-fg); border-color: var(--danger-fg); }
.btn-danger:hover { color: var(--danger-fg); background: var(--danger-bg); }
.btn-small { min-height: var(--control-s); padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }

.field { margin-bottom: var(--space-4); }
.field label, .field .label { display: block; margin-bottom: var(--space-1); font-weight: var(--weight-medium); }
.hint-inline { font-weight: var(--weight-normal); font-size: var(--text-sm); color: var(--muted); }
.hint { display: block; margin-top: var(--space-1); font-size: var(--text-sm); color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
select, textarea {
  width: 100%;
  min-height: var(--touch);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-s);
}
textarea { min-height: var(--textarea); resize: vertical; }

.check { display: flex; gap: var(--space-2); align-items: flex-start; margin-bottom: var(--space-3); }
.check input { width: var(--check); height: var(--check); margin-top: var(--check-nudge); flex: none; }

.grid-2 { display: grid; gap: 0 var(--space-4); }

.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

/* -- panels, notices ---------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow);
}

.notice, .alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-m);
  margin-bottom: var(--space-4);
}
.notice { color: var(--notice-fg); background: var(--notice-bg); }
.alert { color: var(--danger-fg); background: var(--danger-bg); }
.stale { color: var(--work-fg); background: var(--work-bg); }

/* -- toolbar: filter + sort ------------------------------------------------- */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius-m);
  list-style: none;
  margin: 0;
}
.tabs li { flex: 1; }
.tabs a {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--control-m);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-s);
  color: var(--text);
  text-decoration: none;
  font-weight: var(--weight-medium);
  border: var(--border-width) solid transparent;
}
/* A border, not an outline: an outline here would override the keyboard
   focus ring of :focus-visible (found in the A5 focus check). */
.tabs a[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); border-color: var(--border); }

.sort { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0; }
.sort label { flex-basis: 100%; font-size: var(--text-sm); color: var(--muted); }
.sort select { width: auto; flex: 1; min-width: 0; }

/* -- to-do list ----------------------------------------------------------------- */

.todos { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }

.todo {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}
.todo:hover { border-color: var(--accent); color: var(--text); }
.todo-title { font-weight: var(--weight-medium); font-size: var(--text-base); overflow-wrap: anywhere; }
.todo-number { color: var(--muted); font-weight: var(--weight-normal); }

.meta { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; font-size: var(--text-sm); color: var(--muted); }

.badge {
  display: inline-block;
  padding: var(--space-0) var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  line-height: var(--leading);
}
.status-offen { color: var(--open-fg); background: var(--open-bg); }
.status-arbeit { color: var(--work-fg); background: var(--work-bg); }
.status-erledigt { color: var(--done-fg); background: var(--done-bg); }
.status-abgebrochen { color: var(--stop-fg); background: var(--stop-bg); }
.overdue { color: var(--danger-fg); font-weight: var(--weight-bold); }
.chip { padding: var(--space-0) var(--space-2); border: var(--border-width) solid var(--border); border-radius: var(--radius-pill); font-size: var(--text-xs); }

.empty { text-align: center; color: var(--muted); padding: var(--space-6) var(--space-4); }

/* -- detail ------------------------------------------------------------------------ */

.facts { display: grid; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }
.facts div { display: grid; gap: 0; }
.facts dt { font-size: var(--text-sm); color: var(--muted); }
.facts dd { margin: 0; font-weight: var(--weight-medium); }

.description { white-space: pre-line; overflow-wrap: anywhere; }
.description:empty::before { content: "Keine Beschreibung."; color: var(--muted); }

.history { list-style: none; margin: 0; padding: 0; border-left: var(--rule) solid var(--border); }
.history li { position: relative; padding: 0 0 var(--space-3) var(--space-4); }
.history li::before {
  content: "";
  position: absolute;
  left: var(--dot-left);
  top: var(--dot-top);
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: var(--surface);
  border: var(--rule) solid var(--accent);
}
.history time { display: block; font-size: var(--text-sm); color: var(--muted); }

.back { display: inline-block; margin-bottom: var(--space-3); }

/* -- login ----------------------------------------------------------------------- */

.auth { max-width: var(--auth); margin: 0 auto; }
.auth .panel h2 { font-size: var(--text-base); }

.wish { color: var(--work-fg); font-weight: var(--weight-medium); }

/* -- reorder "Unsere Reihenfolge" (A6) ---------------------------------------------
   The ▲/▼ buttons are the single-pointer alternative to dragging (WCAG 2.5.7)
   and work without script; rang.js unhides the grip ⠿. */

.sortable > li { display: flex; gap: var(--space-2); align-items: stretch; }
.sortable > li > .todo { flex: 1; min-width: 0; }
.rank-ctl { display: flex; flex-direction: column; justify-content: center; gap: var(--space-1); }
.rank-ctl form { margin: 0; }
.btn-step, .handle { min-width: var(--touch); min-height: var(--touch); padding: 0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); color: var(--text); }
.handle {
  font: inherit;
  font-size: var(--text-lg);
  color: var(--muted);
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-s);
  cursor: grab;
  touch-action: none;       /* a finger on the grip drags instead of scrolling */
  user-select: none;
}
.handle:hover { color: var(--text); border-color: var(--accent); }
.dragging > .todo { border-color: var(--accent); box-shadow: 0 0 0 var(--rule) var(--accent); }
.dragging .handle { cursor: grabbing; color: var(--accent); }

/* -- navigation, people, audit (A7) ------------------------------------------------- */

.mainnav {
  display: flex;
  gap: var(--space-1) var(--space-4);
  flex-wrap: wrap;
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 var(--space-4) var(--space-2);
  font-size: var(--text-sm);
}
.mainnav a { display: inline-flex; align-items: center; min-height: var(--touch); color: var(--text); font-weight: var(--weight-medium); }

.people { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: grid; gap: var(--space-3); }
.person { display: grid; gap: var(--space-2); }
.person-head { display: grid; gap: var(--space-1); }
.person-name { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.person-mail { font-size: var(--text-sm); color: var(--muted); overflow-wrap: anywhere; }
.person-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.person-actions form { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.inline-form select { width: auto; }
.roles { grid-template-columns: 1fr; }

.log { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.log-row {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-m);
  font-size: var(--text-sm);
}
.log-row time { color: var(--muted); }
.log-person { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.log-row .badge { justify-self: start; }

/* -- tabs Stunden / Hardware ------------------------------------------------------- */

.sum { margin: var(--space-4) 0 var(--space-1); font-size: var(--text-lg); }
.hour-row { display: grid; gap: var(--space-1); padding: var(--space-3) var(--space-4); }
.hour-day { font-size: var(--text-sm); color: var(--muted); }
.hour-text { overflow-wrap: anywhere; }

/* -- breakpoints ------------------------------------------------------------------ */

@media (min-width: 48rem) {
  h1 { font-size: var(--text-2xl); }
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
  .tabs li { flex: none; }
  .sort { flex-wrap: nowrap; }
  .sort label { flex-basis: auto; white-space: nowrap; }
  .sort select { flex: none; }
  .todo { grid-template-columns: 1fr auto; align-items: center; }
  .todo .meta { justify-content: flex-end; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: repeat(3, 1fr); }
  .roles { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: var(--space-5); }
  .person-head { grid-template-columns: 1fr auto; align-items: center; }
  .log-row { grid-template-columns: var(--log-time) var(--log-person) 1fr auto; align-items: center; }
  .hour-row { grid-template-columns: var(--log-person) 1fr auto; align-items: center; }
}

@media (min-width: 64rem) {
  .detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: var(--space-4); align-items: start; }
}

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