:root {
  --paper: #f3efe6;
  --surface: #fffdf7;
  --surface-2: #f8f4ea;
  --ink: #1a1712;
  --ink-soft: #4b463c;
  --muted: #837c6d;
  --line: #ddd6c6;
  --line-strong: #c7bfac;
  --accent: #0e7a5b;
  --accent-ink: #0a5a43;
  --accent-soft: #e0efe6;
  --danger: #b23a3a;
  --shadow: 0 1px 2px rgba(26, 23, 18, 0.05), 0 10px 30px -18px rgba(26, 23, 18, 0.35);
  --radius: 14px;
  --radius-sm: 9px;
  --sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over class-level display rules
   (e.g. .modal-overlay/.quote-bar-right use display:flex). */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(26, 23, 18, 0.045) 1px, transparent 0);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background:
    conic-gradient(from 210deg at 50% 50%, var(--accent), var(--accent-ink) 50%, var(--accent));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25), var(--shadow);
  position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 9px;
  border-radius: 3px; border: 2px solid rgba(255,255,255,0.85);
}
.brand-eyebrow {
  margin: 0; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.brand-title {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: 24px; letter-spacing: -0.01em; line-height: 1;
}

/* ---------- Buttons / inputs ---------- */
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 10px 16px; cursor: pointer; transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--accent-ink); }
.btn-outline { background: var(--surface); color: var(--accent-ink); border-color: var(--line-strong); }
.btn-outline:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.input {
  font-family: var(--sans); font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 9px 12px; width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.num-input { font-family: var(--mono); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.01em; }
.field-label em { font-style: normal; color: var(--muted); }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-shell { width: 100%; max-width: 420px; padding: 24px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 34px 30px; box-shadow: var(--shadow);
}
.login-lede { color: var(--muted); font-size: 14px; margin: 20px 0 22px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form .btn { width: 100%; padding: 12px; }
.login-error { color: var(--danger); font-size: 13px; font-weight: 600; margin: 14px 0 0; }
.login-footnote { text-align: center; color: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 18px; }

/* ---------- App shell ---------- */
.app { max-width: 1180px; margin: 0 auto; padding: 26px 26px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.currency-switch {
  display: inline-flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px;
}
.ccy {
  font-family: var(--mono); font-size: 12.5px; font-weight: 500; letter-spacing: 0.02em;
  border: none; background: transparent; color: var(--ink-soft);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; transition: all .15s ease;
}
.ccy.active { background: var(--accent); color: #fff; box-shadow: var(--shadow); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 0.92fr 1.25fr; gap: 22px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.panel-title { margin: 0; font-family: var(--serif); font-size: 17px; font-weight: 600; }
.pill {
  font-family: var(--mono); font-size: 11.5px; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 999px; padding: 4px 10px; font-weight: 500;
}

/* ---------- Catalogue ---------- */
.search-wrap { padding: 14px 18px 6px; }
.catalogue-list { max-height: 560px; overflow-y: auto; padding: 6px 10px 12px; }
.cat-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 10px; cursor: pointer; transition: background .12s ease, border-color .12s ease;
}
.cat-item:hover { background: var(--surface-2); border-color: var(--line); }
.cat-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.cat-line1, .cat-line2 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cat-name { font-size: 14px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-strength { font-family: var(--mono); font-size: 11px; color: var(--accent-ink); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; flex: none; }
.cat-strength:empty { display: none; }
.cat-no { font-family: var(--mono); font-size: 11px; color: var(--accent-ink); background: var(--accent-soft); padding: 2px 7px; border-radius: 6px; flex: none; }
.cat-cat { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-cat:empty { display: none; }
.cat-cost { font-family: var(--mono); font-size: 13px; color: var(--muted); flex: none; }
.cat-add { font-family: var(--mono); font-size: 18px; color: var(--accent); flex: none; line-height: 1; }
.catalogue-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 16px; }

/* ---------- Cart ---------- */
.cart-table-wrap { padding: 4px 6px 0; }
.cart-table { width: 100%; border-collapse: collapse; }
.cart-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  font-weight: 700; text-align: left; padding: 12px 10px 10px;
}
.cart-table th.num, .cart-table td.num { text-align: right; }
.cart-table td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.cart-item-name { font-weight: 600; font-size: 14px; }
.cart-item-cat { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; }
.cell-input {
  font-family: var(--mono); font-size: 13px; text-align: right; width: 72px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px;
}
.cell-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.cell-cost { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.cell-line { font-family: var(--mono); font-size: 14px; font-weight: 700; }
.row-remove { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 4px; border-radius: 6px; }
.row-remove:hover { color: var(--danger); background: rgba(178,58,58,0.08); }
.empty-cart { color: var(--muted); font-size: 13px; text-align: center; padding: 36px 16px; margin: 0; }

/* ---------- Totals ---------- */
.totals { border-top: 1px solid var(--line); padding: 18px; display: grid; gap: 16px; }
.totals-controls { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.totals-controls .field.inline { max-width: 200px; }
.cn-toggle { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 600; color: var(--ink); cursor: pointer; }
.cn-toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.cn-toggle em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; }
.cn-note { font-family: var(--mono); font-size: 12px; color: var(--accent-ink); background: var(--accent-soft); padding: 7px 11px; border-radius: 8px; margin: 0; }

/* internal profit/margin readout on the order box */
.margin-box { padding: 14px 16px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); display: grid; gap: 7px; }
.margin-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.margin-head em { font-style: normal; font-weight: 500; text-transform: none; letter-spacing: 0; }
.margin-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; color: var(--ink-soft); }
.margin-row em { font-style: normal; color: var(--muted); font-size: 11px; }
.margin-row .mono { font-family: var(--mono); }
.margin-row.profit { border-top: 1px dashed var(--line-strong); padding-top: 8px; margin-top: 2px; font-weight: 700; color: var(--accent-ink); font-size: 14px; }
.margin-row.profit .mono { font-size: 17px; }
.margin-row.profit .mono.neg { color: var(--danger); }
.totals-lines { display: grid; gap: 8px; padding: 4px 2px; }
.total-row { display: flex; align-items: baseline; justify-content: space-between; font-size: 14px; color: var(--ink-soft); }
.total-row .mono { font-family: var(--mono); }
.total-row.grand { border-top: 1px dashed var(--line-strong); padding-top: 12px; margin-top: 4px; font-size: 16px; font-weight: 700; color: var(--ink); }
.total-row.grand em { font-style: normal; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 6px; }
.total-row.grand .mono { font-size: 22px; }
.totals-actions { display: flex; gap: 10px; }
.totals-actions .btn { flex: 1; }

/* ---------- Admin ---------- */
.admin { margin-top: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.admin-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: transparent; border: none; cursor: pointer; padding: 16px 20px;
  font-family: var(--sans); font-weight: 600; font-size: 14px; color: var(--ink);
}
.admin-toggle .chev { transition: transform .2s ease; color: var(--muted); }
.admin-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.admin-body { padding: 4px 20px 22px; border-top: 1px solid var(--line); }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; padding-top: 18px; }
@media (max-width: 760px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-card { display: flex; flex-direction: column; gap: 12px; }
.admin-h { margin: 0; font-size: 14px; font-weight: 700; }
.admin-note { margin: 0; font-size: 12.5px; color: var(--muted); }
.admin-note code, .admin-note code { font-family: var(--mono); font-size: 11.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.file-input { font-family: var(--sans); font-size: 13px; }
.file-input::file-selector-button { font-family: var(--sans); font-weight: 600; font-size: 13px; margin-right: 12px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink); padding: 7px 12px; border-radius: 7px; cursor: pointer; }
#uploadForm, #settingsForm { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-grid .btn { grid-column: 1 / -1; justify-self: start; }
.upload-status { font-size: 12.5px; margin: 0; min-height: 16px; }
.upload-status.ok { color: var(--accent-ink); }
.upload-status.err { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); font-size: 13.5px; font-weight: 600;
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow); z-index: 50;
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Nav ---------- */
.nav { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.nav-btn {
  font-family: var(--sans); font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
  border: none; background: transparent; padding: 8px 16px; border-radius: 999px; cursor: pointer; transition: all .15s ease;
}
.nav-btn:hover { color: var(--ink); }
.nav-btn.active { background: var(--accent); color: #fff; box-shadow: var(--shadow); }

/* ---------- Views ---------- */
.view { animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.view-title { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 600; }

/* ---------- Quote bar (customer + editing) ---------- */
.quote-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.quote-bar-left, .quote-bar-right { display: flex; align-items: flex-end; gap: 12px; }
.customer-pick { display: flex; gap: 8px; align-items: stretch; }
.customer-pick .input { min-width: 240px; }
.field.inline { display: flex; flex-direction: column; gap: 6px; }
.pill-edit { background: #fff3d6; color: #8a6212; align-self: center; }
.status-select { font-family: var(--sans); font-weight: 600; padding: 8px 10px; }
.input.flash { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(178,58,58,.2); }

/* ---------- Data tables ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .mono { font-family: var(--mono); font-size: 13px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }

/* ---------- Status filter + badges ---------- */
.status-filter { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.filter-btn { font-family: var(--sans); font-size: 12.5px; font-weight: 600; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 13px; cursor: pointer; transition: all .15s ease; }
.filter-btn:hover { border-color: var(--accent); }
.filter-btn.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.badge { font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; display: inline-block; }
.badge-quote { background: #ece7da; color: #6b6350; }
.badge-order { background: #dceafe; color: #1d5bbf; }
.badge-shipped { background: #e8defb; color: #6a36c4; }
.badge-landed { background: var(--accent-soft); color: var(--accent-ink); }
.badge-cancelled { background: #fbe0e0; color: #b23a3a; }
select.status-select.status-quote { color: #6b6350; }
select.status-select.status-order { color: #1d5bbf; }
select.status-select.status-shipped { color: #6a36c4; }
select.status-select.status-landed { color: var(--accent-ink); }
select.status-select.status-cancelled { color: #b23a3a; }

/* ---------- Customers ---------- */
.customers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.customer-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.cc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cc-name { margin: 0; font-size: 16px; font-weight: 700; }
.cc-meta { font-size: 13px; color: var(--muted); line-height: 1.6; word-break: break-word; flex: 1; }
.cc-actions { display: flex; gap: 6px; }

/* ---------- Buttons: xs + danger ---------- */
.btn-xs { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: rgba(178,58,58,0.08); }

/* ---------- Logo admin ---------- */
.logo-preview { min-height: 56px; display: flex; align-items: center; padding: 8px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }
.logo-preview img { max-height: 60px; max-width: 100%; }
.logo-none { color: var(--muted); font-size: 12.5px; }
.logo-actions { display: flex; gap: 8px; }
#logoForm { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* ---------- Modals ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(26,23,18,0.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 60; animation: fade-in .15s ease; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px -20px rgba(0,0,0,.5); padding: 26px; width: 100%; max-width: 440px; }
.modal-wide { max-width: 640px; }
.modal-title { font-family: var(--serif); font-size: 20px; margin: 0 0 18px; }
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-form textarea.input { resize: vertical; font-family: var(--sans); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.history-meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.history-meta:empty { display: none; }

/* ---------- Reports ---------- */
.report-filters { display: flex; gap: 10px; }
.report-filters .input { width: auto; }
.report-note { color: var(--muted); font-size: 12.5px; margin: -4px 0 18px; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.report-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.rc-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.rc-value { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--ink); }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.report-panel .panel-head { padding: 14px 16px; }
.report-panel .panel-title { font-size: 15px; }
.report-panel .data-table th { padding: 10px 16px; }
.report-panel .data-table td { padding: 9px 16px; }

@media (max-width: 860px) { .report-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; justify-content: center; }
}
