:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #1f5eff;
  --brand-ink: #ffffff;
  --side: #121a2b;
  --side-ink: #c5cbd8;
  --side-active: #1f5eff;
  --ok: #067647;   --ok-bg: #ecfdf3;
  --warn: #b54708; --warn-bg: #fffaeb;
  --bad: #b42318;  --bad-bg: #fef3f2;
  --info: #175cd3; --info-bg: #eff8ff;
  --plain: #475467; --plain-bg: #f2f4f7;
  --violet: #6941c6; --violet-bg: #f4f3ff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 15px; }
.logo span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.side nav a.on { background: var(--side-active); color: #fff; }
.side nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7c8599; padding: 16px 10px 6px; }
.side nav svg { width: 17px; height: 17px; flex: none; }
.who { border-top: 1px solid rgba(255,255,255,.08); margin-top: 18px; padding: 14px 10px 0; font-size: 13px; }
.who b { color: #fff; display: block; }
.who form { margin-top: 8px; }
.who button { background: none; border: 0; color: var(--side-ink); padding: 0; cursor: pointer; font: inherit; }
.who button:hover { color: #fff; text-decoration: underline; }
.main { padding: 24px 28px 48px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.main .menu-toggle { display: none; }

/* ---- alerts ---- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #abefc6; }
.alert.bad { background: var(--bad-bg); color: var(--bad); border-color: #fecdca; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: #fedf89; }

/* ---- panels ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card .card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: 16px; }

.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.figure { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; border-left: 4px solid var(--line); }
.figure:hover { text-decoration: none; border-color: #cfd4dc; }
.figure .n { font-size: 26px; font-weight: 700; line-height: 1.2; }
.figure .l { color: var(--muted); font-size: 13px; }
.figure.warn { border-left-color: #f79009; }
.figure.info { border-left-color: #2e90fa; }
.figure.violet { border-left-color: #7a5af8; }
.figure.ok { border-left-color: #12b76a; }
.figure.bad { border-left-color: #f04438; }
.figure.plain { border-left-color: #98a2b3; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #f9fafb; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }
tr.dim td { color: var(--muted); }
td.num, th.num, td.mono { text-align: right; white-space: nowrap; }
td.mono { text-align: left; }
tfoot td { font-weight: 600; background: #f9fafb; }
.row-link { font-weight: 600; white-space: nowrap; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---- badges ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--plain-bg); color: var(--plain); }
.s-pending, .c-open, .p-unpaid, .p-partly_paid, .s-on_hold { background: var(--warn-bg); color: var(--warn); }
.s-awaiting_approval { background: var(--bad-bg); color: var(--bad); }
.s-confirmed, .s-processing, .c-in_progress { background: var(--info-bg); color: var(--info); }
.s-shipped, .s-out_for_delivery { background: var(--violet-bg); color: var(--violet); }
.s-delivered, .p-paid, .c-resolved { background: var(--ok-bg); color: var(--ok); }
.s-cancelled, .s-rejected, .p-failed { background: var(--bad-bg); color: var(--bad); }
.bad-text { color: var(--bad); font-weight: 600; }
.p-not_applicable, .c-closed { background: var(--plain-bg); color: var(--plain); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .count { background: var(--plain-bg); border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; color: var(--plain); }

/* ---- forms ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; }
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=datetime-local],
input[type=search], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d0d5dd; border-radius: 8px; font: inherit; color: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,94,255,.25); border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=checkbox] { min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 8px; }
.check input { width: 16px; height: 16px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 14px; }
.checklist { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.price-input { width: 120px !important; text-align: right; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid #d0d5dd; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #1a4fd8; }
.btn.danger { color: var(--bad); border-color: #fda29b; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; font-weight: 500; }
form.inline { display: inline; }

/* ---- details ---- */
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.totals { width: auto; margin-left: auto; min-width: 280px; }
.totals td { border: 0; padding: 4px 14px; }
.totals tr.grand td { font-size: 16px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--muted); font-size: 12px; }

.thread .msg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; background: #fff; }
.thread .msg.staff { background: var(--info-bg); border-color: #b2ddff; }
.thread .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); background: var(--plain-bg); display: block; }
.thumb.blank { display: grid; place-items: center; color: var(--muted); font-weight: 700; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .logo { color: var(--ink); padding: 0 0 18px; }

/* ---- print ---- */
.printable { max-width: 820px; }
@media print {
  .side, .no-print, .head .actions { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}

/* ---- narrow screens ---- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: none; }
  .side.open { display: block; }
  .main .menu-toggle { display: inline-flex; margin-bottom: 12px; }
  .grid.two, .grid.halves { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
