:root {
  --bg: #f6f4f1; --panel: #ffffff; --ink: #1d1b19; --muted: #7a736b; --line: #e7e2db;
  --brand: #2b2622; --accent: #9a7b4f; --accent-soft: #f3ece1;
  --ok: #2f7d4f; --ok-soft: #e5f3ea; --warn: #b26a00; --warn-soft: #fdf1dc;
  --bad: #b3261e; --bad-soft: #fbe7e5; --info-soft: #e9eef6;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Be Vietnam Pro", system-ui, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 18px; font-size: 13px; }
h1 { font-size: 22px; margin: 0; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
a { color: var(--accent); }

/* boot & login */
.boot, .login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.boot-box, .login-box { background: var(--panel); padding: 32px; border-radius: 14px; box-shadow: var(--shadow); width: 340px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.login-box h2 { margin: 0; }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.brand-mark { width: 44px; height: 44px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; margin: 0 auto; letter-spacing: 1px; }
.brand-mark.sm { width: 34px; height: 34px; font-size: 16px; margin: 0; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #e9e4dd; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand .brand-mark { background: var(--accent); }
.brand small { display: block; color: #a89f94; font-size: 11px; }
#nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; }
#nav a { padding: 9px 12px; border-radius: 8px; color: #d8d1c7; text-decoration: none; cursor: pointer; font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.06); }
#nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.side-foot { padding: 12px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .btn.ghost { color: #d8d1c7; border-color: rgba(255,255,255,.15); }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; text-align: center; font-weight: 600; }
.badge.local { background: var(--warn-soft); color: var(--warn); }
.badge.cloud { background: var(--ok-soft); color: var(--ok); }
main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi .lbl { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.bad .val { color: var(--bad); }
.kpi.warn .val { color: var(--warn); }
.split { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.two { grid-template-columns: 1fr 1fr; }

/* buttons & inputs */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfc7bc; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly] { background: #f7f5f2; color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.check input { width: auto; }

/* tables */
.dt-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.dt-tools input[type=search] { max-width: 320px; }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #faf8f5; font-size: 12px; font-weight: 600; color: var(--muted); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.c, th.c { text-align: center; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fcfbf9; }
tr.sel { background: var(--accent-soft) !important; }
tr.clickable { cursor: pointer; }
td.nowrap { white-space: nowrap; }
td input, td select { padding: 5px 8px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); gap: 8px; }
.pager .btns { display: flex; gap: 4px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.code { white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill.draft { background: #eee; color: #555; }
.pill.confirmed { background: var(--info-soft); color: #2c4f86; }
.pill.in_progress { background: var(--warn-soft); color: var(--warn); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.cancelled { background: var(--bad-soft); color: var(--bad); }
.pill.short { background: var(--bad-soft); color: var(--bad); }
.pill.enough { background: var(--ok-soft); color: var(--ok); }
.neg { color: var(--bad); font-weight: 600; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.alert.warn { background: var(--warn-soft); color: #7a4a00; }
.alert.bad { background: var(--bad-soft); color: #7d1a14; }
.alert.info { background: var(--info-soft); color: #23406b; }
.alert.ok { background: var(--ok-soft); color: #1e5434; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,16,12,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: min(620px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1080px, 100%); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-h h2 { margin: 0; }
.modal-b { padding: 18px 20px; overflow: auto; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 380px; animation: tin .2s; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

.busy { position: fixed; inset: 0; background: rgba(255,255,255,.6); display: grid; place-items: center; z-index: 300; font-weight: 600; }

.order-pick { max-height: 280px; overflow: auto; }
.opts { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.stepper { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stepper .card { padding: 14px; }
.stepper .n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-bottom: 8px; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; min-width: 0; }
  .page-head > div, .dt-tools input[type=search] { min-width: 0; max-width: 100%; }
  #nav { flex-direction: row; overflow-x: auto; padding: 6px; }
  #nav a { white-space: nowrap; }
  .brand { display: none; }
  .side-foot { flex-direction: row; padding: 6px 8px; }
  main { padding: 16px; }
  .split, .two, .stepper { grid-template-columns: 1fr; }
}
