:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e6e3de;
  --accent: #c0392b;
  --accent-dark: #96271c;
  --accent-soft: #fbeae7;
  --ok: #157347;
  --ok-soft: #e6f4ec;
  --warn: #b45309;
  --warn-soft: #fdf1e1;
  --danger: #b02a37;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,20,30,.05), 0 8px 24px rgba(20,20,30,.06);
  --maxw: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b; --surface: #1c1f26; --ink: #eceef2; --muted: #9aa2b1;
    --line: #2a2e37; --accent: #e05a48; --accent-dark: #c0392b; --accent-soft: #2a1f1d;
    --ok: #3fb27f; --ok-soft: #17271f; --warn: #d98a2b; --warn-soft: #2a2114;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand-mark { font-size: 1.35rem; }
.brand-name { letter-spacing: .2px; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 18px 16px 40px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px 16px 40px; }

h1 { font-size: 1.5rem; margin: 6px 0 2px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); text-align: center; padding: 28px 16px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { font-size: 2rem; }
.dropzone .dz-main { font-weight: 600; margin-top: 6px; }
.dropzone .dz-sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.dropzone input[type=file] { display: none; }

/* File list */
.filelist { list-style: none; margin: 6px 0 0; padding: 0; }
.fileitem {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  margin-bottom: 8px; touch-action: none;
}
.fileitem.dragging { opacity: .55; }
.fileitem.rejected { border-color: var(--danger); background: var(--warn-soft); }
.handle { cursor: grab; color: var(--muted); font-size: 1.1rem; padding: 0 2px; user-select: none; }
.fmeta { flex: 1 1 auto; min-width: 0; }
.fname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fsub { font-size: .8rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .3px;
  text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: var(--line); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--accent-soft); color: var(--danger); }
.reason { color: var(--danger); font-size: .8rem; }
.forder { display: flex; flex-direction: column; }
.iconbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; width: 34px; height: 30px; font-size: 1rem; cursor: pointer; line-height: 1;
}
.iconbtn:disabled { opacity: .35; cursor: default; }
.iconbtn.mini { width: 26px; height: 20px; font-size: .75rem; }
.removebtn { color: var(--danger); border-color: var(--line); }

/* Options */
.optrow { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.copies { display: inline-flex; align-items: center; gap: 8px; }
.copies input { width: 64px; text-align: center; }
input[type=number], select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink);
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--ink); padding: 8px 14px; cursor: pointer; font: inherit; }
.seg button.active { background: var(--accent); color: #fff; }

/* Summary */
.summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.summary .row { display: contents; }
.summary .k { color: var(--muted); }
.summary .v { text-align: right; font-variant-numeric: tabular-nums; }
.summary .total { font-weight: 800; font-size: 1.25rem; color: var(--accent); }
.summary hr { grid-column: 1 / -1; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Language selector */
.langsel { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.langsel a { color: var(--muted); text-decoration: none; font-size: .78rem; padding: 4px 8px; border-radius: 7px; white-space: nowrap; }
.langsel a.active { background: var(--accent); color: #fff; }

/* Payment method selector */
.pay-seg { display: flex; width: 100%; }
.pay-seg button { flex: 1 1 0; text-align: center; }
.seg button.soon { opacity: .65; font-style: italic; }

/* Upload / processing progress */
.progress-card { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.prog-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.prog-stage { font-weight: 700; }
.prog-pct { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.prog-track { height: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.prog-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.prog-bar.indet { width: 45%; animation: prog-indet 1.1s ease-in-out infinite; }
@keyframes prog-indet { 0% { margin-left: -45%; } 100% { margin-left: 100%; } }
.prog-detail { margin-top: 8px; color: var(--muted); font-size: .85rem; min-height: 1.1em; }
.prog-error { margin-top: 8px; color: #ff6b6b; font-size: .88rem; }
.prog-actions { display: flex; gap: 8px; margin-top: 10px; }
.prog-actions button.hidden { display: none; }

/* Layout (1-up / 2-up) diagram */
.layout-diagram { margin-top: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.layout-diagram .diagram { width: auto; height: 116px; }
.layout-diagram .sheet { fill: var(--surface); stroke: var(--line); stroke-width: 2; }
.layout-diagram .pg { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: var(--accent); stroke-width: 1.5; }
.layout-diagram .pgn { fill: var(--accent); font: 700 20px system-ui, sans-serif; text-anchor: middle; }
.layout-diagram .diagram-cap { color: var(--muted); font-size: .82rem; text-align: center; max-width: 320px; }

/* Banners */
.banner { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .92rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0d9b0; }
.banner.err { background: var(--accent-soft); color: var(--danger); border: 1px solid #eecac4; }
.banner.info { background: var(--ok-soft); color: var(--ok); border: 1px solid #cfe9db; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; border: 0; border-radius: 12px; cursor: pointer;
  padding: 13px 18px; text-decoration: none;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 10px; margin-top: 4px; }

/* Preview */
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.preview-frame { width: 100%; height: 62vh; min-height: 380px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.preview-empty { display: flex; align-items: center; justify-content: center; height: 200px; color: var(--muted); }
/* Image-based preview: renders on every device (mobile browsers can't show a PDF iframe). */
.preview-pages { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; padding: 4px; background: var(--line); border-radius: 12px; }
.preview-page { width: 100%; height: auto; display: block; background: #fff; border-radius: 6px; box-shadow: 0 1px 6px rgba(0,0,0,.35); }

/* Confirm */
.confirm { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0; }
.confirm input { margin-top: 4px; width: 18px; height: 18px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }
.big-code { font-size: 2rem; font-weight: 800; letter-spacing: 1px; color: var(--accent); }

@media (min-width: 620px) {
  .preview-frame { height: 70vh; }
}

/* ---------- Staff ---------- */
.staffnav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.staffnav a { color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; }
.staffnav a.active, .staffnav a:hover { color: var(--ink); }
.spacer { flex: 1 1 auto; }
.agentpill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.agentpill.online { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.agentpill.online .dot { background: var(--ok); }
.agentpill.offline { color: var(--muted); }

.container.wide { max-width: 1080px; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--muted);
  border: 1px solid var(--line); font-size: .88rem; font-weight: 600; }
.tabs a.active { background: var(--accent); color: #fff; border-color: transparent; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.orders { width: 100%; border-collapse: collapse; min-width: 720px; }
table.orders th, table.orders td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: .92rem; white-space: nowrap; }
table.orders th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; }
table.orders tr:last-child td { border-bottom: 0; }
table.orders tbody tr:hover { background: rgba(128,128,128,.05); }
table.orders a.code { font-weight: 800; color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

.pill { display: inline-block; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--line); color: var(--ink); text-transform: capitalize; }
.pill.awaiting_print { background: var(--warn-soft); color: var(--warn); }
.pill.printing { background: #e8effb; color: #2f5fb0; }
.pill.printed { background: var(--ok-soft); color: var(--ok); }
.pill.cancelled { background: var(--accent-soft); color: var(--danger); }
.pill.paid { background: var(--ok-soft); color: var(--ok); }
.pill.unpaid { background: var(--warn-soft); color: var(--warn); }
.pill.attn { background: var(--accent-soft); color: var(--danger); }

.detail-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .detail-grid { grid-template-columns: 1.3fr 1fr; align-items: start; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.btnrow form { margin: 0; }
.btn.sm { padding: 9px 14px; font-size: .9rem; }
.btn.warn { background: var(--warn); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.origlist { list-style: none; margin: 0; padding: 0; }
.origlist li { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.origlist li:last-child { border-bottom: 0; }
.origlist .oname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.flash { border-radius: 12px; padding: 11px 14px; margin-bottom: 14px; font-size: .92rem; }
.flash.info { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--accent-soft); color: var(--danger); }

.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-wrap .field { margin-bottom: 14px; }
.login-wrap input { width: 100%; }
.form-grid { display: grid; gap: 12px; }
.form-grid label { font-size: .82rem; color: var(--muted); font-weight: 600; display: block; margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.chk { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); margin: 0 0 0 0; cursor: pointer; }
.chk input { width: auto !important; margin: 0; }
textarea { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); }
.tier-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.tier-row input { width: 120px; }
.qr { display: block; width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 10px; }
code.inline { background: var(--line); padding: 2px 6px; border-radius: 6px; font-size: .85rem; word-break: break-all; }
