/* ============================================================================================
   fabrica.css — the only stylesheet. No build step, no framework, no CDN request.
   Structure follows the sister project (tokens, mobile-first, 44px targets, card-collapsing
   tables), with three things deliberately done differently from day one:
     1. every table sits in a .table-scroll wrapper (overflow-x)
     2. the card break runs up to 60rem instead of 40rem — no untested tablet no-man's-land
     3. @media print exists from the start, because quotes and material lists go on paper
   ============================================================================================ */

:root {
  /* Surfaces and ink — warm workshop paper against a deep teal accent. */
  --paper:      #F5F2EC;
  --surface:    #FFFFFF;
  --surface-2:  #EFEAE1;
  --ink:        #23201B;
  --ink-muted:  #6A6357;
  --rule:       #D8D1C4;
  --accent:     #0F5C63;
  --accent-ink: #FFFFFF;
  --accent-soft:#DDECEC;

  /* Semantic pairs — never colour alone, always colour plus text or icon. */
  --pos-fg: #2E6B45; --pos-bg: #E2F0E6;
  --neg-fg: #A63A2B; --neg-bg: #F7E5E1;
  --caut-fg:#8A6410; --caut-bg:#F8EFD8;
  --neut-fg:#6A6357; --neut-bg:#ECE8E0;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --fs-sm: 0.83rem; --fs-md: 1rem; --fs-lg: 1.2rem; --fs-xl: 1.5rem; --fs-2xl: 1.9rem;

  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-6: 1.5rem; --s-8: 2rem; --s-12: 3rem;
  --r-ctl: 5px; --r-panel: 9px;
  --measure: 72ch; --page-max: 1250px;
  --tap: 2.75rem;               /* 44px — the iOS/Android minimum touch target */

  /* breakpoints for reference (media queries cannot read custom properties):
     sm 40rem · md 60rem · lg 80rem */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #16150F;
    --surface:    #201E18;
    --surface-2:  #2A271F;
    --ink:        #EDE8DD;
    --ink-muted:  #A79E8D;
    --rule:       #3A3629;
    --accent:     #63B8BC;
    --accent-ink: #10201F;
    --accent-soft:#1E3A3B;

    --pos-fg: #8FD3A5; --pos-bg: #1D3327;
    --neg-fg: #F0A193; --neg-bg: #3A211C;
    --caut-fg:#E0C078; --caut-bg:#352C14;
    --neut-fg:#A79E8D; --neut-bg:#2A271F;
  }
}

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

html { font-size: 100%; }
@media (min-width: 60rem) { html { font-size: 106.25%; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
}

main {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) var(--s-12);
}

h1 { font-size: var(--fs-2xl); line-height: 1.2; margin: 0 0 var(--s-4); }
h2 { font-size: var(--fs-xl); line-height: 1.25; margin: var(--s-8) 0 var(--s-3); }
h3 { font-size: var(--fs-lg); margin: var(--s-6) 0 var(--s-2); }
p  { margin: 0 0 var(--s-3); }
.measure { max-width: var(--measure); }

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

/* --- top bar and navigation (no JavaScript) ------------------------------------------------ */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s-2) var(--s-4);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3);
}
.brand {
  font-weight: 700; font-size: var(--fs-lg); letter-spacing: .02em;
  color: var(--ink); text-decoration: none;
}
.site-nav { margin-left: auto; }
.nav-menu > summary {
  list-style: none; cursor: pointer;
  min-height: var(--tap); display: inline-flex; align-items: center;
  padding: 0 var(--s-3);
  border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--surface-2);
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu ul {
  list-style: none; margin: var(--s-2) 0 0; padding: var(--s-2);
  position: absolute; right: var(--s-4); z-index: 30;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-panel); box-shadow: 0 8px 24px rgb(0 0 0 / .12);
  min-width: 12rem;
}
.nav-menu a {
  display: flex; align-items: center; min-height: var(--tap);
  padding: 0 var(--s-3); border-radius: var(--r-ctl);
  color: var(--ink); text-decoration: none;
}
.nav-menu a:hover { background: var(--surface-2); }
.nav-menu a[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }
/* Logout is a POST form, not a link (it changes state) - styled identically to a nav item so it
   reads as one, with the button chrome reset to get there. */
.nav-logout { margin: 0; }
.nav-menu .nav-logout button {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: flex; align-items: center; min-height: var(--tap);
  padding: 0 var(--s-3); border-radius: var(--r-ctl);
  color: var(--ink); font: inherit;
}
.nav-menu .nav-logout button:hover { background: var(--surface-2); }
.nav-menu .nav-logout button[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }

@media (min-width: 40rem) {
  .nav-menu > summary { display: none; }
  .nav-menu::details-content { content-visibility: visible; display: contents; }
  .nav-menu ul {
    position: static; display: flex; flex-wrap: wrap; gap: var(--s-1);
    margin: 0; padding: 0; background: none; border: 0; box-shadow: none; min-width: 0;
  }
}
/* Without ::details-content support the menu stays a dropdown — no breakage, just a different
   look on older Safari/Firefox. */

.pagefoot {
  border-top: 1px solid var(--rule);
  color: var(--ink-muted); font-size: var(--fs-sm);
  padding: var(--s-4); text-align: center;
}

/* --- panels, breadcrumbs, sections ---------------------------------------------------------- */

.panel {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-panel); padding: var(--s-4); margin-bottom: var(--s-6);
}
.crumbs { font-size: var(--fs-sm); color: var(--ink-muted); margin-bottom: var(--s-2); }
.crumbs a { color: var(--ink-muted); }
.subtle { color: var(--ink-muted); }
.empty { color: var(--ink-muted); font-style: italic; }

.kv { display: grid; grid-template-columns: 1fr; gap: var(--s-1) var(--s-4); margin: 0 0 var(--s-4); }
.kv dt { color: var(--ink-muted); font-size: var(--fs-sm); }
.kv dd { margin: 0 0 var(--s-2); }
@media (min-width: 40rem) {
  .kv { grid-template-columns: minmax(8rem, 14rem) 1fr; }
  .kv dt { padding-top: .1rem; }
  .kv dd { margin-bottom: var(--s-1); }
}

/* --- forms ----------------------------------------------------------------------------------- */

input[type="text"], input[type="search"], input[type="password"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  font: inherit; color: inherit;
  background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--r-ctl);
  padding: var(--s-2) var(--s-3);
  min-height: var(--tap);
  max-width: 100%;
}
textarea { min-height: 6rem; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

label { font-weight: 600; }
.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field > input, .field > select, .field > textarea { width: 100%; }
.field-hint { font-size: var(--fs-sm); color: var(--ink-muted); font-weight: 400; }
/* Second label inside one field, for the "or type a new one" input under a <select>. Lighter than
   the field's own label so the two do not read as two separate fields. */
.label-sub { font-size: var(--fs-sm); font-weight: 400; color: var(--ink-muted); margin-top: var(--s-1); }
/* The list price beside "Ihr Preis" on a quotation. Struck through and quiet, so the number that
   counts stays the loud one; its own line, because the two must never read as one amount. */
.uvp-streich {
  display: block; font-size: var(--fs-sm); font-weight: 400;
  color: var(--ink-muted); text-decoration: line-through;
}
.field-error { font-size: var(--fs-sm); color: var(--neg-fg); font-weight: 600; margin: 0; }

.form-stack { display: flex; flex-direction: column; gap: var(--s-3); max-width: 40rem; }
.row-form   { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-end; }
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-4); }
.filter-bar input[type="search"] { flex: 1 1 14rem; }
.form-grid {
  display: grid; grid-template-columns: 1fr; gap: var(--s-3);
}
@media (min-width: 40rem) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .span-2 { grid-column: 1 / -1; }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
/* A one-button form that should sit in a row of buttons rather than start a block of its own. */
.inline-form { display: inline; }
@media (max-width: 39.9999rem) {
  /* The primary action must not scroll away in a long form. */
  .form-actions {
    position: sticky; bottom: 0; background: var(--paper);
    border-top: 1px solid var(--rule); padding: var(--s-3) 0; z-index: 10;
  }
}

button, .btn {
  font: inherit; cursor: pointer;
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 0 var(--s-4);
  border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--surface-2); color: var(--ink);
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn--quiet   { background: transparent; }
.btn--danger  { background: var(--neg-bg); border-color: var(--neg-fg); color: var(--neg-fg); font-weight: 600; }
.btn--small   { min-height: 2.25rem; padding: 0 var(--s-3); font-size: var(--fs-sm); }

details.details-edit {
  border: 1px solid var(--rule); border-radius: var(--r-panel);
  background: var(--surface); padding: var(--s-2) var(--s-3); margin-bottom: var(--s-4);
}
details.details-edit > summary {
  cursor: pointer; font-weight: 600;
  min-height: var(--tap); display: flex; align-items: center;
}
details.details-edit[open] > summary { border-bottom: 1px solid var(--rule); margin-bottom: var(--s-3); }

/* --- messages ---------------------------------------------------------------------------------- */

.flash {
  border: 1px solid var(--rule); border-left-width: 5px;
  border-radius: var(--r-ctl); padding: var(--s-3);
  margin: 0 0 var(--s-4);
}
.flash--ok    { background: var(--pos-bg);  border-left-color: var(--pos-fg);  color: var(--pos-fg); }
.flash--warn  { background: var(--caut-bg); border-left-color: var(--caut-fg); color: var(--caut-fg); }
.flash--error { background: var(--neg-bg);  border-left-color: var(--neg-fg);  color: var(--neg-fg); }
.flash ul { margin: var(--s-2) 0 0; padding-left: var(--s-6); }

.badge {
  display: inline-block; padding: .1rem var(--s-2);
  border-radius: 999px; font-size: var(--fs-sm); font-weight: 600;
  background: var(--neut-bg); color: var(--neut-fg);
}
.badge--pos  { background: var(--pos-bg);  color: var(--pos-fg); }
.badge--neg  { background: var(--neg-bg);  color: var(--neg-fg); }
.badge--caut { background: var(--caut-bg); color: var(--caut-fg); }
.badge--neut { background: var(--neut-bg); color: var(--neut-fg); }

/* --- tables ------------------------------------------------------------------------------------ */

/* Every table lives in this wrapper. A wide table then scrolls inside itself instead of
   pushing the whole page sideways. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--rule); border-radius: var(--r-panel);
  background: var(--surface);
  margin-bottom: var(--s-4);
}
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-meta { color: var(--ink-muted); font-size: var(--fs-sm); }
.td-actions { white-space: nowrap; }

/* Card break up to 60rem: tablets in portrait and split screens get cards, not a squeezed grid. */
@media (max-width: 59.9999rem) {
  table.collapsing, table.collapsing tbody, table.collapsing td, table.collapsing tr { display: block; }
  table.collapsing thead { display: none; }
  table.collapsing tr {
    display: flex; flex-direction: column;
    padding: var(--s-3); border-bottom: 1px solid var(--rule);
  }
  table.collapsing td { border: 0; padding: .125rem 0; }
  table.collapsing td:empty { display: none; }
  table.collapsing .td-empty { display: none; }
  table.collapsing .td-key  { order: -3; font-weight: 700; font-size: var(--fs-lg); }
  table.collapsing .td-2    { order: -2; }
  table.collapsing .td-3    { order: -1; }
  table.collapsing .num     { text-align: left; }
  table.collapsing td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--ink-muted); font-size: var(--fs-sm);
  }
  table.collapsing td.td-key::before { content: none; }
  .table-scroll { overflow-x: visible; }
}

/* Nested sections: the indent shows the depth. It stops at three levels so an unexpectedly deep
   tree stays readable rather than walking off the page - the tree itself has no depth limit. */
.bereich-tiefe-1 { margin-left: var(--s-4); border-left: 3px solid var(--rule); }
.bereich-tiefe-2 { margin-left: var(--s-8); border-left: 3px solid var(--rule); }
.bereich-tiefe-3 { margin-left: var(--s-12); border-left: 3px solid var(--rule); }
@media (max-width: 39.9999rem) {
  /* On a phone the indent would eat the content; the badge carries the meaning instead. */
  .bereich-tiefe-1, .bereich-tiefe-2, .bereich-tiefe-3 { margin-left: var(--s-2); }
}
@media print {
  .bereich-tiefe-1 { margin-left: var(--s-4); }
  .bereich-tiefe-2 { margin-left: var(--s-8); }
  .bereich-tiefe-3 { margin-left: var(--s-12); }
}

/* --- the quotation document -------------------------------------------------------------------- */

.angebot-dokument {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  padding: var(--s-6);
  margin-bottom: var(--s-6);
}
.angebot-kopf {
  display: flex; flex-wrap: wrap; gap: var(--s-6); justify-content: space-between;
  border-bottom: 2px solid var(--rule); padding-bottom: var(--s-4); margin-bottom: var(--s-6);
}
/* The letterhead is a flex row so a logo can be dropped in later without moving anything else. */
.angebot-absender p { margin: 0 0 var(--s-1); }
.angebot-firma { font-size: var(--fs-lg); font-weight: 700; }
.angebot-meta { display: grid; grid-template-columns: auto auto; gap: var(--s-1) var(--s-3); margin: 0; }
.angebot-meta dt { color: var(--ink-muted); font-size: var(--fs-sm); }
.angebot-meta dd { margin: 0; text-align: right; }
.angebot-empfaenger h1 { margin-bottom: var(--s-3); }
.angebot-einleitung { margin: var(--s-4) 0 var(--s-6); }
.angebot-bereich { margin-bottom: var(--s-6); }
.angebot-summen { margin-top: var(--s-6); border-top: 2px solid var(--rule); padding-top: var(--s-4); }
.angebot-summen .table-scroll { max-width: 32rem; margin-left: auto; }
.angebot-endpreis td { border-top: 1px solid var(--rule); font-size: var(--fs-lg); }
.angebot-hinweis {
  margin-top: var(--s-4); padding: var(--s-3);
  border-left: 3px solid var(--rule); background: var(--surface-2); font-size: var(--fs-sm);
}

/* A draft must be recognisable as one on paper too, and on EVERY page - not just the first. The
   element is position: fixed for exactly that reason: most browsers repeat a fixed element on each
   printed page, whereas an absolutely positioned one lands on page 1 and is never seen again.
   print-color-adjust keeps the printer from helpfully optimising it away. It is a direct child of
   the page, so no ancestor can turn into a containing block and pin it down. */
.wasserzeichen {
  position: fixed; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; overflow: hidden;
}
/* The text pins ITSELF to the middle of the page - position: fixed plus top/left 50% and a
   translate back by half its own size - instead of being centred inside the container above. The
   container's height is well defined on screen but not on a printed page, which is why the
   watermark used to sit in the lower third. Pinning the text works per page and across browsers. */
.wasserzeichen span {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-24deg);
  font-size: clamp(1.8rem, 6vw, 3rem);
  font-weight: 800; letter-spacing: .05em;
  color: var(--neg-fg); opacity: .14; white-space: nowrap; text-transform: uppercase;
}

/* Only useful in front of a screen: in print the dialog is already gone. */
.druckhinweis {
  max-width: var(--measure); margin-top: var(--s-3);
  font-size: var(--fs-sm); color: var(--ink-muted);
}

@media print {
  /* A sheet of paper needs its own margins - the screen layout's padding is not one. */
  @page { margin: 18mm 16mm; }

  .angebot-dokument { border: 0; padding: 0; background: #FFF; }
  .angebot-kopf, .angebot-summen { border-color: #000; }
  /* Keep a section and its table together where the page allows it, and never break a head or a
     total off from what it belongs to. */
  .angebot-kopf { break-inside: avoid; break-after: avoid; }
  .angebot-empfaenger, .angebot-einleitung { break-inside: avoid; }
  .angebot-bereich { break-inside: avoid; }
  .angebot-summen { break-inside: avoid; break-before: avoid; }
  .angebot-tabelle tr { break-inside: avoid; }
  .angebot-tabelle thead { display: table-header-group; }
  .angebot-hinweis { break-inside: avoid; }
  .druckhinweis { display: none; }

  .wasserzeichen {
    position: fixed;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  /* A fixed 2.4rem rather than a viewport-relative size: 9vw grew past the width of the sheet, so
     the rotated line "ENTWURF - UNVERBINDLICH" ran off the side. This fits A4 portrait within the
     existing @page margins of 18/16 mm. */
  .wasserzeichen span {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) rotate(-24deg);
    font-size: 2.4rem;
    opacity: .16; color: #B3382E;
  }
}

/* Photo gallery. v1 stores originals only (no server-side thumbnails), so the browser scales them
   and loading="lazy" keeps a long page from fetching every full-size image at once. */
.foto-galerie {
  list-style: none; margin: 0 0 var(--s-4); padding: 0;
  display: flex; flex-wrap: wrap; gap: var(--s-3);
}
.foto-karte {
  flex: 1 1 14rem; max-width: 20rem;
  border: 1px solid var(--rule); border-radius: var(--r-panel);
  background: var(--surface); overflow: hidden;
}
.foto-karte img {
  display: block; width: 100%; height: 10rem; object-fit: cover; background: var(--surface-2);
}
.foto-text { padding: var(--s-2) var(--s-3); font-size: var(--fs-sm); }
.foto-block { margin: var(--s-3) 0; }
@media print {
  /* On paper a photo is evidence, not a thumbnail - let it keep its proportions. */
  .foto-karte img { height: auto; }
  .foto-karte { break-inside: avoid; }
}

/* A non-blocking advisory under the line it belongs to (the cheaper-dealer hint). */
.hint-row td { background: var(--caut-bg); color: var(--caut-fg); }
.hint-row .btn { margin-left: var(--s-2); }
/* The inline quantity field sits inside a table cell and must not stretch it. */
.input-menge { width: 6rem; }

/* --- pagination --------------------------------------------------------------------------------- */

.pagination { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; margin: var(--s-4) 0; }
.pagination-info { color: var(--ink-muted); font-size: var(--fs-sm); }

/* --- danger zone ---------------------------------------------------------------------------------- */

.danger-zone {
  margin-top: var(--s-12);
  border: 1px solid var(--neg-fg); border-radius: var(--r-panel);
  background: var(--neg-bg); padding: var(--s-4);
}
.danger-zone h2 { margin-top: 0; color: var(--neg-fg); }

/* --- accessibility helper ------------------------------------------------------------------------- */

.vh {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

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

/* --- print ------------------------------------------------------------------------------------------ */

@media print {
  :root {
    --paper: #FFF; --surface: #FFF; --surface-2: #FFF; --ink: #000; --ink-muted: #333;
    --rule: #999; --accent: #000; --accent-soft: #EEE;
  }
  body { background: #FFF; color: #000; font-size: 10.5pt; }
  .topbar, .pagefoot, .filter-bar, .pagination, .danger-zone,
  .btn, button, form.row-form, details.details-edit, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  a { color: #000; text-decoration: none; }
  a[href^="/"]::after { content: ""; }
  .table-scroll { overflow: visible; border: 0; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }
  h1, h2, h3 { page-break-after: avoid; }
  /* Printed output is a document, not a screen: cards would waste the page. */
  table.collapsing, table.collapsing tbody, table.collapsing tr { display: table-row-group; }
  table.collapsing { display: table; }
  table.collapsing tr { display: table-row; }
  table.collapsing td { display: table-cell; border-bottom: 1px solid var(--rule); }
  table.collapsing thead { display: table-header-group; }
  table.collapsing td[data-label]::before { content: none; }
}
