:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #14202b;
  --muted: #667480;
  --line: #dfe5ea;
  --navy: #122b43;
  --blue: #1f5c8c;
  --green: #1db777;
  --green-dark: #11875a;
  --amber: #f2a31b;
  --red: #d64045;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { touch-action: manipulation; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
.hidden { display: none !important; }

.offline { position: sticky; top: 0; z-index: 100; padding: 10px 16px; text-align: center; color: #fff; background: var(--red); font-weight: 700; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(145deg, #0d1c2a, #173a58); }
.login-card { width: min(420px, 100%); padding: 30px; border-radius: 24px; background: #fff; box-shadow: 0 24px 70px #06121e66; }
.brand { font-size: 20px; letter-spacing: .09em; font-weight: 900; color: #fff; white-space: nowrap; }
.login-card .brand { color: var(--navy); }
.brand span { color: var(--green); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 22px 0; font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 17px; }
label { display: grid; gap: 7px; margin: 14px 0; color: var(--muted); font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fff; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid #1db77726; border-color: var(--green); }

.app { min-height: 100vh; }
.topbar { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px max(16px, calc((100vw - 1280px)/2)); background: var(--navy); color: #fff; }
.topbar-user { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.tabs { display: flex; gap: 8px; padding: 10px max(16px, calc((100vw - 1280px)/2)); overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); }
.tabs button { padding: 10px 14px; border: 0; border-radius: 999px; background: transparent; white-space: nowrap; font-weight: 800; color: var(--muted); }
.tabs button.active { color: #fff; background: var(--blue); }
.content { width: min(1280px, 100%); margin: 0 auto; padding: 22px 16px 60px; }

button { min-height: 42px; padding: 9px 15px; border-radius: 12px; border: 1px solid transparent; font-weight: 800; }
.primary { color: #fff; background: var(--green); }
.primary:hover { background: var(--green-dark); }
.secondary { color: #fff; background: var(--blue); }
.ghost { color: inherit; background: transparent; border-color: #ffffff44; }
.ghost.dark { color: var(--navy); border-color: var(--line); background: #fff; }
.danger { color: #fff; background: var(--red); }
.warning { color: #5b3b00; background: #ffe2a8; }
.wide { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.error { min-height: 20px; color: var(--red); font-weight: 700; }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(6, minmax(135px, 1fr)); gap: 12px; margin: 18px 0; }
.card { padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 24px #162b3b0a; }
.metric span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric strong { display: block; margin-top: 8px; font-size: 30px; }
.section { margin-top: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2, .section-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.forecast { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; align-items: center; }
.forecast div { display: grid; gap: 4px; }
.forecast span, .forecast small { color: var(--muted); font-size: 12px; font-weight: 700; }
.forecast strong { font-size: 21px; }
.workforce-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.worker { padding: 7px 10px; border-radius: 999px; background: #edf2f5; color: var(--muted); font-size: 13px; font-weight: 800; }
.worker.ready { color: var(--green-dark); background: #dff8ec; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); background: #f8fafb; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover { background: #f5fbf8; }
.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 900; background: #edf2f5; }
.status.PICKING { color: #8a5400; background: #fff0c9; }
.status.PICKED { color: #174b74; background: #dcefff; }
.status.WAITING_PACKING { color: #6c3f8c; background: #f0e2fb; }
.status.READY { color: #08734a; background: #d8f7e9; }

.queue { display: grid; gap: 10px; }
.order-mini { display: grid; grid-template-columns: minmax(0, 1.3fr) 1fr auto; gap: 12px; align-items: center; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.order-mini strong { display: block; }
.order-mini small { color: var(--muted); }
.order-progress { margin-top: 10px; }
.order-progress-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; color: var(--navy); font-size: 12px; }
.order-progress-head strong { display: inline; }
.order-progress .progress-track { height: 8px; margin-bottom: 5px; }
.order-progress small b { color: #8a5400; }
.order-progress.detailed { margin: 16px 0 20px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafb; }
.order-progress.detailed .progress-track { height: 12px; }
.hero-order { padding: 22px; color: #fff; background: linear-gradient(145deg, #13324c, #1f5c8c); border-radius: 22px; }
.hero-order h1 { margin: 5px 0 8px; }
.hero-order .facts { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-order .facts span { padding: 7px 10px; border-radius: 999px; background: #ffffff18; font-weight: 800; }
.items { display: grid; gap: 8px; margin: 16px 0; }
.item-group { margin: 14px 0 2px; padding: 8px 2px 4px; color: var(--navy); }
.item-group span { margin-left: 6px; color: var(--muted); font-size: 13px; }
.item { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 13px 14px; background: #fff; border: 1px solid var(--line); border-radius: 13px; }
.pick-item { touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; transition: background .16s, border-color .16s, transform .08s; }
.pick-item:active { transform: scale(.995); }
.pick-item.picked { background: #dff8ec; border-color: #81d9b4; }
.pick-item.short { background: #fff0cf; border-color: #efbf59; }
.pick-item.picked .qty { color: #fff; background: var(--green); }
.pick-item.short .qty { color: #724900; background: #ffd67d; }
.inspection-item.picked { background: #dff8ec; border-color: #81d9b4; }
.inspection-item.short { background: #fff0cf; border-color: #efbf59; }
.inspection-item.inspection-pending { background: #f5f7f9; color: #657381; }
.inspection-item.picked .qty { color: #fff; background: var(--green); }
.inspection-item.short .qty { color: #724900; background: #ffd67d; }
.inspection-item.inspection-pending .qty { color: var(--muted); background: #e5eaee; }
.inspection-state { margin-top: 4px; font-size: 13px; font-weight: 900; }
.inspection-item.picked .inspection-state { color: var(--green-dark); }
.inspection-item.short .inspection-state { color: #885800; }
.inspection-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.inspection-legend span { padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 900; }
.legend-picked { color: var(--green-dark); background: #dff8ec; }
.legend-short { color: #885800; background: #fff0cf; }
.legend-pending { color: var(--muted); background: #e5eaee; }
.stock-live { margin-top: 4px; color: var(--blue); font-size: 13px; }
.short-note { margin-top: 4px; color: #885800; font-size: 13px; font-weight: 900; }
.item .position { color: var(--muted); font-weight: 800; }
.item .qty { min-width: 54px; padding: 7px 9px; border-radius: 9px; text-align: center; font-size: 18px; font-weight: 900; background: #e3f8ee; color: var(--green-dark); }
.event { display: grid; grid-template-columns: 150px 190px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.event-product { display: block; margin-bottom: 3px; }
.history-tabs { display: flex; gap: 8px; margin-top: 24px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.history-tab { color: var(--muted); background: #edf2f5; }
.history-tab.active { color: #fff; background: var(--blue); }
.history-tab span { display: inline-block; margin-left: 4px; padding: 2px 6px; border-radius: 999px; color: inherit; background: #ffffff25; font-size: 11px; }
.history-panel { padding-top: 4px; }
.picker-progress { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: auto minmax(120px, 1fr); gap: 14px; align-items: center; margin-top: 12px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fffffff2; backdrop-filter: blur(10px); }
.picker-progress strong, .picker-progress span { display: block; }
.picker-progress span { color: var(--muted); font-size: 12px; }
.progress-track { height: 10px; overflow: hidden; border-radius: 99px; background: #e5eaee; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: var(--green); transition: width .2s; }
.gesture-help { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.picker-empty { width: min(620px, 100%); margin: 7vh auto 0; text-align: center; }
.picker-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.shift-pill, .eyebrow { display: inline-block; margin-bottom: 10px; padding: 7px 10px; border-radius: 999px; color: var(--green-dark); background: #dff8ec; font-weight: 900; }
.mobile-action { min-height: 56px; font-size: 18px; }

dialog { width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 30px); overflow: auto; padding: 0; border: 0; border-radius: 20px; box-shadow: 0 30px 100px #0007; }
dialog::backdrop { background: #0b1722aa; }
#dialog-body { padding: 22px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 200; max-width: 440px; padding: 14px 18px; border-radius: 12px; color: #fff; background: var(--navy); box-shadow: 0 15px 40px #0004; font-weight: 800; }

@media (max-width: 920px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .forecast { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .topbar-user #user-name { display: none; }
  .content { padding-top: 14px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 14px; }
  .order-mini { grid-template-columns: 1fr; }
  .event { grid-template-columns: 1fr; gap: 3px; }
  .item { grid-template-columns: 34px minmax(0, 1fr) auto; padding: 12px 10px; }
  .content { padding-left: 10px; padding-right: 10px; }
  .hero-order { padding: 17px; border-radius: 17px; }
  .hero-order h1 { font-size: 24px; }
  .section-head { align-items: flex-start; }
  .section-head #print-order { display: none; }
  .picker-actions { grid-template-columns: 1fr; }
  .pick-item { min-height: 78px; }
  .forecast { grid-template-columns: 1fr 1fr; }
}

@media print {
  .topbar, .tabs, .button-row, .offline { display: none !important; }
  body, .content { background: #fff; padding: 0; }
  .hero-order { color: #000; background: #fff; border: 2px solid #000; }
  .hero-order .facts span { background: #eee; }
  .item { break-inside: avoid; border-color: #555; }
}
