:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-2: #FBFBFA;
  --line: #EAEAEA;
  --text: #2F3437;
  --strong: #111111;
  --muted: #787774;
  --red-bg: #FDEBEC; --red: #9F2F2D;
  --blue-bg: #E1F3FE; --blue: #1F6C9F;
  --green-bg: #EDF3EC; --green: #346538;
  --yellow-bg: #FBF3DB; --yellow: #956400;
  --sans: 'Geist', 'SF Pro Display', 'Helvetica Neue', sans-serif;
  --serif: 'Instrument Serif', 'Newsreader', Georgia, serif;
  --mono: 'Geist Mono', 'SF Mono', 'JetBrains Mono', Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.serif { font-family: var(--serif); font-weight: 400; letter-spacing: -0.02em; line-height: 1.1; color: var(--strong); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus { border-color: #BDBCB8; }
label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }

.btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 16px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--strong); border-color: var(--strong); color: #fff; }
.btn.primary:hover { background: #333; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.link { border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--strong); }
.error { color: var(--red); background: var(--red-bg); border-radius: 6px; padding: 8px 12px; margin: 0; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(800px 400px at 50% 0%, rgba(149,100,0,.035), transparent); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 40px; display: grid; gap: 16px; animation: rise .6s var(--ease); }
.login-card h1 { font-size: 40px; margin: 0; }
.login-card p { margin: 0; }
.seg { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg legend { padding: 0; margin-bottom: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.seg label { display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; font-size: 14px; color: var(--text); background: var(--surface); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-weight: 500; }
.seg input:checked + span { color: var(--strong); border-color: var(--strong); box-shadow: inset 0 0 0 1px var(--strong); }
.seg input:focus-visible + span { outline: 2px solid var(--strong); outline-offset: 2px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(247,246,243,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 32px; height: 60px; }
.brand { font-size: 24px; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab:hover { color: var(--strong); }
.tab.active { color: var(--strong); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.user { margin-left: auto; display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 13px; }

main.wrap { padding-top: 40px; padding-bottom: 140px; }
section { animation: rise .6s var(--ease); }

/* Direction switch */
.direction { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
.dir {
  text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 20px 24px; cursor: pointer; display: grid; gap: 4px; transition: box-shadow .2s, border-color .2s;
}
.dir:hover { box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.dir.active { border-color: var(--strong); box-shadow: inset 0 0 0 1px var(--strong); }
.dir-route { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 26px; color: var(--strong); line-height: 1.2; }
.dir-route svg { flex: none; color: var(--muted); }
.dir-loc { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.eyebrow { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 500; }

/* Stats */
.stats { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; animation: rise .6s var(--ease) both; animation-delay: calc(var(--i) * 80ms); }
.stat .value { font-family: var(--serif); font-size: 34px; color: var(--strong); line-height: 1.1; margin-top: 6px; }
.stat .sub { color: var(--muted); font-size: 12px; }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.toolbar input { max-width: 360px; }
.chips { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 9999px; padding: 5px 12px; cursor: pointer; font-size: 12px; color: var(--muted); }
.chip.active { background: var(--strong); border-color: var(--strong); color: #fff; }
.toolbar .btn { margin-left: auto; }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; }
.grid td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
th.num { font-family: var(--sans); }
.code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.item-name { color: var(--strong); font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px !important; }
.qty-col { width: 140px; }
.qty { width: 110px; text-align: right; font-family: var(--mono); padding: 6px 10px; }
.qty.over { border-color: var(--red); background: var(--red-bg); }
.map-cell { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.map-target { display: grid; line-height: 1.35; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
tr.expand td { background: var(--surface-2); padding: 0 16px 16px; }
tr.clickable { cursor: pointer; }
.sub-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sub-table td, .sub-table th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.sub-table th { font-size: 11px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }

/* Badges */
.badge { display: inline-block; border-radius: 9999px; padding: 2px 9px; font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }

/* Sticky cart */
.cart { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-top: 1px solid var(--line); animation: up .4s var(--ease); }
.cart-inner { display: flex; gap: 12px; align-items: center; padding-top: 14px; padding-bottom: 14px; }
.cart-sum { white-space: nowrap; color: var(--muted); }
.cart-sum strong { color: var(--strong); }
.dot { display: inline-block; width: 3px; height: 3px; border-radius: 50%; background: var(--muted); vertical-align: middle; margin: 0 6px; }
.cart input { flex: 1; }

.section-head { display: flex; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 36px; margin: 0; }
.lead { margin: -4px 0 20px; max-width: 720px; }
.nowrap { white-space: nowrap; }
.new-map { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; margin-bottom: 24px; display: grid; gap: 14px; }
.new-map-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: start; }
.pick-arrow { font-size: 22px; color: var(--muted); padding-top: 30px; }
.pick { display: grid; gap: 8px; min-width: 0; }
.picked { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--strong); border-radius: 8px; padding: 10px 14px; }
.pick .results .badge { margin-left: 8px; }
.new-map-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.new-map-actions .error { margin: 0 auto 0 0; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(17,17,17,.25); }
dialog[open] { animation: rise .35s var(--ease); }
.dlg { padding: 28px; display: grid; gap: 14px; }
.dlg h3 { font-size: 28px; margin: 0; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.results { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 320px; overflow: auto; }
.results li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.results li:last-child { border-bottom: 0; }
.results li.none { color: var(--muted); justify-content: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }

.toast { position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%); background: var(--strong); color: #fff; padding: 10px 18px; border-radius: 6px; font-size: 13px; z-index: 20; animation: rise .3s var(--ease); max-width: 90vw; }
.toast.bad { background: var(--red); }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }

@media (max-width: 800px) {
  .wrap { padding: 0 16px; }
  .topbar-inner { gap: 12px; }
  .brand { font-size: 20px; }
  .user span { display: none; }
  .direction, .stats, .form-grid, .new-map-grid { grid-template-columns: 1fr; }
  .pick-arrow { display: none; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { max-width: none; }
  .cart-inner { flex-wrap: wrap; }
  .cart input { flex-basis: 100%; order: 3; }
}

/* ---- company transfer v2 ---- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 22px; width: auto; display: block; }
.login-logo { height: 34px; width: auto; justify-self: start; }
.dir { cursor: default; }
.who { display: inline-block; min-width: 68px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.people { font-size: 12.5px; line-height: 1.5; }
.people .code { margin-left: 4px; }
.req-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
dialog.wide { width: min(920px, calc(100vw - 32px)); }
dialog.wide .sub-table { width: 100%; }
dialog.wide .qty { width: 96px; text-align: right; }
td.error { color: var(--red); }
.check-sum { font-weight: 600; color: var(--green); }
.check-sum.error { color: var(--red); }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 50vh; overflow: auto; font-size: 13px; }
.check-list .badge { margin-right: 6px; }
.report-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.report-filters label { width: auto; min-width: 140px; }
#view-report h3 { font-size: 22px; margin: 28px 0 10px; }

@media print {
  .topbar, .no-print, .cart, .toast, .tabs { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .table-wrap { border: 0; overflow: visible; }
  .stat { break-inside: avoid; }
  tr { break-inside: avoid; }
}
