:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c2330;
  --muted: #6b7482;
  --accent: #972533;
  --accent-dark: #7a1d29;
  --accent-soft: #f6e9eb;
  --ok: #1f8f4e;    --ok-soft: #e4f5ea;
  --warn: #b9760c;  --warn-soft: #fdf1dc;
  --bad: #c43a31;   --bad-soft: #fbe6e4;
  --none-soft: #eceef1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --topbar-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.45; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; letter-spacing: .01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* topbar */
.topbar { height: var(--topbar-h); display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 0 32px; background: var(--accent); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 40px; height: 40px; padding: 7px; border-radius: 10px; background: #fff; display: block; }
.topbar h1 { font-size: 18px; }
.topbar h1 .muted { font-weight: 400; margin-left: 6px; color: rgba(255,255,255,.75); }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
.topbar .btn:hover { background: rgba(255,255,255,.12); border-color: #fff; }

/* buttons */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px; font: inherit; font-size: 13.5px; cursor: pointer; transition: all .12s; }
.btn:hover { border-color: #b8c0cb; background: #f7f8fa; }
.btn.big { padding: 11px 18px; font-size: 14.5px; width: 100%; background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 20px; line-height: 1; border-radius: 50%; }
.btn:disabled { opacity: .5; cursor: default; }

/* intake */
.intake { min-height: calc(100vh - var(--topbar-h)); display: grid; place-items: center; padding: 32px; }
.intake-card { width: min(520px, 100%); }
.card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.dropzone { border: 1.5px dashed #c7cdd6; border-radius: 10px; padding: 40px 18px; text-align: center; cursor: pointer; color: var(--muted); transition: all .15s ease; background: #fafbfc; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); outline: none; }
.dropzone strong { color: var(--text); font-size: 15.5px; }
.dropzone span { font-size: 13px; }
.dz-icon { margin-bottom: 6px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; margin: 16px 0; text-transform: uppercase; letter-spacing: .06em; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* work view */
.work { display: grid; grid-template-columns: minmax(360px, 42%) minmax(0, 1fr); gap: 20px; padding: 20px 24px 40px; max-width: 1800px; margin: 0 auto; align-items: start; }
@media (max-width: 1000px) { .work { grid-template-columns: 1fr; } .preview { position: static !important; height: 60vh !important; } }
.preview { position: sticky; top: calc(var(--topbar-h) + 20px); height: calc(100vh - var(--topbar-h) - 40px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.preview-head { padding: 10px 16px; border-bottom: 1px solid var(--border); border-top: 3px solid var(--accent); font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-body { flex: 1; min-height: 0; background: #e9ebef; display: grid; place-items: center; }
.preview-body iframe, .preview-body img { width: 100%; height: 100%; border: 0; display: block; object-fit: contain; }
.preview-body .noprev { text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.preview-body .noprev .ftype { font-size: 12px; }
.results { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* busy / error */
.steps { list-style: none; margin: 0; padding: 80px 20px; display: flex; flex-direction: column; align-items: center; gap: 18px; font-size: 16px; color: #aab1bb; }
.steps li { display: flex; align-items: center; gap: 14px; width: 220px; transition: color .3s; }
.steps li.running { color: var(--text); }
.steps li.done { color: var(--ok); }
.steps .mark { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d7dce3; display: grid; place-items: center; transition: all .3s; }
.steps li.running .mark { border-color: #d7dce3; border-top-color: var(--accent); animation: spin .9s linear infinite; }
.steps li.done .mark { background: var(--ok); border-color: var(--ok); animation: bump .4s cubic-bezier(.3,1.6,.5,1); }
.steps li.done .mark::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
@keyframes spin { to { transform: rotate(360deg); } }
.error { border: 1px solid #f1c1bd; background: var(--bad-soft); color: #7d2a24; border-radius: var(--radius); padding: 14px 16px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }

/* header */
.doc-type { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; background: var(--none-soft); color: var(--muted); white-space: nowrap; }
.doc-type.order, .doc-type.inquiry { background: var(--accent-soft); color: var(--accent); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 24px; margin: 0; }
.kv > div { border-top: 1px solid var(--border); padding-top: 8px; min-width: 0; }
.kv dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.kv dd { margin: 0; white-space: pre-line; word-break: break-word; }
.kv > div.wide { grid-column: 1 / -1; }
.kv dd ul { margin: 0; padding-left: 16px; } .kv dd ul li { margin: 1px 0; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; margin-left: 6px; vertical-align: middle; }
.pill.warn { background: #fef3c7; color: #92400e; }
.flags { margin-top: 14px; padding: 10px 14px; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px; font-size: 13px; }
.flags b { display: block; margin-bottom: 4px; }
.flags ul { margin: 0 0 0 18px; padding: 0; } .flags li { margin: 2px 0; }

/* lines table */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table.lines { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.lines th, table.lines td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.lines th { font-size: 11.5px; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; white-space: nowrap; background: var(--accent-soft); }
table.lines th.num, table.lines td.num { text-align: right; white-space: nowrap; }
table.lines td.desc { min-width: 240px; }
table.lines td.desc .spec { font-size: 12px; color: var(--muted); margin-top: 3px; }
table.lines td.sap { min-width: 220px; }
table.lines td.sap .art { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; font-size: 13.5px; }
table.lines td.sap .art-desc { font-size: 12px; color: var(--muted); }
table.lines td.sap .notfound { font-size: 12.5px; color: #4b5563; margin-bottom: 4px; }
table.lines td.cust { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; white-space: nowrap; }
table.lines.no-cust .col-cust, table.lines.no-cust td.cust { display: none; }
table.lines td.sap .options { font-size: 12px; margin-top: 4px; } table.lines td.sap .options code { background: #f3f4f6; padding: 1px 5px; border-radius: 3px; margin-right: 4px; }
table.lines td.cert { font-size: 12.5px; max-width: 180px; }
table.lines td.rem { font-size: 12.5px; min-width: 140px; max-width: 260px; color: #4b5563; }
table.lines.no-cert .col-cert, table.lines.no-cert td.cert { display: none; }
table.lines.no-rem .col-rem, table.lines.no-rem td.rem { display: none; }
.qty-alt { display: block; font-size: 11.5px; color: #b45309; margin-top: 2px; white-space: nowrap; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; margin-bottom: 4px; }
.badge.resolved { background: #d1fae5; color: #065f46; } .badge.ambiguous { background: #fef3c7; color: #92400e; }
.badge.none { background: #fee2e2; color: #991b1b; } .badge.not_applicable { background: #e5e7eb; color: #374151; }

/* actions (demo only) */
.card.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 28px; }
.btn.sap, .btn.save { position: relative; overflow: hidden; color: #fff; font-weight: 600; transition: transform .15s, background .3s, border-color .3s; }
.btn.sap { background: var(--ok); border-color: var(--ok); padding: 12px 28px; font-size: 15px; }
.btn.sap:hover { background: #197a42; border-color: #197a42; }
.btn.save { background: var(--accent); border-color: var(--accent); padding: 9px 16px; }
.btn.save:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.sap .done, .btn.save .done { display: none; }
.btn.sap.busy, .btn.save.busy { transform: scale(.96); }
.btn.sap.busy::after, .btn.save.busy::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,.55) 50%, transparent 80%); animation: sweep .55s linear infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.btn.sap.done, .btn.save.done { background: #14532d; border-color: #14532d; animation: bump .5s cubic-bezier(.3,1.6,.5,1); }
.btn.sap.done .label, .btn.save.done .label { display: none; }
.btn.sap.done .done, .btn.save.done .done { display: inline; }
.btn.sap.done .done::before, .btn.save.done .done::before { content: "✓"; margin-right: 8px; }
@keyframes bump { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
.feedback { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 320px; justify-content: flex-end; }
.feedback input { flex: 1; max-width: 360px; min-width: 140px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font: inherit; font-size: 13.5px; }
.feedback input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thumb { appearance: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: all .15s; }
.thumb:hover { border-color: #b8c0cb; color: var(--text); }
.thumb.on { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.thumb.down.on { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.thumb.pop { animation: pop .4s cubic-bezier(.3,1.8,.5,1); }
@keyframes pop { 0% { transform: scale(.8); } 50% { transform: scale(1.3) rotate(-8deg); } 100% { transform: scale(1); } }

/* excluded */
.excluded { list-style: none; margin: 0; padding: 0; }
.excluded li { padding: 7px 0; border-bottom: 1px solid #eee; font-size: 13px; display: flex; gap: 12px; }
.excluded li:last-child { border-bottom: 0; }
.excluded .num { color: var(--muted); min-width: 24px; text-align: right; }
.excluded .why { color: var(--muted); margin-left: auto; text-align: right; white-space: nowrap; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; z-index: 20; padding: 24px; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 48px); background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); border-top: 4px solid var(--accent); }
.samples { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.samples li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.samples li:hover { background: var(--accent-soft); }
.samples li.muted { cursor: default; }
.samples .ftype { flex: none; width: 40px; text-align: center; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; padding: 3px 0; border-radius: 5px; background: var(--none-soft); color: var(--muted); text-transform: uppercase; }
.ftype.pdf { background: #fdeceb; color: #b3372f; } .ftype.xls, .ftype.xlsx { background: #e4f5ea; color: #1f7a45; }
.samples .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 30; }
