/*
 * Shared look of the Werkzeugkasten tools: page, header, sidebar panel, inputs,
 * drawings, tables and the printed drawing sheet. Each tool's style.css sets its
 * accent (--tool-accent…) and adds its own rules.
 */

:root {
  --bg: #f8f7f4;
  --surface: #ffffff;
  --surface-2: #f6f5f1;
  --border: #d6d0c5;
  --text: #1c1917;
  --muted: #6b645c;
  /* Accent: each tool sets --tool-accent… (see its style.css) */
  --accent: var(--tool-accent);
  --accent-soft: var(--tool-accent-soft);
  --on-accent: #ffffff;
  --ok: #166534;
  --ok-soft: #e8f5ec;
  --warn: #92400e;
  --warn-soft: #fdf3e4;
  --err: #b91c1c;
  --err-soft: #fdecec;
  /* Drawings sit directly on the page: same tone as --bg in light mode */
  --paper: #f8f7f4;
  --radius: 14px;
  --gutter: 32px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #1b1a18;
    --border: #36322d;
    --text: #ece8e2;
    --muted: #a39b91;
    --accent: var(--tool-accent-dark);
    --accent-soft: var(--tool-accent-soft-dark);
    --on-accent: var(--tool-on-accent-dark);
    --ok: #4ade80;
    --ok-soft: #14291b;
    --warn: #f59e0b;
    --warn-soft: #2e2312;
    --err: #f87171;
    --err-soft: #331a1a;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #171614;
  --surface: #211f1c;
  --surface-2: #1b1a18;
  --border: #36322d;
  --text: #ece8e2;
  --muted: #a39b91;
  --accent: var(--tool-accent-dark);
  --accent-soft: var(--tool-accent-soft-dark);
  --on-accent: var(--tool-on-accent-dark);
  --ok: #4ade80;
  --ok-soft: #14291b;
  --warn: #f59e0b;
  --warn-soft: #2e2312;
  --err: #f87171;
  --err-soft: #331a1a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

var { font-style: italic; font-family: Georgia, "Times New Roman", serif; font-size: 1.05em; }
sub { font-size: 0.72em; line-height: 0; }
var + sub { margin-left: 0.05em; }
.chip var, .chip sub { font-weight: 500; }

h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: 0.01em; }

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  /* Content lines up with the 1600px layout */
  padding: 16px max(var(--gutter), calc((100% - 1600px) / 2 + var(--gutter)));
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand-home { display: flex; border-radius: 8px; }
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: 0; color: var(--accent); }
.actions { display: flex; gap: 8px; flex: none; }

/* Download menu: above page content, below modals (z-index 950) */
.menu-wrap { position: relative; display: flex; }
.btn-menu { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-menu svg { width: 10px; height: 6px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: transform 120ms; }
.btn-menu[aria-expanded="true"] svg { transform: rotate(180deg); }
.btn-menu[aria-busy="true"] { cursor: progress; }
.menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 950;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.menu[hidden] { display: none; }
.menu button {
  font: inherit;
  text-align: left;
  padding: 7px 12px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }

.btn {
  font: inherit;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: 4px;
  /* Secondary by default: page background with an outline */
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); border-color: var(--accent); }
.btn-ghost { width: 100%; background: transparent; color: var(--muted); font-weight: 500; }

/* ---------- Grid ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 48px;
  /* Sidebar starts where the brand mark starts */
  padding: 32px var(--gutter) 0;
  max-width: 1600px;
  margin: 0 auto;
}

/* Bottom space inside the grid row, so the sticky panel is never pushed up under the header */
main { min-width: 0; display: flex; flex-direction: column; gap: 40px; padding-bottom: 64px; }

/* White panel; its outer edge lines up with the page title and the first drawing title */
.panel {
  position: sticky;
  top: 104px; /* header height (72px) + layout top padding: no jump when it sticks */
  align-self: start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  /* Only fields can be selected; labels and titles behave like UI */
  -webkit-user-select: none;
  user-select: none;
  background: var(--surface);
  /* Light tint of the accent, as on the Werkzeugkasten tile */
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--surface));
  border-radius: 12px;
  padding: 16px;
}

/* ---------- Inputs ---------- */

fieldset {
  border: 0;
  margin: 0;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
fieldset[hidden] { display: none; }
legend {
  float: left;
  width: 100%;
  padding: 0;
  margin-bottom: 4px;
  font-size: inherit; /* same as the toggle labels (Hobby / Profi) */
  font-weight: 700;
  color: var(--text);
}
legend + * { clear: both; }
/* Sidebar content starts flush with the first drawing title */
form > fieldset:first-child,
form > fieldset[hidden]:first-child + fieldset { padding-top: 0; }
/* Less space under the last visible section */
form > fieldset:last-of-type { padding-bottom: 4px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row > label, .lbl { color: var(--text); }
.sub { display: flex; flex-direction: column; gap: 12px; padding-left: 2px; }
.sub.disabled { opacity: 0.45; pointer-events: none; }

.field {
  display: flex;
  align-items: center;
  width: 112px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}
.field:focus-within { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.field input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 6px 4px 6px 8px;
  outline: none;
}
.field .unit { color: var(--muted); padding-right: 9px; min-width: 14px; font-size: 12.5px; }
.field .spin {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  border-left: 1px solid var(--border);
  border-radius: 0 3px 3px 0;
  background: var(--surface-2);
}
.field .spin button {
  flex: 1;
  width: 24px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.field .spin button + button { border-top: 1px solid var(--border); }
.field .spin button:first-child { border-top-right-radius: 3px; }
.field .spin button:last-child { border-bottom-right-radius: 3px; }
.field .spin button:hover { background: var(--accent-soft); color: var(--accent); }
.field .spin button:active { background: var(--accent); color: var(--on-accent); }
.field .spin svg { width: 10px; height: 6px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.field:has(.spin) { width: 128px; }
.field.field-sm { width: 76px; }
.field.field-sm:has(.spin) { width: 86px; }
.field:has(.spin) .unit { padding-right: 10px; flex: none; }
.field.invalid { border-color: var(--err); box-shadow: 0 0 0 2px var(--err-soft); }
.field.invalid:focus-within { outline-color: var(--err); }
.field input:disabled { color: var(--muted); }
.field:has(input:disabled) .spin { opacity: 0.4; pointer-events: none; }

select, input.text {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  width: 150px;
  flex: none;
}
select:focus, input.text:focus { border-color: var(--accent); }
select:focus-visible, input.text:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; }

.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
  gap: 2px;
}
.seg label { flex: 1; position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 5px 8px;
  border-radius: 2px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg label.disabled { opacity: 0.4; pointer-events: none; }
.seg-sm { width: 150px; flex: none; }
.seg-sm span { padding: 3px 6px; font-size: 12.5px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 0; }

/* ---------- Status ---------- */

.status { display: flex; flex-direction: column; gap: 10px; }
.status:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
  font-size: 13px;
}
.chip b { font-weight: 650; }
.chip.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.fail { background: var(--err-soft); border-color: transparent; color: var(--err); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

.msgs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.msgs li { display: flex; align-items: flex-start; gap: 8px; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.msgs .error { background: var(--err-soft); color: var(--err); }
.msgs .warn { background: var(--warn-soft); color: var(--warn); }

/* Messages under the inputs: as tall as an input; info in the accent colour, errors in red */
.hint.info, .hint.error { display: flex; align-items: flex-start; gap: 7px; min-height: 34px; padding: 8px 0; }
.hint.info { color: var(--accent); }
.hint.error { color: var(--err); }
.hint.info:empty, .hint.error:empty { display: none; }
/* An error right above an info message: the two read as one block */
.hint.error:not(:empty) + .hint.info { margin-top: -18px; }

/* Icon before a message, centred on its first line: info, or a triangle for errors and warnings */
.hint.info::before, .hint.error::before, .msgs li::before {
  content: "";
  flex: none;
  width: 14px;
  height: 1lh;
  background: currentColor;
  -webkit-mask: var(--msg-icon) center / 14px 14px no-repeat;
  mask: var(--msg-icon) center / 14px 14px no-repeat;
}
.hint.info { --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0Zm-1 7v5h2V7H7Zm1-4a1.1 1.1 0 1 0 0 2.2A1.1 1.1 0 0 0 8 3Z'/%3E%3C/svg%3E"); }
.hint.error, .msgs li { --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M8 1c.4 0 .76.21.96.56l6.86 12.07c.42.74-.12 1.67-.97 1.67H1.15c-.85 0-1.39-.93-.97-1.67L7.04 1.56C7.24 1.21 7.6 1 8 1Zm-1 4.5V10h2V5.5H7Zm1 6.2a1.05 1.05 0 1 0 0 2.1 1.05 1.05 0 0 0 0-2.1Z'/%3E%3C/svg%3E"); }

/* ---------- Cards and drawings ---------- */

/* Sections sit flat on the page: no surface, border or shadow */
.card {
  margin: 0;
  padding: 0;
  min-width: 0;
}

.view figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 650;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 16px;
}
/* Capital letters of the first title start exactly at the top of the sidebar */
main > .view:first-child figcaption { margin-top: -0.16em; }
.badge {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--muted);
}

.paper {
  background: var(--paper);
  border-radius: 8px;
  display: flex;
  justify-content: center;
}
/* White text halos would show as patches on the off-white page */
.paper svg text[stroke="#ffffff"] { stroke: var(--paper); }
.paper svg { display: block; width: 100%; height: auto; max-height: 64vh; }
.paper.scroll { overflow-x: auto; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
.paper.scroll svg { flex: none; max-height: none; }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; align-items: start; }
.card > h2 {
  font-size: 18px;
  font-weight: 650;
  color: var(--accent);
}

/* ---------- Tables ---------- */

/* Visually hidden, still read by screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

table.vals { width: 100%; border-collapse: collapse; font-size: 13px; }
table.vals th {
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  padding: 14px 0 6px;
  border-bottom: 1px solid var(--border);
}
table.vals tbody tr:first-child th { padding-top: 0; }
table.vals td { padding: 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
table.vals td.v { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 12px; }
table.vals td .note { display: block; color: var(--muted); font-size: 12px; }

/* Design checks: items with utilisation bars */
.check-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.check-item:first-child { padding-top: 0; }
.check-item:last-child { border-bottom: 0; padding-bottom: 0; }
.check-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.check-head h3 { font-size: 14px; margin: 0; }
.check-head .ref { color: var(--muted); font-size: 12px; }
.check-rows { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 12.5px; }
.check-rows td, .check-rows tbody th { padding: 2px 0; font-weight: normal; text-align: left; }
.check-rows td.f { color: var(--muted); }
.check-rows td.v { text-align: right; white-space: nowrap; font-weight: 600; }
.eta { display: flex; align-items: center; gap: 10px; }
.eta-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.eta-bar i { display: block; height: 100%; border-radius: 4px; }
.eta-val { font-weight: 700; white-space: nowrap; min-width: 92px; text-align: right; }
.eta.ok i { background: var(--ok); } .eta.ok .eta-val { color: var(--ok); }
.eta.fail i { background: var(--err); } .eta.fail .eta-val { color: var(--err); }
.eta.warn i { background: var(--warn); } .eta.warn .eta-val { color: var(--warn); }
.check-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--err); }

.muted { color: var(--muted); }

.notes a { color: var(--accent); text-underline-offset: 2px; }
.notes ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.panel input, .panel select { -webkit-user-select: text; user-select: text; }

.print-only { display: none; }

/* ---------- Hobby / Profi mode ---------- */

body[data-mode="simple"] .full-only,
body[data-mode="full"] .simple-only { display: none !important; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .btn-menu svg { transition: none; }
}

/* ---------- Narrow screens ---------- */

@media (max-width: 1100px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  :root { --gutter: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  main { padding-bottom: 40px; }
  .panel { position: static; max-height: none; overflow: visible; }
  .app-header { padding-top: 12px; padding-bottom: 12px; }
}

@media (max-width: 560px) {
  /* Stacked header is too tall to keep pinned on phones */
  .app-header { flex-direction: column; align-items: stretch; position: static; }
  /* Full width on phones; no room to indent under the title */
  .actions .btn, .actions .menu-wrap { flex: 1; }
  .menu-wrap .btn { width: 100%; }
  select, input.text { width: 140px; }
}

/* ---------- Print: A4 landscape sheet, then the tool's tables ---------- */

@page { size: A4 landscape; margin: 12mm 16mm; }
@page sheet { size: A4 landscape; margin: 0; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #1c1917; font-size: 9pt; }
  .app { display: none; }
  .print-only { display: block; }
  #print-sheet { page: sheet; }
  #print-sheet svg { display: block; width: 297mm; height: 210mm; }
  .print-page { break-before: page; }
  .print-page h2 { font-size: 12pt; margin-bottom: 6pt; }
  .print-page .cols { columns: 2; column-gap: 12mm; }
  .print-page table.vals td { padding: 3pt 0; }
  .print-page table.vals tr { break-inside: avoid; }
  .print-page .check-item { break-inside: avoid; padding: 7pt 0; }
  .eta-bar { border-color: #ccc; }
}
