:root {
  --red: #d81e1e; --red-dark: #b51616; --black: #111111; --ink: #1c1c1c; --muted: #6b7280;
  --bg: #f4f4f5; --card: #ffffff; --line: #e5e7eb; --line-2: #d1d5db; --soft: #f7f7f8;
  --ok: #15803d; --warn: #d97706; --magenta: #ec008c;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 10px rgba(0,0,0,.04);
  --font: "Inter", "Helvetica Neue", Arial, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 800; letter-spacing: -.01em; margin: 0 0 4px; }
h2 { font-size: 15px; font-weight: 700; margin: 0 0 14px; text-transform: uppercase; letter-spacing: .04em; padding-left: 10px; border-left: 3px solid var(--red); }
h2 small, h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
h3 { font-size: 13px; font-weight: 700; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* top bar */
.topbar { background: var(--black); color: #fff; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 0 20px; height: 54px; display: flex; align-items: center; gap: 28px; }
.brand { font-weight: 800; font-size: 22px; letter-spacing: -.02em; color: #fff; display: flex; align-items: baseline; gap: 0; }
.brand:hover { text-decoration: none; }
.brand-do { color: var(--red); }
.brand-sub { font-size: 11px; font-weight: 600; letter-spacing: .12em; color: #9ca3af; margin-left: 10px; text-transform: uppercase; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #d1d5db; padding: 8px 12px; border-radius: 6px; font-weight: 600; }
.nav a:hover { color: #fff; background: #1f2937; text-decoration: none; }
.nav a.active { color: #fff; background: var(--red); }
.userbox { display: flex; align-items: center; gap: 10px; color: #d1d5db; }
.userbox .btn { color: #d1d5db; border-color: #374151; }
.userbox .btn:hover { background: #1f2937; color: #fff; }
.status-inline { padding-top: 6px; }
.role-pill { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; background: #374151; color: #fff; }
.role-pill.role-admin { background: var(--red); }
.role-pill.role-production { background: #2563eb; }

.main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.main-wide { max-width: 1400px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash-ok { background: #dcfce7; color: #166534; }
.flash-err { background: #fee2e2; color: #991b1b; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card.narrow { max-width: 520px; margin: 40px auto; }
.table-card { padding: 0; overflow: auto; }
.table-card h2 { margin: 18px 20px 6px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.back { font-size: 12px; font-weight: 600; color: var(--muted); display: inline-block; margin-bottom: 4px; }

/* toolbar / tabs */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 6px; color: var(--ink); font-weight: 600; font-size: 13px; }
.tabs a small { color: var(--muted); font-weight: 600; margin-left: 2px; }
.tabs a:hover { background: #e9e9ec; text-decoration: none; }
.tabs a.active { background: var(--black); color: #fff; }
.tabs a.active small { color: #d1d5db; }
.search input { width: 280px; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: var(--soft); }
.table .num { text-align: right; white-space: nowrap; }
.orders-table td:nth-child(2), .orders-table td:nth-child(7), .orders-table td:nth-child(8) { white-space: nowrap; }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table tr.row-link { cursor: pointer; }
.table tr.row-link:hover { background: #fafafa; }
.table td.empty { text-align: center; color: var(--muted); padding: 40px; }
.order-no { font-weight: 700; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; color: #fff; background: var(--pill, #999); white-space: nowrap; }
.deadline-over { color: var(--red); font-weight: 700; }
.deadline-soon { color: var(--warn); font-weight: 700; }

/* forms */
.form label { display: block; font-size: 12px; font-weight: 600; color: #374151; }
.form input, .form select, .form textarea, .search input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 7px; font: inherit; font-size: 14px; color: var(--ink); background: #fff; }
.form input:focus, .form select:focus, .form textarea:focus, .search input:focus { outline: 2px solid rgba(216,30,30,.25); border-color: var(--red); }
.form textarea { resize: vertical; }
.form input.num { text-align: right; }
.card.narrow .form label { margin-bottom: 12px; }
.fgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 14px; }
.fgrid .span2 { grid-column: span 2; }
.fgrid .span4 { grid-column: span 4; }
.label-text { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.form label.check, label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; }
.form label.check input { width: auto; margin: 0; }
.check-white { font-weight: 700 !important; }
.new-customer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; background: var(--soft); border-radius: 8px; }
.new-customer input { margin: 0; }
.savebar { display: flex; align-items: center; gap: 14px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.savebar .btn-danger { margin-left: auto; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.inline-form input { margin: 0; padding: 6px 8px; width: auto; }
.status-form select { margin: 0; padding: 8px 12px; font-weight: 600; }
.status-form label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line-2); background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* layout grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.order-grid { grid-template-columns: minmax(0, 7fr) minmax(0, 6fr); }
.customers-grid { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) { .grid-2, .order-grid, .customers-grid { grid-template-columns: 1fr; } .fgrid { grid-template-columns: repeat(2, 1fr); } .fgrid .span4 { grid-column: span 2; } }
@media (max-width: 600px) { .fgrid { grid-template-columns: 1fr; } .fgrid .span2, .fgrid .span4 { grid-column: span 1; } .topbar-inner { gap: 12px; } .brand-sub { display: none; } }

/* spec list (production view) */
.spec { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 0; }
.spec dt { color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 2px; }
.spec dd { margin: 0; }
.note-card { background: #fffbeb; border: 1px solid #fde68a; }
.icon-inline { display: inline-block; vertical-align: middle; width: 42px; height: 42px; margin-right: 6px; }
.icon-inline svg { width: 100%; height: 100%; }
.icon-inline img { height: 56px; width: auto; }
.icon-inline:has(img) { width: auto; height: 56px; }

/* file lists */
.file-list { list-style: none; margin: 10px 0 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.file-list li:last-child { border-bottom: 0; }
.file-ico { font-size: 10px; font-weight: 800; background: var(--black); color: #fff; padding: 4px 6px; border-radius: 4px; letter-spacing: .05em; }
.file-ico.proof { background: var(--red); }
.file-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .btn { margin-left: auto; }
.file-list .muted { white-space: nowrap; font-size: 12px; }

/* dropzone */
.dropzone { border: 2px dashed var(--line-2); border-radius: 10px; padding: 18px; text-align: center; background: var(--soft); transition: .15s; }
.dropzone.over { border-color: var(--red); background: #fff5f5; }
.dropzone p { margin: 4px 0; }
.progress { height: 6px; background: #e5e7eb; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--red); transition: width .2s; }

/* layers */
.layer-list { display: flex; flex-direction: column; gap: 10px; }
.layer { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.layer-canvas { width: 120px; height: 90px; display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 6px; overflow: hidden; }
.layer-canvas canvas, .layer-canvas img { max-width: 100%; max-height: 100%; }
.layer-fields { display: grid; grid-template-columns: 1fr; gap: 8px; }
.layer-fields input { width: 100%; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 6px; font: inherit; font-size: 13px; }
.layer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.layer-head .warn { color: var(--warn); font-weight: 600; }
.layer-head .ok { color: var(--ok); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px; border: 1px solid var(--line-2); border-radius: 99px; font-size: 12px; background: #fff; }
.chip i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); display: inline-block; }
.chip input[type=color] { width: 18px; height: 18px; border: 0; padding: 0; background: none; cursor: pointer; }
.chip input[type=text] { border: 0; padding: 0; width: 90px; font-size: 12px; background: transparent; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; font-size: 12px; }
.chip.add { cursor: pointer; color: var(--muted); border-style: dashed; }
.layer-note-input { border-color: var(--magenta) !important; color: var(--magenta); }
.layer-thumbs { display: grid; gap: 12px; }
.layer-thumb { display: grid; grid-template-columns: 140px 1fr; gap: 12px; align-items: center; }
.layer-thumb img { max-width: 140px; max-height: 100px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.layer-note { color: var(--magenta); font-weight: 600; font-size: 12px; text-transform: uppercase; }

/* icon pickers (winding / eyemark) */
.icon-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-picker label { cursor: pointer; border: 1px solid var(--line-2); border-radius: 8px; padding: 4px; background: #fff; position: relative; }
.icon-picker label:hover { border-color: #9ca3af; }
.icon-picker label.selected { border-color: var(--red); box-shadow: 0 0 0 2px rgba(216,30,30,.2); background: #fff5f5; }
.icon-picker input { position: absolute; opacity: 0; pointer-events: none; }
.icon-picker svg { width: 56px; height: 49px; display: block; }
.icon-picker label.has-img { position: relative; opacity: .45; }
.icon-picker label.has-img.selected { opacity: 1; }
.icon-picker label.has-img img { display: block; height: 64px; width: auto; max-width: 140px; object-fit: contain; }
.icon-picker .pick-no { position: absolute; top: 2px; left: 4px; font-size: 11px; font-weight: 800; color: var(--muted); }
.icon-picker label.has-img.selected .pick-no { color: var(--red); }
.icon-picker label.none { display: flex; align-items: center; justify-content: center; width: 58px; font-size: 12px; font-weight: 600; color: var(--muted); }

/* softproof */
.softproof-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.big-version { font-size: 22px; font-weight: 800; }
.proof-preview { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #525659; }
.proof-preview iframe { width: 100%; height: 480px; border: 0; display: block; }
#generateStatus { margin-top: 8px; min-height: 16px; }
#generateStatus.err { color: var(--red); font-weight: 600; }

/* price */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--soft); border-radius: 8px; padding: 10px 12px; }
.kpi-val { font-size: 22px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }
.kpi-price { background: #fff5f5; }
.kpi-price .kpi-val { color: var(--red); }
.kpi .neg { color: var(--red); }
.price-final-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; margin-top: 12px; }
.price-final-row input { font-size: 18px; font-weight: 700; }
#priceError { margin-top: 10px; }
.breakdown { margin-top: 12px; }
.breakdown summary { cursor: pointer; font-weight: 600; font-size: 12px; color: var(--muted); }
.breakdown tr.subtotal td { font-weight: 700; border-top: 2px solid var(--line-2); }
.breakdown tr.total td { font-weight: 800; font-size: 15px; }
.breakdown table { margin-top: 8px; }
.breakdown td.src { color: var(--muted); font-size: 11px; white-space: nowrap; }
.src-customer { color: #2563eb !important; font-weight: 600; }
.src-order { color: var(--red) !important; font-weight: 600; }
.ladder-custom { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.ladder-custom input { width: 90px; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 6px; font: inherit; }
.ladder-custom .label-text { margin: 0; }
#ladderTable tr.is-order td { background: #fff5f5; font-weight: 700; }
#ladderTable tr.custom td:first-child::after { content: ' ✎'; color: var(--muted); }
.override-grid { margin-top: 8px; grid-template-columns: repeat(2, 1fr); }
.override-grid input, .override-grid select { padding: 6px 8px; }
.override-grid input:not(:placeholder-shown) { border-color: var(--red); background: #fff5f5; }
.totals-row td { font-weight: 800; background: var(--soft); border-top: 2px solid var(--line-2); }
.profit-neg { color: var(--red); }
@media (max-width: 600px) { .kpis, .price-final-row { grid-template-columns: 1fr; } }

.activity { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* settings */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 18px; align-items: start; }
.settings-nav { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 8px 12px; border-radius: 6px; color: var(--ink); font-weight: 600; }
.settings-nav a:hover { background: #e9e9ec; text-decoration: none; }
.rows-table input { width: 100%; margin: 0; padding: 6px 8px; }
.table input.ov, .rows-table input.num { max-width: 120px; margin-left: auto; }
.table td input { margin: 0; padding: 5px 8px; }
input.ov:not(:placeholder-shown) { border-color: #2563eb !important; background: #eff6ff; }
.preview-no { font-size: 20px; font-weight: 800; padding-top: 4px; }
.actions { white-space: nowrap; }
@media (max-width: 800px) { .settings-layout { grid-template-columns: 1fr; } .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; } }
.login-card { margin-top: 80px; }

/* invoices */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin-bottom: 0; }
.inv-link { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; color: #fff; background: var(--pill, #999); }
.inv-link:hover { text-decoration: none; opacity: .85; }
.invoice-grid { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
fieldset#invForm { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset#invForm:disabled input, fieldset#invForm:disabled select { background: var(--soft); color: #374151; }
fieldset#invForm:disabled .line-adders, fieldset#invForm:disabled [data-rm] { display: none; }
.fgrid .span3 { grid-column: span 3; }
.lines-table td { vertical-align: top; }
.lines-table input.ln { width: 100%; margin: 0; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 6px; font: inherit; font-size: 13px; }
.lines-table input.narrow { width: 70px; }
.lines-table input.num { width: 96px; text-align: right; }
.lines-table tfoot td { font-weight: 600; }
.lines-table tfoot tr.total td { font-weight: 800; font-size: 15px; border-top: 2px solid var(--line-2); }
.lines-table tr.order-line td:first-child { border-left: 3px solid var(--red); }
.line-adders { margin-top: 10px; }
.line-adders select { max-width: 420px; }
.invoice-preview iframe { height: 720px; background: #fff; }
.uninvoiced { flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 12px; padding: 10px; background: var(--soft); border-radius: 8px; }

/* dashboard */
.dash { margin-bottom: 22px; }
.dash-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border-top: 4px solid var(--muted); }
.tile-green { border-top-color: #15803d; } .tile-amber { border-top-color: #d97706; } .tile-blue { border-top-color: #2563eb; }
.tile-val { font-size: 28px; font-weight: 800; letter-spacing: -.01em; margin: 2px 0 4px; white-space: nowrap; }
.dash-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dash-card { margin-bottom: 0; }
.dash-card .table td { padding: 7px 8px; }
@media (max-width: 1000px) { .dash-tiles, .dash-lists { grid-template-columns: 1fr; } }
.section-title { margin: 6px 0 12px; }
