/* PrintDoc Lab - one stylesheet for every page. */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1c212d;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #e8effe;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --warn: #d97706;
  --warn-soft: #fdf3e2;
  --bad: #dc2626;
  --bad-soft: #fdeaea;
  --side: #0f172a;
  --side-ink: #cbd5e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 14.5px; }
p { margin: 0 0 .8em; }
code { font-family: var(--mono); font-size: 12.5px; background: #eef2f7; padding: 1px 5px; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 12.5px; background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow: auto; margin: 0 0 1em; }
pre code { background: none; padding: 0; color: inherit; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 270px; flex: 0 0 270px; background: var(--side); color: var(--side-ink);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 14px 30px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff; font-size: 17px;
}
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: #94a3b8; }
.nav-group { margin-top: 14px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--side-ink); font-size: 13.5px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .num {
  font: 600 11px var(--mono); background: rgba(255,255,255,.08); color: #93c5fd;
  padding: 2px 6px; border-radius: 6px; min-width: 34px; text-align: center;
}
.nav a.active .num { background: rgba(255,255,255,.2); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar .crumb { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.topbar .links { display: flex; gap: 6px; }
.content { padding: 24px 28px 48px; max-width: 1360px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head p { color: var(--muted); margin: 0; max-width: 760px; }

/* ---------- Building blocks ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.split-wide { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.sticky { position: sticky; top: 80px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }

.chip { display: inline-flex; align-items: center; gap: 6px; font: 600 11.5px var(--mono); padding: 3px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #eef2f7; color: #475569; }
.badge.PAID, .badge.DONE, .badge.SENT-ok, .badge.SAVED, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.SENT, .badge.info { background: var(--brand-soft); color: var(--brand-dark); }
.badge.OVERDUE, .badge.FAILED, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.DRAFT, .badge.QUEUED, .badge.warn { background: var(--warn-soft); color: var(--warn); }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: #b7e4c4; color: #14532d; }
.alert.bad { background: var(--bad-soft); border-color: #f5c2c2; color: #7f1d1d; }
.alert.info { background: var(--brand-soft); border-color: #c7d7fb; color: #1e3a8a; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.field > small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], input[type=url], select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: var(--mono); font-size: 13px; line-height: 1.6; min-height: 420px; tab-size: 2; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; }
input[type=range] { width: 100%; accent-color: var(--brand); }
input[type=file] { font: inherit; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 4px; margin: 0 0 14px; }
legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px; }
.seg { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 9px; overflow: hidden; }
.seg label { display: flex; align-items: center; gap: 6px; padding: 7px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid #cbd5e1; }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: 600 13.5px inherit; font-family: inherit;
  padding: 8px 14px; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; color: var(--ink); cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f1b4b4; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:hover td { background: #f8fafc; }
table.data .r, .r { text-align: right; }
table.data .c { text-align: center; }
table.data .nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { font: 600 13.5px inherit; font-family: inherit; background: none; border: 0; padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- PDF + paper preview ---------- */
.pdf-frame { width: 100%; height: 78vh; min-height: 520px; border: 1px solid var(--line); border-radius: 10px; background: #525659; }
.pdf-frame.short { height: 60vh; }
.stage { background: #e5e9f0; border-radius: 10px; padding: 26px; overflow: auto; max-height: 80vh; }
.paper {
  background: #fff; margin: 0 auto; box-shadow: 0 2px 10px rgba(0,0,0,.18); position: relative; color: #1c212d;
  transform-origin: top center;
}
.paper .paper-inner { position: absolute; inset: 0; overflow: hidden; }
.paper-watermark {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-weight: 800; color: rgba(200, 30, 45, .15); transform: rotate(-35deg); font-size: 96px; letter-spacing: .05em;
}
.paper-header, .paper-footer { position: absolute; left: 0; right: 0; font-size: 9px; color: #64748b; display: flex; justify-content: space-between; }
.paper-header.line { border-bottom: 1px solid #d6dbe4; padding-bottom: 3px; }
.margin-guide { position: absolute; border: 1px dashed rgba(37,99,235,.35); pointer-events: none; }

/* HTML invoice inside the paper */
.doc { font-size: 11px; }
.doc .doc-top { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.doc .co-name { font-size: 18px; font-weight: 700; color: var(--brand); }
.doc .doc-title { font-size: 26px; font-weight: 800; text-align: right; }
.doc .bill { background: #f3f6fb; padding: 10px 12px; border-radius: 4px; }
.doc table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.doc th { background: var(--brand); color: #fff; text-align: left; padding: 6px; font-size: 10px; }
.doc td { padding: 5px 6px; border-bottom: 1px solid #e2e8f0; }
.doc tr:nth-child(even) td { background: #f8fafc; }
.doc .totals { width: 45%; margin-left: auto; }
.doc .totals td { border: 0; }
.doc .totals .grand td { background: #1c212d; color: #fff; font-weight: 700; font-size: 13px; }

/* Thermal receipt preview */
.receipt-paper { background: #fff; margin: 0 auto; padding: 14px 12px 22px; font: 12px/1.45 var(--mono); color: #111; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  background-image: radial-gradient(circle at 6px -2px, transparent 6px, #fff 6.5px); }
.receipt-paper.w80 { width: 302px; }
.receipt-paper.w58 { width: 219px; font-size: 10.5px; }
.receipt-paper .c { text-align: center; }
.receipt-paper .line { border-top: 1px dashed #999; margin: 6px 0; }
.receipt-paper .kv { display: flex; justify-content: space-between; gap: 8px; }
.receipt-paper .big { font-size: 1.45em; font-weight: 700; }
.receipt-paper img { display: block; margin: 6px auto 0; }

/* ---------- Home ---------- */
.hero { background: linear-gradient(135deg, #1e3a8a, #2563eb 55%, #6366f1); color: #fff; border-radius: 16px; padding: 26px 28px; margin-bottom: 20px; position: relative; overflow: hidden; }
.hero h1 { font-size: 26px; margin-bottom: 6px; }
.hero p { color: #dbeafe; max-width: 760px; }
.hero .row .btn { border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff; }
.hero .row .btn.light { background: #fff; color: var(--brand-dark); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 24px; }
.kpi span { color: var(--muted); font-size: 12.5px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 13px 14px; color: var(--ink); transition: transform .12s, box-shadow .12s, border-color .12s; }
.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); border-color: #bfd0f7; }
.tile .chip { margin-bottom: 6px; }
.tile b { display: block; margin-bottom: 3px; }
.tile span { color: var(--muted); font-size: 12.5px; }
.group-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 18px 0 8px; }

/* ---------- Study notes ---------- */
details.study { background: #fffdf5; border: 1px solid #f1e3b4; border-radius: var(--radius); padding: 0; margin-bottom: 18px; }
details.study > summary { cursor: pointer; padding: 12px 18px; font-weight: 700; color: #854d0e; list-style: none; display: flex; align-items: center; gap: 8px; }
details.study > summary::before { content: "\25B8"; transition: transform .15s; }
details.study[open] > summary::before { transform: rotate(90deg); }
details.study .study-body { padding: 0 18px 14px; }
details.study ul { margin: 0 0 1em; padding-left: 20px; }

/* ---------- Template editor ---------- */
.tpl-preview { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px 32px; min-height: 420px; font-size: 13px; }
.tpl-preview h1 { font-size: 22px; }
.tpl-preview h2 { font-size: 16px; color: var(--brand); margin-top: 8px; }
.tpl-table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; }
.tpl-table th { background: var(--brand); color: #fff; text-align: left; padding: 5px 7px; font-size: 12px; }
.tpl-table td { padding: 5px 7px; border-bottom: 1px solid var(--line); }
.tpl-table .r { text-align: right; }
.tpl-totals { margin-left: auto; min-width: 260px; border-collapse: collapse; }
.tpl-totals td { padding: 3px 7px; text-align: right; }
.tpl-totals .grand td { font-weight: 700; border-top: 2px solid var(--ink); }
.tpl-space { height: 10px; }
.tpl-sign { margin-top: 34px; width: 240px; font-size: 12px; }
.tpl-sign-line { border-top: 1px solid #94a3b8; margin-bottom: 4px; }
.tpl-pagebreak { border-top: 2px dashed #f59e0b; color: #b45309; font-size: 11px; text-align: center; margin: 14px 0; }
.tpl-error { color: var(--bad); font-style: italic; }
.tpl-barcode { max-height: 70px; }
.tpl-qr { width: 110px; }
.field-list { font: 12px var(--mono); max-height: 300px; overflow: auto; }
.field-list div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--line); cursor: pointer; }
.field-list div:hover { color: var(--brand); }
.field-list span:last-child { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }

/* ---------- Barcode studio ---------- */
.code-stage { background: repeating-conic-gradient(#f1f5f9 0% 25%, #fff 0% 50%) 50% / 18px 18px; border: 1px solid var(--line); border-radius: 10px; min-height: 280px; display: grid; place-items: center; padding: 20px; }
.code-stage img { max-width: 100%; image-rendering: pixelated; }
.preset-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

/* Signature pad */
.sigpad { border: 1px dashed #94a3b8; border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 130px; cursor: crosshair; }

/* Label sheet thumbnail */
.sheet-thumb { display: grid; gap: 3px; background: #fff; border: 1px solid var(--line); padding: 6px; border-radius: 6px; aspect-ratio: 210 / 297; width: 150px; }
.sheet-thumb i { background: var(--brand-soft); border-radius: 2px; }
.sheet-thumb i.skip { background: #f1f5f9; }

/* Paper diagram */
.paper-diagram { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; padding: 8px 0; }
.paper-diagram div { border: 1.5px solid #94a3b8; background: #fff; display: grid; place-items: center; font-size: 10.5px; color: var(--muted); border-radius: 2px; }
.paper-diagram div.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }

.print-only { display: none; }

@media (max-width: 1100px) {
  .split, .split-wide, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpis, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky { position: static; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: static; width: auto; height: auto; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- 351/352: what the browser prints ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, details.study, .page-head, .alert { display: none !important; }
  .shell, .main, .content { display: block; padding: 0; margin: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .stage { background: none; padding: 0; max-height: none; overflow: visible; }
  .paper { box-shadow: none; margin: 0; zoom: 1 !important; }
  .print-only { display: block; }
  .receipt-paper { box-shadow: none; margin: 0; }
}
