/* PCB Fabrication Specification template - v2.
   Two worlds in one file: the app chrome (screen only, styled like
   tools.peterbell.ch) and the printable A4 sheet (fixed Arial 11px, prints
   with margin 0 on an A4 @page). No inline styles anywhere: CSP is
   style-src 'self'. */

:root {
  /* sheet */
  --ink: #222;
  --muted: #666;
  --line: #bbb;
  --accent: #1a1a1a;
  --red: #ff0000;
  --amber: #b57d00;
  /* chrome (matches tools.peterbell.ch) */
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ui-ink: #1b1b19;
  --dim: #6b6b66;
  --ui-line: #dedcd6;
  --ui-accent: #2f5d50;
  --ok: #2e7d55;
  --warn: #9a6a1c;
  --bad: #a63232;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  line-height: 1.4;
  background: var(--bg);
}
button { font-family: var(--sans); }

/* ---- App chrome ------------------------------------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  color: var(--ui-ink);
  border-bottom: 1px solid var(--ui-line);
  padding: 10px 16px 8px;
  font-family: var(--sans);
  font-size: 13px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "brand tools" "status status";
  gap: 6px 18px;
  align-items: center;
}
.brand { grid-area: brand; display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { color: var(--dim); font-size: 12px; }
.toolbar { grid-area: tools; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.toolbar button.red { margin-left: 10px; }
.toolbar button {
  background: var(--panel);
  color: var(--ui-ink);
  border: 1px solid var(--ui-line);
  padding: 6px 11px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}
.toolbar button:hover { border-color: var(--ui-accent); color: var(--ui-accent); }
.toolbar button.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.toolbar button.primary:hover { filter: brightness(1.1); color: #fff; }
.toolbar button.red { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.toolbar button.red:hover { filter: brightness(1.08); color: #fff; }
.toolbar button.quiet { color: var(--dim); }
.private-only { display: none; }
body.mode-private .private-only { display: inline-block; }
body.mode-private .toolbar button.private-only { border-style: dashed; }
.statusline {
  grid-area: status;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--dim);
  font-size: 12px;
}
.statusline #saveStatus.ok { color: var(--ok); }
.statusline #saveStatus.err { color: var(--bad); }
.local-note { color: var(--ok); }

.help {
  max-width: 210mm;
  margin: 14px auto 0;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ui-ink);
  background: var(--panel);
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  padding: 0 14px;
}
.help summary { cursor: pointer; padding: 9px 0; font-weight: 600; color: var(--ui-accent); }
.help-body { padding: 0 0 8px; }
.help-body p { margin: 4px 0 8px; }
.help-body ul { margin: 0 0 8px; padding-left: 18px; }
.help-body li { margin: 3px 0; }
.help .muted, .muted { color: var(--dim); }
.small { font-size: 0.85em; }

.overflow-warn {
  max-width: 210mm;
  margin: 10px auto 0;
  padding: 8px 12px;
  font-family: var(--sans);
  font-size: 13px;
  background: #fff5df;
  color: var(--warn);
  border: 1px solid #e6c87a;
  border-radius: 8px;
}

/* ---- The sheet -------------------------------------------------------- */
.page {
  width: 210mm;
  min-height: 297mm;
  margin: 14px auto 24px;
  padding: 10mm 14mm;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
  position: relative;
}
[contenteditable] { outline: none; }
[contenteditable]:hover { background: #fdf6e3; }
[contenteditable]:focus { background: #fff6d6; box-shadow: inset 0 0 0 1px #d9c97a; }

/* Placeholders: a grey hint in empty fields, never printed. Rendered in flow
   so an empty table cell still takes its natural width. */
span[data-ph] { display: inline-block; min-width: 2em; }
[data-ph].is-empty::before {
  content: attr(data-ph);
  color: #b0b0b0;
  font-weight: normal;
  font-style: italic;
  pointer-events: none;
}

/* Header band */
.hdr { display: flex; align-items: stretch; gap: 12px; border: 1.5px solid var(--accent); padding: 8px 10px; }
.logo-box {
  width: 34mm; min-height: 20mm;
  border: 1px dashed #aaa; color: #aaa; font-size: 9px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  flex-shrink: 0; cursor: pointer; overflow: hidden; position: relative;
  transition: background 0.15s, border-color 0.15s;
}
.logo-box:hover { border-color: #888; }
.logo-box.drag-over { background: #eaf2fb; border-color: #4a90d9; color: #4a90d9; }
.logo-box.has-logo { border-style: solid; border-color: #ddd; }
.logo-box img.logo-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-box .logo-clear {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.55); color: #fff; border: none; border-radius: 50%;
  width: 16px; height: 16px; line-height: 14px; font-size: 11px; cursor: pointer; display: none;
}
.logo-box.has-logo:hover .logo-clear { display: block; }
.hdr .company { flex: 1; min-width: 0; }
.hdr .company strong { font-size: 14px; display: block; min-height: 1.3em; }
.hdr .company div { min-height: 1.3em; }
.hdr .company .contact { color: var(--muted); }
.hdr .meta { text-align: right; min-width: 42mm; }
.hdr .meta .doc-type { font-size: 19px; font-weight: bold; letter-spacing: 0.4px; }

/* Governing note + standards line */
.gov-note { text-align: center; padding: 5px 6px 0; }
.gov-main { font-size: 12px; font-weight: bold; }
.gov-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }
.gov-sub .ckw.inline { margin-left: 8px; }
.ipcsel { font: inherit; font-weight: bold; border: 1px solid #ccc; border-radius: 3px; background: #f5f5f5; padding: 0 2px; }
.ipc-print { display: none; }

/* Spec section boxes */
.spec { border: 1.5px solid var(--accent); margin-top: 6px; }
.spec h3 {
  margin: 0; padding: 3px 6px; text-align: center; font-size: 12px;
  background: #e9e9e9; border-bottom: 1px solid var(--accent);
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.spec table { width: 100%; border-collapse: collapse; }
.spec td { padding: 3px 6px; border: 1px solid var(--line); vertical-align: top; }
.spec td.lbl { font-style: italic; color: var(--muted); white-space: nowrap; width: 1%; }
.spec td.val { font-weight: bold; }
.spec .footnote { padding: 2px 6px; font-size: 9px; color: var(--muted); }
.spec td.ckrow { font-weight: normal; }
.spec td.ckrow .ckw.inline { margin-right: 14px; }
.spec tr.ckgrid td { font-weight: normal; width: 33.33%; }
.spec tr.ckgrid-half td { width: 50%; }

/* Checkboxes */
.ck { display: flex; align-items: baseline; gap: 6px; }
.ck input[type=checkbox], .ckw input[type=checkbox] {
  width: 12px; height: 12px; margin: 0 4px 0 0; position: relative; top: 2px;
  accent-color: var(--accent); flex-shrink: 0;
}
.ck .ck-lbl { white-space: nowrap; }
.ck .ck-note { flex: 1; min-width: 30px; color: var(--muted); border-bottom: 1px dotted #ccc; }
.ck .ck-note .stdsel { margin-left: 8px; }
.ck .ck-note span[data-ph] { min-width: 1em; }
.ckw { display: block; }
.ckw.inline { display: inline; white-space: nowrap; }
.ckw .ck-sub { margin: 1px 0 0 16px; color: var(--muted); }
.ckw .ck-sub [contenteditable], .ckw .ck-sub[contenteditable] { border-bottom: 1px dotted #ccc; }
.ckw.inline .ck-sub { display: inline; margin-left: 4px; }
/* The whole "Refer to: <file>" line demands attention once its box is ticked */
.ckw input:checked ~ .ck-sub { color: var(--red); font-weight: bold; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ckw input:checked ~ .ck-sub [contenteditable] { border-bottom-color: var(--red); }
.ckw .ck-extra { display: none; margin-left: 6px; color: var(--muted); white-space: nowrap; }
.ckw input:checked ~ .ck-extra { display: inline; }

/* Standard-options dropdown and buttons inside the sheet: screen only */
.stdsel {
  font-size: 9px; color: #555; background: #f5f5f5; border: 1px solid #ccc;
  border-radius: 3px; margin-left: 6px; max-width: 64px; vertical-align: middle;
}
.today-btn {
  border: 1px solid #bbb; background: #f0f0f0; color: #444; font-size: 9px; line-height: 1.3;
  padding: 0 5px; border-radius: 3px; cursor: pointer; margin-left: 6px; vertical-align: middle;
}
.today-btn:hover { background: #dff0df; border-color: #2e7d32; color: #2e7d32; }

/* Calculated cell */
td.calc { background: #eef2f6; color: #333; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
td.calc.ar-warn { background: #fff3d6; color: var(--amber); }
td.calc.ar-bad { background: #ffe3e3; color: var(--red); }

/* Critical (bold red) marking */
.crit { color: var(--red); font-weight: bold; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

.page-footer {
  position: absolute; bottom: 5mm; left: 14mm; right: 14mm;
  display: flex; justify-content: space-between;
  font-size: 9px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 3px;
}

/* ---- Site footer ------------------------------------------------------ */
.disclaimer {
  max-width: 210mm; margin: 0 auto 32px; padding-top: 12px;
  border-top: 1px solid var(--ui-line);
  font-family: var(--sans); font-size: 12.5px; color: var(--dim); line-height: 1.5;
}
.disclaimer p { margin: 0 0 6px; }
.disclaimer strong { color: var(--ui-ink); }
.disclaimer a { color: var(--ui-accent); }
.disclaimer .local-note { color: var(--ok); }
button.link {
  background: none; border: none; padding: 0; margin: 0; font: inherit;
  color: var(--ui-accent); text-decoration: underline; cursor: pointer;
}

/* ---- Modal gates (consent, decline, privacy) -------------------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 20, 18, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  font-family: var(--sans); font-size: 14px; color: var(--ui-ink); line-height: 1.5;
}
.gate[hidden] { display: none; }
.gate-card {
  background: var(--panel); border-radius: 10px; max-width: 640px; width: 100%;
  max-height: calc(100vh - 32px); overflow: auto; padding: 22px 26px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.gate-card h2 { margin: 0 0 10px; font-size: 20px; }
.gate-card h3 { margin: 0 0 6px; font-size: 15px; }
.gate-card p { margin: 0 0 10px; }
.gate-card a { color: var(--ui-accent); }
.telemetry-box { background: var(--bg); border: 1px solid var(--ui-line); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.telemetry-notice { font-size: 13px; }
.telemetry-notice ul { margin: 2px 0 8px; padding-left: 20px; }
.telemetry-notice .tn-head { font-weight: 600; margin: 8px 0 2px; }
.gate-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.gate-card button.primary {
  background: var(--ui-accent); color: #fff; border: 1px solid var(--ui-accent);
  padding: 8px 16px; border-radius: 6px; font-size: 14px; cursor: pointer;
}
.gate-card button.primary:hover { filter: brightness(1.1); }
body.gated { overflow: hidden; }

/* ---- Print ------------------------------------------------------------ */
@media print {
  body { background: #fff; }
  .appbar, .help, .overflow-warn, .disclaimer, .gate { display: none !important; }
  .page { margin: 0; box-shadow: none; width: auto; min-height: 100vh; padding: 10mm 14mm; }
  .stdsel, .today-btn, .ipcsel { display: none !important; }
  .ipc-print { display: inline; }
  .logo-box:not(.has-logo) { visibility: hidden; }
  .logo-box .logo-clear { display: none !important; }
  [contenteditable]:hover, [contenteditable]:focus { background: none; box-shadow: none; }
  [data-ph].is-empty::before { display: none; }
  @page { size: A4; margin: 0; }
}

/* ---- Narrow screens: let the sheet scroll sideways rather than squash --- */
@media (max-width: 820px) {
  #doc { overflow-x: auto; }
  .appbar { grid-template-columns: 1fr; grid-template-areas: "brand" "tools" "status"; }
  .toolbar { justify-content: flex-start; }
}
