:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --muted: #6b6b6b;
  --accent: #b5651d;      /* warm terracotta — RoboAnna, not meifis */
  --accent-ink: #ffffff;
  --line: #e4ded4;
  --error-bg: #fdecea;
  --error-ink: #a12626;
  --dry-bg: #fff4d6;
  --dry-ink: #8a6d1a;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
b { font-weight: 600; }

/* --- login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  background: var(--panel); width: 100%; max-width: 360px;
  padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .85rem;
}
.brand { font-size: 1.4rem; font-weight: 700; letter-spacing: .3px; }
.brand-mark { margin-right: .35rem; }
.subtitle { margin: -.4rem 0 .4rem; color: var(--muted); font-size: .9rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; background: #fff; color: var(--ink);
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
button[type=submit] {
  margin-top: .4rem; padding: .65rem; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 1rem; font-weight: 600;
  cursor: pointer;
}
button[type=submit]:hover { filter: brightness(1.05); }
.error { background: var(--error-bg); color: var(--error-ink); padding: .55rem .7rem; border-radius: 8px; font-size: .88rem; }

/* --- app shell --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-size: 1.15rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; font-size: .88rem; color: var(--muted); }
.badge { padding: .25rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-dry { background: var(--dry-bg); color: var(--dry-ink); }
.btn-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

.mainnav { display: flex; gap: .3rem; margin-left: 1.4rem; margin-right: auto; }
.mainnav a { color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 600; padding: .35rem .7rem; border-radius: 7px; }
.mainnav a:hover { background: #f0ebe2; color: var(--ink); }
.mainnav a.active { background: var(--accent); color: #fff; }

.content { max-width: 960px; margin: 1.5rem auto; padding: 0 1.2rem; }
.content.wide { max-width: 1280px; }

/* order list table */
.orders-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.orders-head h1 { margin: 0; font-size: 1.3rem; }
.orders-controls { display: flex; gap: .5rem; align-items: center; }
.orders-controls input, .orders-controls select { padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: .88rem; background: #fff; }
.orders-controls input { min-width: 260px; }
.table-wrap { overflow: auto; max-height: 72vh; border: 1px solid var(--line); border-radius: 8px; }
#orders-table { border-collapse: collapse; width: 100%; font-size: .84rem; }
#orders-table th, #orders-table td { padding: .4rem .6rem; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
#orders-table thead th { position: sticky; top: 0; background: #f3efe8; z-index: 1; cursor: pointer; user-select: none; }
#orders-table th.sortable:hover { background: #eae3d6; }
#orders-table th.asc::after { content: " ▲"; color: var(--accent); }
#orders-table th.desc::after { content: " ▼"; color: var(--accent); }
#orders-table td:first-child { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
#orders-table td a { color: var(--accent); text-decoration: none; }
#orders-table td a:hover { text-decoration: underline; }
#orders-table tbody tr:hover { background: #faf7f1; }
.pill { padding: .1rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.pill-received { background: #e6f4e2; color: #2f6b2a; }
.pill-ordered { background: #e7f0fb; color: #24567e; }
.pill-cancelled { background: var(--error-bg); color: var(--error-ink); }
.pill-none { background: #eee; color: #888; }
.docs-cell { display: flex; gap: .2rem; }
.doctag { width: 1.15rem; height: 1.15rem; display: inline-grid; place-items: center; border-radius: 4px; font-size: .68rem; font-weight: 700; }
.doctag.on { background: #cfe6c8; color: #2f6b2a; }
.doctag.off { background: #efece6; color: #c3bcae; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.panel h1 { margin: 0 0 .4rem; font-size: 1.3rem; }
.muted { color: var(--muted); }
.dropzone {
  margin-top: 1.2rem; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 2.5rem 1rem; text-align: center; color: var(--muted); background: #faf8f4;
}
.dropzone.hot { border-color: var(--accent); background: #fff3e6; color: var(--ink); }
.linkish { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }

/* queue */
.queue { margin-top: 1.2rem; }
.queue h2, .results h2 { font-size: 1rem; color: var(--muted); margin: 0 0 .5rem; }
.queue-hint { font-size: .82rem; margin: -.2rem 0 .5rem; }
.queue ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.q-item { padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #faf8f4; font-size: .88rem; }
.q-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.q-name { font-weight: 600; }
.q-status { color: var(--muted); margin-left: auto; }
.q-dismiss { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .95rem; line-height: 1; padding: .1rem .3rem; border-radius: 5px; }
.q-dismiss:hover { background: var(--error-bg); color: var(--error-ink); }
/* progress bar */
.qbar { margin-top: .45rem; height: 5px; border-radius: 999px; background: #ece6da; overflow: hidden; }
.qbar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.qbar-fill.idle { width: 12%; opacity: .4; }
.qbar-fill.anim { width: 40%; animation: qslide 1.3s ease-in-out infinite; }
@keyframes qslide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.q-error { border-color: #eab8b1; background: var(--error-bg); }
.q-done { border-color: #cfe3c8; background: #f3f9f0; }

/* result cards */
.results { max-width: 960px; margin: 1.2rem auto 3rem; padding: 0 1.2rem; display: flex; flex-direction: column; gap: 1rem; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-dismiss { border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; font-size: .78rem; padding: .2rem .5rem; border-radius: 6px; }
.card-dismiss:hover { background: var(--error-bg); color: var(--error-ink); border-color: #eab8b1; }
.apply-hint { color: var(--dry-ink); font-size: .8rem; }
.card-title { display: flex; align-items: center; gap: .6rem; }
.src-name { font-weight: 600; word-break: break-all; }
.rename { color: var(--muted); font-size: .9rem; }
.rename b { color: var(--accent); }
.doc-badge { padding: .2rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #eee; }
.dt-invoice { background: #e7f0fb; color: #24567e; }
.dt-delivery_note { background: #eaf6e8; color: #2f6b2a; }
.dt-other, .dt-quote { background: #f0ebe2; color: #7a6a4a; }

.warnings { margin: .5rem 0; display: flex; flex-direction: column; gap: .3rem; }
.warn { background: var(--dry-bg); color: var(--dry-ink); padding: .35rem .6rem; border-radius: 6px; font-size: .83rem; }
.card-error .warn { background: var(--error-bg); color: var(--error-ink); }

.line { border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .8rem; }
.line-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .6rem; }
.chip { background: #f0ede7; color: var(--muted); padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; }
.conf { margin-left: auto; padding: .12rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.conf-ok { background: #e6f4e2; color: #2f6b2a; }
.conf-low { background: #fdecd6; color: #99631a; }

.diff { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.side { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; background: #fbfaf7; }
.side-h { font-size: .74rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: .35rem; }
.side.proposed { background: #fbfdfa; border-color: #d5e7cf; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; margin: 0; font-size: .85rem; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.fields dd.changed { color: var(--accent); font-weight: 700; }
@media (max-width: 640px) { .diff { grid-template-columns: 1fr; } }

/* editable proposed fields */
.rename { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .85rem; }
.fname-input { border: 1px solid var(--line); border-radius: 6px; padding: .25rem .45rem; font: inherit; font-size: .85rem; min-width: 260px; color: var(--accent); font-weight: 600; }
.fields dd .prop-input { border: 1px solid #cdd8c6; border-radius: 5px; padding: .1rem .35rem; font: inherit; font-size: .84rem; width: 12rem; max-width: 100%; background: #fff; }
.fields dd .prop-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.order-row { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; font-size: .85rem; flex-wrap: wrap; }
.order-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.order-link:hover { text-decoration: underline; }

.picker { margin-top: .5rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; background: #faf8f4; }
.picker-input { width: 100%; box-sizing: border-box; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.picker-results { margin-top: .4rem; display: flex; flex-direction: column; gap: .2rem; max-height: 220px; overflow: auto; }
.picker-item { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: .35rem .5rem; cursor: pointer; font: inherit; font-size: .84rem; }
.picker-item:hover { border-color: var(--accent); background: #fff7ef; }

.card-foot { display: flex; align-items: center; gap: .8rem; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.btn-save { background: #fff; color: var(--accent); border: 1px solid var(--accent); border-radius: 7px; padding: .45rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; }
.btn-save:disabled { opacity: .6; cursor: default; }
.btn-apply { background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: .45rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; }
.btn-apply:disabled { opacity: .55; cursor: default; }
.save-note { color: var(--muted); font-size: .82rem; }

.apply-results { margin-top: .8rem; border-top: 1px dashed var(--line); padding-top: .7rem; }
.apply-head { font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
.apply-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: baseline; padding: .25rem 0; font-size: .82rem; }
.apply-item { font-weight: 600; min-width: 180px; }
.apply-op { background: #f0ede7; color: var(--muted); padding: .1rem .5rem; border-radius: 999px; font-size: .76rem; }
