:root {
  --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec; --bg: #f4f5f8; --panel: #fff;
  --brand: #d4117b; --brand-dark: #a80d61; --navy: #172554; --yellow: #ffd60a;
  --design: #6d28d9; --design-soft: #f3efff;
  --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "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 { font-size: 24px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }

/* ---------- shell ---------- */
.topbar { position: fixed; inset: 0 0 auto 0; height: 50px; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 20px; z-index: 20; border-bottom: 3px solid var(--brand); }
.topbar .logo { font-weight: 800; font-style: italic; font-size: 20px; color: var(--yellow); letter-spacing: .3px; width: 196px; }
.topbar .logo small { font-style: normal; font-weight: 600; font-size: 10px; color: #fff; letter-spacing: 1.5px; margin-left: 6px; }
.topbar .crumb { font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar a.tb { color: #fff; font-weight: 600; padding: 6px 10px; border-radius: 6px; }
.topbar a.tb:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.sidebar { position: fixed; top: 50px; bottom: 0; left: 0; width: 216px; background: #fff; border-right: 1px solid var(--line); padding: 14px 0; overflow: auto; z-index: 10; }
.sidebar .co { padding: 6px 18px 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin: 0 0 8px; }
.sidebar .sec { font-size: 11px; letter-spacing: 1.6px; color: #9aa1b1; padding: 14px 18px 4px; }
.sidebar a { display: block; padding: 8px 18px 8px 26px; color: var(--ink); border-left: 3px solid transparent; }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.on { border-left-color: var(--brand); color: var(--brand); font-weight: 600; background: #fdf2f8; }
.main { margin: 50px 0 0 216px; padding: 26px 32px 80px; min-height: calc(100vh - 50px); }
.navbadge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: 4px; }
.banner { background: #fff7d6; border: 1px solid #f1d56b; color: #6b5200; padding: 8px 14px; border-radius: 6px; margin-bottom: 16px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 6px; display: inline-block; }
button:hover, .btn:hover { background: var(--bg); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
button.x { border: 0; background: none; padding: 2px 6px; color: var(--muted); font-size: 16px; line-height: 1; }
button.x:hover { color: var(--bad); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid #cfd4de; border-radius: 5px; padding: 6px 8px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f5a8d2; border-color: var(--brand); }
input:disabled { background: #eef0f4; color: #b3b8c4; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 3px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: 18px; }
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead .spacer { flex: 1; }

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list tbody tr:hover { background: #fdf2f8; cursor: pointer; }
table.list td.right, table.list th.right { text-align: right; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- line items ---------- */
.items-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
table.items { min-width: 1420px; }
table.items th { background: #f1f3f7; font-weight: 600; font-size: 13px; padding: 12px 6px; text-align: left; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.items td { padding: 8px 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.items th:last-child, table.items td:last-child { border-right: 0; }
table.items th.sz, table.items td.sz { text-align: center; width: 44px; padding-left: 3px; padding-right: 3px; }
table.items td.sz input { text-align: center; padding: 6px 2px; min-width: 40px; -moz-appearance: textfield; appearance: textfield; }
table.items td.sz input::-webkit-outer-spin-button, table.items td.sz input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.main > .totals { background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table.items td.num { text-align: right; white-space: nowrap; }
table.items tr.sub td { background: #f8f9fb; }
table.items tr.sub.view td { padding: 6px 8px; }
table.items input.price { width: 78px; text-align: right; }
table.items input.price.manual { border-color: var(--warn); background: #fffbeb; }
table.items textarea { min-height: 44px; }
.mockups { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mockup { height: 130px; max-width: 260px; object-fit: contain; border: 1px solid var(--line); border-radius: 4px; background: #fff; display: block; }
.mockup.small { height: 64px; max-width: 120px; }
.mockup-edit { position: relative; display: inline-flex; align-items: flex-start; gap: 2px; }
.thumb { width: 72px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 4px; background: #fff; vertical-align: middle; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid #0003; vertical-align: -1px; margin-right: 5px; }
.subrow { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.imprints { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.imprint { display: flex; gap: 4px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px 3px 6px; }
.imprint select { width: 124px; padding: 3px 4px; }
.imprint input { width: 48px; padding: 3px 4px; text-align: center; }
.chip { display: inline-block; background: #eef0f6; border-radius: 999px; padding: 2px 10px; font-size: 12px; margin-right: 6px; }
.calc { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }
.calc b { color: var(--ink); }
.warn { color: var(--warn); font-size: 12px; }
.matches { display: flex; gap: 6px; flex-wrap: wrap; }
.matches button { font-size: 12px; padding: 4px 10px; }
.xsizes { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.xsizes input { width: 46px; text-align: center; padding: 3px; }

/* ---------- invoice sheet ---------- */
.sheet { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 30px 32px; }
.sheet .title { display: flex; align-items: flex-start; }
.sheet .title .nick { font-size: 19px; color: #444b5c; margin-top: 4px; }
.stamp { margin-left: auto; text-align: right; }
.stamp span { display: inline-block; border: 2px solid var(--bad); color: var(--bad); font-weight: 800; font-size: 17px; padding: 2px 9px; border-radius: 4px; letter-spacing: .5px; }
.stamp span.due { border-color: var(--warn); color: var(--warn); }
.stamp div { color: #9aa1b1; margin-top: 8px; }
.sheet .head { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 16px; border-top: 1px solid var(--line); padding-top: 0; margin-top: 12px; }
.sheet .head > div { padding-top: 26px; }
.sheet .logo img { max-width: 180px; max-height: 110px; }
.sheet .logo .txt { font-weight: 800; font-style: italic; font-size: 26px; color: var(--brand); line-height: 1.05; }
.sheet .logo .txt small { display: block; font-style: normal; font-size: 11px; color: #1d4ed8; letter-spacing: 2px; margin-top: 2px; }
.datebox { background: #f4f5f8; padding: 20px 26px !important; border-radius: 4px; }
.datebox table td { padding: 7px 0; }
.datebox td:first-child { text-align: right; font-weight: 700; padding-right: 30px; width: 55%; }
.sheet .parties { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 16px; border-top: 1px solid var(--line); margin: 26px 0; padding-top: 30px; }
.totals { margin: 18px 0 0 auto; width: 340px; background: #f4f5f8; border-radius: 4px; padding: 12px 22px; }
.totals td { padding: 6px 0; }
.totals td:first-child { text-align: right; font-weight: 700; padding-right: 26px; }
.totals tr.big td { font-size: 16px; border-top: 1px solid #d5d9e2; padding-top: 10px; }
.totals input { width: 90px; text-align: right; padding: 3px 6px; }
.payments { margin-top: 26px; }
.footnote { margin-top: 28px; color: var(--muted); text-align: center; }

/* ---------- graphic design documents (purple, deposit terms) ---------- */
.sheet.design { border-top: 6px solid var(--design); }
.sheet.design h1 { color: var(--design); }
.sheet.design .datebox, .sheet.design .totals { background: var(--design-soft); }
.sheet.design table.items th { background: var(--design-soft); }
.doc-tag { display: inline-block; background: var(--design); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 1.5px; padding: 3px 10px; border-radius: 999px; margin-bottom: 8px; }
.stamp span.deposit { border-color: var(--design); color: var(--design); }
.terms-box { border: 2px solid var(--design); border-radius: 8px; margin: 26px 0 0; overflow: hidden; }
.terms-title { background: var(--design); color: #fff; font-weight: 700; padding: 10px 16px; }
.terms-grid { display: grid; grid-template-columns: 1fr 1fr; }
.terms-grid > div { padding: 14px 16px; }
.terms-grid > div + div { border-left: 1px solid #ddd3fb; }
.terms-grid .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.terms-grid .now .lbl { color: var(--design); }
.terms-grid .done .lbl { color: var(--ok); }
.terms-grid .amt { font-size: 26px; font-weight: 800; margin-top: 2px; }
.terms-grid .sub { font-size: 12px; color: var(--muted); }
.sheet .parties.two { grid-template-columns: 1fr 1.4fr; }
@media print { .sheet.design, .terms-title, .doc-tag, .terms-box { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border-left: 1px solid var(--line); border-top: 1px solid var(--line); background: #fff; }
.cal .dow { padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal .day { min-height: 104px; padding: 4px 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 12px; }
.cal .day.off { background: #f8f9fb; color: #b3b8c4; }
.cal .day.today .n { background: var(--brand); color: #fff; border-radius: 50%; display: inline-block; min-width: 20px; text-align: center; }
.cal .ev { display: block; color: #fff; border-radius: 4px; padding: 2px 6px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- modal / login / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding-top: 9vh; z-index: 50; }
.modal { background: #fff; border-radius: 10px; padding: 22px 24px; width: 520px; max-width: 94vw; max-height: 84vh; overflow: auto; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.login { max-width: 340px; margin: 16vh auto; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px #0003; }
.toast.err { background: var(--bad); }
table.matrix { width: auto; font-size: 12px; margin-top: 8px; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: 4px 10px; text-align: right; }
table.matrix th { background: #f1f3f7; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 18px 14px 60px; }
  .grid3, .sheet .head, .sheet .parties { grid-template-columns: 1fr; }
}
@media print {
  @page { size: letter landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .sidebar, .noprint, .toast, .banner { display: none !important; }
  .main { margin: 0; padding: 0; }
  .sheet { border: 0; padding: 0; }
  .items-wrap { overflow: visible; border: 0; }
  table.items { min-width: 0; }
  table.items th, table.items td { padding: 5px 3px; }
  .datebox, .totals, table.items th, tr.sub td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
