:root {
    --ink: #0a0a0a;
    --ink-2: #555;
    --ink-3: #8a8578;
    --ground: #f2ede2;
    --card: #fffdf8;
    --line: #e2dccd;
    --accent: #6344f5;
    --accent-soft: #efebff;
    --ok: #1f7a4d;
    --ok-soft: #e6f4ec;
    --warn: #8a5a00;
    --warn-soft: #fff4dc;
    --err: #b42318;
    --err-soft: #fdecea;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 17px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--ink);
    background: var(--ground);
}

.wrap { max-width: 960px; margin: 0 auto; padding: 48px 20px 80px; }

.brand { font-size: 15px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
h1 { font-size: 34px; line-height: 1.2; letter-spacing: -.01em; margin: 6px 0 8px; }
.lede { color: var(--ink-2); margin: 0 0 32px; }

a { color: var(--accent); }
.back { display: inline-block; font-size: 16px; text-decoration: none; margin-bottom: 20px; }
.back:hover { text-decoration: underline; }

/* Menu */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tile {
    display: flex; flex-direction: column; gap: 6px;
    padding: 22px; min-height: 150px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    color: inherit; text-decoration: none;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tile:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(99, 68, 245, .12); transform: translateY(-1px); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile h2 { font-size: 20px; margin: 0; }
.tile p { margin: 0; color: var(--ink-2); font-size: 16px; flex: 1; }
.tag {
    align-self: flex-start; font: 600 14px/1 "JetBrains Mono", ui-monospace, Menlo, monospace;
    padding: 5px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}

/* Drop zone */
.drop {
    display: flex; flex-direction: column; align-items: center; gap: 12px;
    padding: 56px 24px; text-align: center;
    background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius);
    transition: border-color .15s, background .15s;
}
.drop.compact { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 20px 24px; }
.drop.compact p { display: none; }
.drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop p { margin: 0; color: var(--ink-2); }
.drop strong { color: var(--ink); font-size: 19px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 20px; border-radius: 8px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5236e0; }

/* Status + results */
.status { margin-top: 20px; padding: 14px 16px; border-radius: 10px; font-weight: 500; }
.status.busy { background: var(--accent-soft); color: var(--accent); }
.status.err { background: var(--err-soft); color: var(--err); }

.result { margin-top: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.result-head h2 { margin: 0; font-size: 21px; }
.stats { display: flex; flex-wrap: wrap; gap: 24px; margin: 18px 0 0; }
.stat b { display: block; font-size: 25px; }
.stat span { font-size: 15px; color: var(--ink-3); }

.notice { margin-top: 18px; padding: 14px 16px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice h3 { margin: 0 0 6px; font-size: 16px; }
.notice p { margin: 0 0 8px; font-size: 16px; }
.notice ul { margin: 0; padding-left: 18px; font-size: 16px; }
.notice code { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 15px; }

.table-wrap { margin-top: 20px; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 11px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { background: #faf7f0; font-weight: 600; color: var(--ink-2); }
tr:last-child td { border-bottom: 0; }
td.unmapped { color: var(--warn); font-weight: 600; }
.more { font-size: 15px; color: var(--ink-3); margin: 10px 0 0; }

[hidden] { display: none !important; }

/* Fresh Markets page */
.server-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: -12px 0 24px; }
.seg { display: inline-flex; padding: 3px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.seg button { font: inherit; font-weight: 600; font-size: 16px; padding: 7px 16px; border: 0; border-radius: 7px; background: none; color: var(--ink-2); cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--accent); color: #fff; }
body.prod .seg button[aria-selected="true"] { background: var(--err); }
.server-info { margin: 0; font-size: 15px; color: var(--ink-3); }
.pill { display: inline-block; margin-right: 8px; padding: 4px 10px; border-radius: 6px; font-size: 14px; font-weight: 600; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }

.panel { margin-top: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.panel-head h2 { display: inline; margin: 0; font-size: 21px; }
.panel-head .sub { margin: 4px 0 0; font-size: 16px; color: var(--ink-2); }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 8px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 700; vertical-align: 2px; }
.panel .drop { margin-top: 16px; padding: 36px 24px; }
.btn.small { padding: 8px 14px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status:not(.busy):not(.err):not(.ok) { background: #f6f2e8; color: var(--ink-2); }
.muted-note { margin-top: 8px; font-size: 15px; color: var(--ink-3); }
.empty { margin: 8px 0 0; color: var(--ink-3); font-size: 16px; }

.day-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 4px; }
.day-head h3 { margin: 0; font-size: 17px; }
.order, .invoice { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.invoice.ok { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok) inset; }
.invoice.sent { opacity: .7; }
.order-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.order-head .meta { font-size: 15px; color: var(--ink-3); margin-top: 2px; }
.order-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.order .table-wrap, .invoice .table-wrap { margin-top: 12px; }
.order .notice, .invoice .notice { margin-top: 12px; }
.notice.err { background: var(--err-soft); color: var(--err); }
.notice.err .btn { margin-top: 4px; }
td.num, th.num { text-align: right; }
td.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 14px; }
td.hl { color: var(--warn); font-weight: 600; }
tfoot td { font-weight: 700; background: #faf7f0; border-bottom: 0; }
.confirm { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 16px; font-weight: 600; cursor: pointer; }
.confirm input { width: 18px; height: 18px; accent-color: var(--ok); }

.earlier { margin-top: 20px; }
.earlier summary { cursor: pointer; font-weight: 600; font-size: 16px; color: var(--ink-2); }

.send-bar { position: sticky; bottom: 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 14px 16px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.send-bar p { margin: 0; font-size: 16px; }
body.prod .send-bar .btn.primary { background: var(--err); border-color: var(--err); }

@media (max-width: 560px) {
    .panel { padding: 18px 16px; }
    .send-bar { bottom: 8px; }
}
.check-result { margin-top: 16px; padding: 18px; border-radius: 10px; background: #fff; border: 1px solid var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.check-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.check-head h3 { margin: 0; font-size: 19px; }
.check-head .meta { margin: 4px 0 0; font-size: 15px; color: var(--ink-3); }
.check-result .table-wrap { margin-top: 14px; }
.pill.new { background: var(--ok-soft); color: var(--ok); }
.pill.old { background: #f1ede4; color: var(--ink-2); }

/* Invoice check + fix */
.invoice.needs { border-color: var(--err); box-shadow: 0 0 0 1px var(--err) inset; }
.verdict { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 16px; }
.verdict.good { background: var(--ok-soft); color: var(--ok); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.verdict.bad { background: var(--err-soft); color: var(--err); }
tr.flagged td { background: #fffdf5; }
td .was { font-family: Inter, sans-serif; font-size: 14px; color: var(--warn); font-weight: 600; }
tr.detail td { background: #faf7f0; padding: 0; }
.fix { padding: 14px 16px; }
.fix-why { margin: 0 0 8px; font-size: 15px; color: var(--ink-2); }
.fix-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; color: var(--ink-3); }
.field select, .field input { font: inherit; font-weight: 400; font-size: 16px; color: var(--ink); padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-width: 320px; }
.field input { width: 120px; }
.fix-remember { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 15px; font-weight: 600; }
.fix-actions { margin-top: 12px; }
.confirm.disabled { color: var(--ink-3); cursor: not-allowed; }
td .pill { margin: 1px 4px 1px 0; }
table td:has(.pill) { white-space: normal; min-width: 150px; }
.changed-panel { margin-top: 12px; padding: 14px 16px; border-radius: 8px; background: var(--accent-soft); }
.changed-panel h4 { margin: 0 0 10px; font-size: 16px; color: var(--accent); }
.change-item { margin-bottom: 10px; }
.change-item:last-of-type { margin-bottom: 0; }
.change-head { font-weight: 600; font-size: 16px; }
.change { font-size: 15px; margin-top: 3px; }
.change .from { text-decoration: line-through; color: var(--ink-3); }
.change strong { font-weight: 600; }
.why { font-size: 14px; color: var(--ink-3); margin: 4px 0 0; }
.pill.auto { background: var(--accent); color: #fff; }
.pill.manual { background: var(--ink); color: #fff; }

/* Wider text means the line tables need to breathe: only the wordy columns wrap. */
.invoice table { table-layout: fixed; }
.invoice th, .invoice td { white-space: normal; padding: 10px 12px; vertical-align: top; }
.invoice td.num, .invoice th.num, .invoice td.mono, .invoice td:last-child, .invoice th:last-child { white-space: nowrap; }
.invoice td .pill { font-size: 13px; padding: 3px 8px; margin: 2px 4px 2px 0; }
.invoice table td:has(.pill) { min-width: 0; }
.invoice col.c-code { width: 10%; }
.invoice col.c-name { width: 19%; }
.invoice col.c-qty { width: 6%; }
.invoice col.c-unit { width: 7%; }
.invoice col.c-money { width: 10%; }
.invoice col.c-check { width: 17%; }
.invoice col.c-fix { width: 11%; }

/* Fix panel: say the difference, then ask the question */
.fix-q p { margin: 0 0 6px; font-size: 16px; }
.fix-q p:last-child { margin-bottom: 12px; }
.fix-choices { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.choice { text-align: left; font: inherit; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.choice:hover { border-color: var(--ink-3); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: 0 0 0 1px var(--accent) inset; }
.fix-more { margin-top: 10px; }
.fix-more summary { cursor: pointer; font-size: 15px; color: var(--ink-2); }

/* Review before sending */
.review { margin-top: 20px; padding: 20px; border-radius: var(--radius); background: #fff; border: 2px solid var(--accent); }
body.prod .review { border-color: var(--err); }
.review h3 { margin: 0; font-size: 20px; }
.review > .sub { margin: 6px 0 16px; color: var(--ink-2); font-size: 16px; }
.review-inv { padding: 16px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; }
.review-file { font-weight: 600; font-size: 16px; }
.review-changes { margin: 10px 0 0; padding-left: 20px; font-size: 15px; }
.review-csv { margin: 12px 0 0; padding: 12px; background: #faf7f0; border-radius: 8px; font: 13px/1.6 "JetBrains Mono", ui-monospace, Menlo, monospace; white-space: pre; overflow-x: auto; }
.review-actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* Price comparison */
.price-panel { margin-top: 12px; padding: 14px 16px; border-radius: 8px; background: var(--warn-soft); }
.price-panel h4 { margin: 0 0 10px; font-size: 16px; color: var(--warn); }
.price-table { width: 100%; border-collapse: collapse; font-size: 15px; background: #fff; border-radius: 8px; overflow: hidden; }
.price-table th, .price-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.price-table th.num, .price-table td.num { text-align: right; }
.price-table tr:last-child td { border-bottom: 0; }
td.over { color: var(--err); font-weight: 600; }
td.under { color: var(--ok); font-weight: 600; }
.price-panel .fix-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.fix-compare { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.compare-row { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.compare-text { font-size: 15px; margin-bottom: 8px; }
.compare-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.choice.small { font-size: 15px; padding: 8px 14px; width: auto; }

/* Changed-total alert */
.total-alert { margin-top: 12px; padding: 14px 16px; border-radius: 8px; background: var(--err-soft); border: 1px solid var(--err); }
.total-alert h4 { margin: 0 0 6px; font-size: 17px; color: var(--err); }
.total-alert p { margin: 0 0 4px; font-size: 16px; }
.notice.warn-strong { background: var(--err-soft); color: var(--err); font-weight: 600; }
.change { font-size: 15px; margin-top: 5px; line-height: 1.5; }
.change .pill { vertical-align: 1px; }

/* Saved product-code rules */
.rules-panel { margin-top: 12px; padding: 14px 16px; border-radius: 8px; background: var(--accent-soft); border: 1px solid var(--accent); }
.rules-panel h4 { margin: 0 0 10px; font-size: 16px; color: var(--accent); }
.rule-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 16px; }
.linkish { background: none; border: 0; padding: 0; margin-top: 4px; font: inherit; font-size: 15px; color: var(--accent); text-decoration: underline; cursor: pointer; }
.send-bar-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.send-bar .btn:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.send-bar .btn:not(.primary):hover { border-color: #fff; }
tr.blocking td { background: #fff6f5; }
tr.pointed td, tr.pointed { animation: point 2.6s ease-out; }
@keyframes point { 0%, 60% { background: var(--err-soft); box-shadow: inset 3px 0 0 var(--err); } 100% { background: none; } }
.fix-outcome { margin: 10px 0 0; padding: 10px 14px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); font-size: 15px; }

/* The "I have checked this invoice" step: a big, obvious final action on each invoice */
.confirm {
    display: flex; align-items: center; gap: 16px;
    margin-top: 18px; padding: 18px 20px;
    font-size: 19px; font-weight: 700; line-height: 1.35;
    border: 2px solid var(--accent); border-radius: 12px;
    background: var(--accent-soft); color: var(--ink);
    cursor: pointer; transition: background .15s, border-color .15s;
}
.confirm:hover { background: #e4ddff; }
.confirm input { flex: none; width: 30px; height: 30px; margin: 0; accent-color: var(--ok); cursor: pointer; }
.invoice.ok .confirm { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.confirm.disabled { border-style: dashed; border-color: var(--line); background: #f6f3ec; color: var(--ink-3); cursor: not-allowed; font-weight: 600; }
.confirm.disabled input { cursor: not-allowed; }
