:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8;
  --text: #1c2330; --muted: #6a7382; --accent: #2457d6; --accent-ink: #fff;
  --green: #1f8a4c; --green-bg: #e3f4ea; --red: #c23434; --red-bg: #fbe7e7;
  --amber: #a86a00; --amber-bg: #fdf1d8; --grey-bg: #eceef1;
  --in-bg: #ffffff; --out-bg: #eef3ff; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1a1e26; --surface-2: #222733; --border: #2e3442;
    --text: #e4e7ec; --muted: #8e97a6; --accent: #6b93ff; --accent-ink: #0d1118;
    --green: #5cc98a; --green-bg: #183326; --red: #f07a7a; --red-bg: #3a1f22;
    --amber: #f0b54d; --amber-bg: #3a2f17; --grey-bg: #262b36;
    --in-bg: #1a1e26; --out-bg: #1d2740;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 4px 0 6px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, pre { font-family: ui-monospace, Consolas, monospace; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.brand span { font-weight: 400; color: var(--muted); margin-left: 4px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--text); }
.topbar nav a.active, .topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.who { display: flex; align-items: center; gap: 10px; }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
main.narrow { max-width: 760px; }
main.center { display: grid; place-items: center; min-height: 90vh; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-title h2 { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { filter: brightness(0.97); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.warn { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
form.inline { display: inline; margin: 0; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 140px; }
.grow { flex: 1; min-width: 100px; } .grow2 { flex: 2; min-width: 160px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.flash.error { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.flash.warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
.banner { padding: 8px 20px; font-size: 13px; }
.banner.error { background: var(--red-bg); color: var(--red); }

.muted { color: var(--muted); } .small { font-size: 12.5px; } .tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; } .red-text { color: var(--red); }

.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; margin: 2px 4px 2px 0; font-weight: 600; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.grey { background: var(--grey-bg); color: var(--muted); }
.cat { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--grey-bg); text-transform: capitalize; }
.cat-tracking { background: #e2ecff; color: #2457d6; } .cat-refund { background: var(--amber-bg); color: var(--amber); }
.cat-return { background: #efe4ff; color: #6b3fc4; } .cat-complaint { background: var(--red-bg); color: var(--red); }
.cat-product { background: var(--green-bg); color: var(--green); }
@media (prefers-color-scheme: dark) { .cat-tracking { background: #1d2a4a; color: #8fb0ff; } .cat-return { background: #2c2142; color: #c2a5ff; } }
.st { font-size: 12px; font-weight: 600; text-transform: capitalize; }
.st-open { color: var(--accent); } .st-waiting { color: var(--amber); } .st-resolved { color: var(--green); }

/* Queue */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--text); }
.tabs a.active { background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.filters { display: flex; gap: 8px; }
.filters select { width: 150px; } .filters input { width: 280px; }
table.queue { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.queue th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.queue td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.queue tbody tr { cursor: pointer; } .queue tbody tr:hover { background: var(--surface-2); }
.queue tr.has-error td:first-child { border-left: 3px solid var(--red); }

/* Ticket */
.ticket-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.status-form { display: flex; gap: 10px; } .status-form select { width: 160px; }
.summary { margin: 8px 0 0; }
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .ticket-grid { grid-template-columns: 1fr; } }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--in-bg); max-width: 92%; }
.msg.out { background: var(--out-bg); align-self: flex-end; }
.msg.ack { opacity: .75; }
.msg header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.reply-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.reply-actions label { margin: 0; display: flex; gap: 6px; align-items: center; }
.reply-actions select { width: auto; margin: 0; }
.redraft { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.note { padding: 8px 0; border-bottom: 1px solid var(--border); }
.note div { white-space: pre-wrap; }
#notes form { margin-top: 10px; }

.order-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-size: 13px; margin-bottom: 10px; }
.kv > span:nth-child(odd) { color: var(--muted); }
table.items { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; }
.items th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: 4px 0; }
.items td { padding: 4px 0; border-bottom: 1px solid var(--border); }
.track { padding: 8px 0; border-bottom: 1px solid var(--border); }
.track:last-child { border-bottom: 0; }
.track-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.status-chip { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--grey-bg); }
.s-delivered { background: var(--green-bg); color: var(--green); }
.s-in_transit, .s-out_for_delivery, .s-manifested { background: #e2ecff; color: #2457d6; }
.s-exception, .s-attempted_delivery { background: var(--red-bg); color: var(--red); }
.events { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; }
.events li { margin-bottom: 3px; }
.card.action { border-left: 3px solid var(--amber); }
.item-pick { align-items: center; margin-bottom: 4px; }
.item-pick label { margin: 0; }
.qty { width: 64px !important; flex: 0 0 64px; }
.hist { padding: 5px 0; border-bottom: 1px solid var(--border); }

/* Confirm, login, orders */
.confirm .big { font-size: 34px; font-weight: 700; margin: 6px 0; }
.summary-box { background: var(--surface-2); padding: 12px; border-radius: 8px; white-space: pre-wrap; }
.login { width: 340px; }
.login h1 { margin-bottom: 0; }
.search-big { margin-bottom: 16px; max-width: 640px; }
.order-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .filters input { width: 100%; } .filters { width: 100%; }
  .queue th:nth-child(5), .queue td:nth-child(5), .queue th:nth-child(7), .queue td:nth-child(7) { display: none; }
  .order-results { grid-template-columns: 1fr; }
}
.track-links { margin-top: 6px; }
.tracking-note { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.tracking-note label.check { margin: 0; flex: 1; }
.steps { padding-left: 20px; } .steps li { margin-bottom: 10px; }
.qr { background: #fff; padding: 10px; border-radius: 8px; width: max-content; margin: 8px 0; }
.qr svg { display: block; width: 200px; height: 200px; }
code.secret { word-break: break-all; font-size: 13px; }
.qty-wide { width: 110px !important; flex: 0 0 110px; }
tr.inactive td { opacity: .55; }
.who a.muted { color: var(--muted); }
.banner.warn { background: var(--amber-bg); color: var(--amber); }
/* Filtering */
.bulkbar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.bulkbar label.check { margin: 0; }
th.cb, td.cb { width: 34px; padding-left: 8px !important; padding-right: 4px !important; }
td.cb input { width: auto; }
.rowmenu { position: relative; }
.rowmenu summary { list-style: none; cursor: pointer; padding: 2px 8px; border-radius: 6px; color: var(--muted); font-weight: 700; }
.rowmenu summary::-webkit-details-marker { display: none; }
.rowmenu summary:hover, .rowmenu[open] summary { background: var(--surface-2); color: var(--text); }
.rowmenu .menu { position: absolute; right: 0; top: 28px; z-index: 10; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.15); min-width: 260px; padding: 4px; }
.rowmenu .menu form { margin: 0; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px;
  font: inherit; color: var(--text); cursor: pointer; white-space: normal; }
.menu-item:hover { background: var(--surface-2); }
.filter-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 14px; }
.filtered-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.filtered-banner form { margin: 0; }
.tabs a.tab-filtered { color: var(--muted); }

/* ---- Brands (several shops in one portal) ---- */
.brand-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; margin: 0 6px 2px 0;
  border-radius: 10px; color: #fff; background: var(--bc, #4b5563); vertical-align: middle; white-space: nowrap; }
.brand-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.brand-tabs a { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text);
  background: var(--surface); font-size: 13.5px; }
.brand-tabs a.active { border-color: var(--bc, var(--text)); box-shadow: inset 0 0 0 1px var(--bc, var(--text)); font-weight: 700; }
.brand-tabs .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bc); margin-right: 6px; }
.search-big select { max-width: 180px; }

/* ---- Settings page ---- */
.hidden { display: none; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 16px; }
.setting { display: flex; flex-direction: column; gap: 3px; }
.setting > span:first-child { font-size: 13px; }
.setting .badge { font-size: 10.5px; }
#settings-form h3 { margin: 14px 0 4px; font-size: 14px; }

/* ---- CS Hub: brand on/off ---- */
.hub-brands { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-left: 10px; }
.hub-pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; color: var(--text);
  border: 1px solid var(--border); background: var(--surface); text-decoration: none; white-space: nowrap; }
.hub-pill .dot, .brand-tabs .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bc); margin-right: 5px; }
.hub-pill.off { color: var(--muted); }
.hub-pill.off .dot, .brand-tabs .dot.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--bc); }
.brand-switch { padding: 6px 0; border-bottom: 1px solid var(--border); }
.brand-switch:last-of-type { border-bottom: 0; }

/* ---- Version footer + release log ---- */
.appfoot { text-align: center; padding: 18px 0 26px; font-size: 12px; }
.appfoot a { color: var(--muted); }
.changelog h2.release { margin-top: 22px; font-size: 18px; }
.changelog h3 { font-size: 14px; margin: 12px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.changelog ul { margin: 4px 0 8px 18px; padding: 0; }
.changelog li { margin: 3px 0; }
.changelog hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---- Backups ---- */
.backup-kv { margin: 10px 0; }
pre.pubkey { white-space: pre-wrap; word-break: break-all; font-size: 11.5px; background: var(--bg); padding: 8px; border-radius: 6px; }

/* ---- Delivery photos ---- */
.photo-box { margin: 8px 0 4px; }
.photo-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; cursor: text; line-height: 1.6; }
.photo-zone:focus, .photo-zone.drag { outline: none; border-color: #2563eb; background: rgba(37, 99, 235, .06); }
.photo-zone kbd { font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--surface); }
.photo-zone .link { color: #2563eb; text-decoration: underline; cursor: pointer; display: inline; font-weight: 400; margin: 0; }
.photo-count { display: block; font-weight: 600; color: #15803d; }
.photo-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.photo-thumb { position: relative; }
.photo-thumb img { height: 90px; border-radius: 6px; border: 1px solid var(--border); display: block; }
.photo-remove { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: #b91c1c; color: #fff; font-weight: 700; cursor: pointer; line-height: 22px; padding: 0; }
.msg-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.msg-photos img { max-height: 140px; border-radius: 6px; border: 1px solid var(--border); }

/* ---- Brands: details, logo, add ---- */
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.logo-preview { max-height: 48px; max-width: 230px; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 4px; }
.logo-file { max-width: 230px; font-size: 12px; }
.color-pick { width: 64px; height: 34px; padding: 2px; }
.remove-brand { margin-top: 10px; }
#add-brand h3 { margin: 14px 0 4px; font-size: 14px; }

/* ---- Customer attachments + viewer ---- */
.msg-files { margin-top: 10px; }
.msg-files .msg-photos img { height: 130px; width: auto; max-width: 220px; object-fit: cover; cursor: zoom-in; background: #f4f4f4; }
.msg-files .msg-photos a:hover img { outline: 2px solid var(--accent, #2563eb); }
.att-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--card, #fff); text-decoration: none; max-width: 100%; }
.att-chip span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.att-count { font-size: 12px; white-space: nowrap; }
.fetch-files { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.viewer { position: fixed; inset: 0; z-index: 1000; background: rgba(10, 12, 16, .92); display: flex;
  flex-direction: column; color: #fff; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.viewer-bar .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.viewer-bar button, .viewer-bar a { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 6px;
  padding: 7px 12px; font-size: 14px; cursor: pointer; text-decoration: none; }
.viewer-bar button:hover, .viewer-bar a:hover { background: rgba(255,255,255,.25); }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; position: relative; }
.viewer-stage img { max-width: 96%; max-height: 96%; object-fit: contain; cursor: zoom-in; transition: transform .15s; background: #fff; }
.viewer-stage.zoomed { align-items: flex-start; justify-content: flex-start; }
.viewer-stage.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.14); color: #fff;
  border: 0; font-size: 30px; width: 48px; height: 64px; border-radius: 8px; cursor: pointer; }
.viewer-nav:hover { background: rgba(255,255,255,.3); }
.viewer-nav.prev { left: 12px; } .viewer-nav.next { right: 12px; }
.viewer-hint { text-align: center; font-size: 12px; opacity: .7; padding: 6px; }
