:root {
  /* Theme colours — the defaults are the "Matttech" preset; app.js
     overwrites these five from the store's saved theme on load.
     --line and --muted are derived so they track any theme. */
  --orange: #f26a1b;
  --ink: #17181c;
  --panel: #ffffff;
  --bg: #f4f4f6;
  --gold: #b98a1c;
  --line: color-mix(in srgb, var(--ink) 14%, var(--panel));
  --muted: color-mix(in srgb, var(--ink) 60%, var(--panel));
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--ink); }

.topbar { background: var(--ink); color: #fff; padding: 12px 20px; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 42px; height: 42px; border-radius: 10px; background: var(--orange); color: #fff; font-weight: 800; font-size: 24px; display: flex; align-items: center; justify-content: center; }
.brand-name { font-size: 19px; font-weight: 700; }
.brand-sub { font-size: 12px; color: #c9cad1; }
.demo-badge { background: var(--orange); color: #fff; border-radius: 4px; padding: 1px 6px; font-weight: 700; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { background: #26272e; color: #e8e8ec; border: 1px solid #34353d; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
.lang-toggle { white-space: nowrap; }
.lang-toggle span.on { font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
/* Dark themes: the top bar can't be the (light) text colour — use a
   deepened panel tone instead. */
html[data-mode="dark"] .topbar { background: color-mix(in srgb, var(--panel) 55%, #000); }
html[data-mode="dark"] .tab { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.16); color: var(--ink); }
html[data-mode="dark"] .tab.active { background: var(--orange); border-color: var(--orange); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 18px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"], .toolbar select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--panel); color: var(--ink); }
.btn { background: var(--orange); color: #fff; border: none; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #fff; color: #b3261e; border: 1px solid #e5b6b3; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; transition: box-shadow .15s; }
.card:hover { box-shadow: 0 6px 22px rgba(0,0,0,.10); }
.gem { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 52px; background: linear-gradient(135deg, #fdf3e3, #f7e3c2 55%, #efd9ab); border-bottom: 1px solid var(--line); }
.card-photo { width: 100%; height: 120px; object-fit: cover; display: block; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--gold) 10%, var(--panel)); }
.card-body { padding: 13px 15px 15px; }
.card-name { font-weight: 700; font-size: 16px; }
.card-meta { color: var(--muted); font-size: 12.5px; margin: 2px 0 8px; }
.card-nums { display: flex; justify-content: space-between; font-size: 13.5px; }
.card-nums .price { font-weight: 800; color: var(--gold); font-size: 16px; }

table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.list th { background: color-mix(in srgb, var(--ink) 4%, var(--panel)); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list select { background: var(--panel); color: var(--ink); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* Editor */
.overlay { position: fixed; inset: 0; background: rgba(15,15,20,.5); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 26px 12px; z-index: 40; }
.sheet { background: var(--panel); border-radius: 16px; width: 860px; max-width: 100%; padding: 22px 24px 26px; }
.sheet h2 { margin: 0 0 4px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 14px 0; }
label.f { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
label.f input, label.f select, label.f textarea { width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink); font-weight: 400; background: var(--panel); }
table.comp { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.comp th, table.comp td { padding: 6px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
table.comp input, table.comp select { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13.5px; background: var(--panel); color: var(--ink); }
table.comp td.c-qty, table.comp td.c-cost { width: 92px; }
table.comp td.c-unit { width: 70px; }
table.comp td.c-kind { width: 118px; }
table.comp td.c-x { width: 34px; text-align: center; }
.xbtn { background: none; border: none; color: #b3261e; font-size: 17px; cursor: pointer; }
.totals { display: flex; gap: 26px; justify-content: flex-end; align-items: baseline; margin-top: 14px; font-size: 15px; flex-wrap: wrap; }
.totals .grand { font-size: 20px; font-weight: 800; color: var(--gold); }
.kind-chip { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }

/* Labels */
.label-controls { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.pick input[type="number"] { background: var(--panel); color: var(--ink); }
.pick:last-child { border-bottom: none; }
.tag-sheet { display: flex; flex-wrap: wrap; gap: 10px; }
.tag { width: 300px; height: 62px; background: #fff; color: #17181c; border: 1.5px solid #999; border-radius: 31px; display: flex; overflow: hidden; font-family: Arial, sans-serif; }
.tag .lobe { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; justify-content: center; }
.tag .bridge { width: 54px; border-left: 1.5px dashed #bbb; border-right: 1.5px dashed #bbb; display: flex; align-items: center; justify-content: center; background: repeating-linear-gradient(90deg, #111 0 2px, transparent 2px 5px, #111 5px 6px, transparent 6px 10px); }
.tag .t-name { font-size: 11.5px; font-weight: 700; line-height: 1.15; }
.tag .t-sub { font-size: 9.5px; color: #444; }
.tag .t-price { font-size: 17px; font-weight: 800; text-align: right; }
.tag .t-sku { font-size: 9.5px; color: #444; text-align: right; }

/* Catalogue print preview — a paper document: stays white with dark
   text whatever theme the app chrome is wearing. */
.cat-page { background: #fff; color: #22252b; border: 1px solid var(--line); border-radius: 12px; padding: 26px; }
.cat-page .hint { color: #6d6f78; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.cat-item { display: flex; gap: 14px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.cat-item .gem { width: 108px; height: 92px; font-size: 38px; border: 1px solid var(--line); border-radius: 10px; flex: none; }
.cat-item img.cat-photo { width: 108px; height: 92px; object-fit: cover; border: 1px solid var(--line); border-radius: 10px; flex: none; background: #f7f2e7; }
#imp-text { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; font-size: 13.5px; }

/* Editor photo */
.photo-block { display: flex; gap: 16px; margin: 14px 0 4px; align-items: flex-start; flex-wrap: wrap; }
.photo-preview { width: 280px; max-width: 100%; flex: none; }
.photo-preview img { width: 100%; max-height: 260px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--gold) 7%, var(--panel)); display: block; }
.photo-empty { border: 1.5px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 13.5px; padding: 34px 12px; text-align: center; background: color-mix(in srgb, var(--ink) 3%, var(--panel)); }
.photo-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; max-width: 340px; }
.cat-item .price { color: var(--gold); font-weight: 800; font-size: 17px; }

.settings-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 640px; }
.settings-card .field-row { grid-template-columns: 1fr 1fr; }
.gold-note { background: color-mix(in srgb, var(--gold) 13%, var(--panel)); border: 1px solid color-mix(in srgb, var(--gold) 45%, var(--panel)); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 13.5px; }

/* Theme picker (Settings) */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 4px; }
.theme-swatch { text-align: left; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; font: inherit; }
.theme-swatch.sel { border-color: var(--orange); }
.theme-swatch .t-name { font-weight: 700; font-size: 14px; }
.theme-swatch .t-mode { font-size: 11.5px; opacity: .65; text-transform: uppercase; letter-spacing: .04em; }
.theme-dots { display: flex; gap: 5px; margin-top: 8px; }
.theme-dots span { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.18); }
.color-rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 10px; }
.color-row { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.color-row input[type="color"] { width: 42px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; }
.color-row .hex { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.mode-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode-toggle button { background: var(--panel); color: var(--ink); border: none; padding: 7px 14px; font: inherit; font-size: 13.5px; cursor: pointer; }
.mode-toggle button.sel { background: var(--orange); color: #fff; font-weight: 600; }

/* Work sheets */
.ws-typeline { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 2px; }
.ws-type { font-size: 14px; cursor: pointer; }
.ws-costline { display: block; margin-top: 12px; font-size: 14px; cursor: pointer; }
.ws-preview { margin-top: 16px; max-height: 500px; overflow: auto; background: color-mix(in srgb, var(--ink) 7%, var(--bg)); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.ws-page { page: ws; background: #fff; color: #000; font-family: Arial, Helvetica, sans-serif; max-width: 760px; margin: 0 auto; padding: 26px 28px; border: 1px solid #bbb; }
.ws-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; border-bottom: 2.5px solid #000; padding-bottom: 10px; }
.ws-company { font-size: 22px; font-weight: 800; }
.ws-tagline { font-size: 12px; color: #444; }
.ws-title { text-align: right; flex: none; }
.ws-doctitle { font-size: 20px; font-weight: 800; letter-spacing: .06em; }
.ws-jobno { display: inline-block; margin-top: 4px; border: 2px solid #000; padding: 2px 10px; font-size: 17px; font-weight: 800; }
.ws-model { display: flex; gap: 14px; align-items: center; margin: 14px 0 6px; }
.ws-gem { font-size: 38px; width: 74px; height: 62px; display: flex; align-items: center; justify-content: center; border: 1px solid #999; border-radius: 8px; flex: none; background: #fff; }
.ws-mname { font-size: 18px; font-weight: 800; }
.ws-mmeta { font-size: 12.5px; color: #444; }
.ws-mdesc { font-size: 13px; margin-top: 3px; }
.ws-qty { margin-left: auto; text-align: center; font-size: 12px; color: #444; flex: none; }
.ws-qty b { display: block; font-size: 26px; color: #000; }
.ws-infos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 10px 0 4px; }
.ws-info span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: #555; }
.ws-info b { display: block; font-size: 14px; font-weight: 600; border-bottom: 1px solid #999; min-height: 20px; padding-bottom: 2px; }
.ws-h { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid #000; padding-bottom: 3px; }
table.ws-table { width: 100%; border-collapse: collapse; }
table.ws-table th, table.ws-table td { border: 1px solid #aaa; padding: 6px 9px; font-size: 13.5px; text-align: left; }
table.ws-table th { background: #f0f0f0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.ws-costs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; margin-top: 14px; border: 1.5px solid #000; padding: 10px 12px; }
.ws-costs span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: #555; }
.ws-costs b { font-size: 15px; }
.ws-bench { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-top: 22px; font-size: 13px; }
.ws-bench .ws-line { display: block; border-bottom: 1.5px solid #000; height: 22px; margin-top: 2px; }
.ws-notes { font-size: 13.5px; white-space: pre-wrap; margin-bottom: 4px; }
.ws-rules div { border-bottom: 1px solid #bbb; height: 27px; }
.ws-foot { margin-top: 18px; font-size: 10.5px; color: #777; text-align: center; }

@page ws { size: letter; margin: 12mm; }

#print-root { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-root { display: block; position: absolute; inset: 0; visibility: visible; }
  #print-root * { visibility: visible; }
  .topbar, .foot { display: none; }
  .ws-page { border: none; padding: 0; max-width: none; }
  /* Printed documents are paper: pin the price-list table to light
     colours even when the app is wearing a dark theme. */
  #print-root table.list { background: #fff; color: #17181c; }
  #print-root table.list th { background: #fafafa; color: #6d6f78; }
}
