:root {
  /* bpd portal identity kit */
  --accent: #F16522;
  --accent-dark: #d1531a;
  --ink: #231F20;
  --bg: #f4f3f1;
  --surface: #ffffff;
  --panel-tint: #fbfaf9;
  --text: #231F20;
  --muted: #78736f;
  --border: #e6e3df;
  --border-light: #efece8;
  --danger: #c0392b;
  --warn: #b8860b;
  --ok: #1f7a3f;
  --packed-bg: #fdf3d8;
  --despatched-bg: #e3f3e8;
  --cancelled-bg: #fbe3e0;
  --dropped-bg: #ecebe8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Poppins', "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Top bar ─────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border-light); }
.topbar-inner {
  max-width: 1300px; margin: 0 auto; padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 1rem;
}
.brand { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 1.4rem; display: flex; align-items: baseline; gap: 0.6rem; }
.brand-sub { font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.lockup { display: inline-flex; align-items: center; gap: 0.32em; line-height: 1; }
.lockup-bpd { font-weight: 700; letter-spacing: -0.05em; }
.lockup-rule { width: 0.09em; height: 0.78em; background: var(--accent); transform: skewX(-14deg); }
.lockup-portal { font-weight: 300; letter-spacing: -0.02em; }
.topbar nav { flex: 1; }
.topbar nav a {
  color: #57534f; font-size: 0.92rem; text-decoration: none; margin-left: 1.25rem;
  padding: 0.35rem 0 0.25rem; border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--ink); font-weight: 500; border-bottom-color: var(--accent); }
.user-chip { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.user-chip .user-name { font-size: .85rem; white-space: nowrap; color: var(--ink); text-decoration: none; }
.user-chip form { margin: 0; }
.btn-signout { background: none; border: 1px solid var(--border); color: var(--ink); border-radius: 4px; padding: .25rem .6rem; font-size: .8rem; cursor: pointer; }
.btn-signout:hover { border-color: var(--ink); }
.banner-flash { background: #fdeee6; color: #b34a16; border-bottom: 1px solid #f6d3bf; padding: .5rem 1.25rem; text-align: center; font-size: .9rem; }

/* ── Layout ──────────────────────────────── */
.container { max-width: 1300px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; margin: 0.25rem 0 0.75rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.mono { font-family: 'JetBrains Mono', Consolas, monospace; font-size: 0.9em; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }
.form-error { color: var(--danger); font-size: 0.9rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.panel h2 { margin-top: 0; }

/* ── Buttons & forms ─────────────────────── */
.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none; border-radius: 4px;
  padding: 0.45rem 1rem; font-size: 0.95rem; font-family: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-ghost { background: transparent; color: var(--accent-dark); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: 0.2rem 0.6rem; font-size: 0.82rem; }
.btn-pack { background: var(--ink); }
.btn-pack:hover { background: #000; }
.btn-primary { margin-top: .5rem; width: 100%; padding: .6rem; border: none; border-radius: 6px; background: var(--accent-dark); color: #fff; font-size: .95rem; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn-primary:hover { background: var(--accent); }
.row-actions { display: flex; gap: 0.4rem; align-items: center; }
.row-actions form { margin: 0; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0; }
input[type="text"], input[type="email"], input[type="search"], input[type="date"], input[type="password"], select {
  padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; font-family: inherit; background: var(--surface);
}

/* ── Stats & filters ─────────────────────── */
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.stat-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.9rem; display: flex; align-items: baseline; gap: 0.5rem; }
.stat-num { font-size: 1.3rem; font-weight: 600; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-warn .stat-num { color: var(--danger); }
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 0.6rem 0.9rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 1rem; margin: 0.75rem 0 1.25rem;
  font-size: 0.9rem;
}
.filter-bar label { display: flex; align-items: center; gap: 0.4rem; }
.filter-search { min-width: 260px; flex: 1; }
.quick-links { display: flex; gap: 0.3rem; }
.check { color: var(--muted); }

/* ── Job cards & line grid ───────────────── */
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; overflow: hidden; }
.job-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem; padding: 0.7rem 1rem; background: var(--panel-tint); border-bottom: 1px solid var(--border-light); }
.job-title { display: flex; align-items: baseline; gap: 0.75rem; min-width: 320px; }
.elem-code { font-size: 1.05rem; font-weight: 600; color: var(--ink); text-decoration: none; }
a.elem-code:hover { color: var(--accent-dark); }
.elem-desc { font-weight: 500; }
.job-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; font-size: 0.82rem; flex: 1; }
.job-progress { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.82rem; }
.progress-text { font-weight: 600; }
.job-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 1rem; font-size: 0.85rem; margin: 0.5rem 0 0; flex-basis: 100%; }
.job-facts dt { color: var(--muted); }
.job-facts dd { margin: 0; }

.lines-table, .changes-table, .batches-table, .users-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.lines-table th, .changes-table th, .batches-table th, .users-table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.45rem 0.9rem; border-bottom: 1px solid var(--border);
}
.lines-table td, .changes-table td, .batches-table td, .users-table td { padding: 0.45rem 0.9rem; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.lines-table tr:last-child td { border-bottom: none; }
.col-qty { text-align: right; font-variant-numeric: tabular-nums; }
.col-actions { text-align: right; white-space: nowrap; }
.col-actions .btn { margin-left: 0.3rem; }
.col-location .depot { font-weight: 600; display: block; }
.col-location .small { display: block; line-height: 1.2; }
.col-status .badge { margin-right: 0.3rem; }

.line-row.state-packed { background: var(--packed-bg); }
.line-row.state-despatched { background: var(--despatched-bg); color: #3b5a45; }
.line-row.is-dropped { background: var(--dropped-bg); color: var(--muted); }
.line-row.is-complete { background: var(--dropped-bg); color: var(--muted); }
.line-row.is-cancelled { background: var(--cancelled-bg); }
.line-row.is-cancelled .depot, .line-row.is-cancelled .col-qty { text-decoration: line-through; color: var(--danger); }
.line-row.just-changed td { animation: flash 1.4s ease-out; }
@keyframes flash { from { box-shadow: inset 0 0 0 100px rgba(241, 101, 34, 0.25); } to { box-shadow: none; } }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge-open { background: #edece7; color: #6b6a64; }
.badge-packed { background: #f7e3a8; color: #7a5a06; }
.badge-despatched { background: #cdebd7; color: var(--ok); }
.badge-cancelled { background: var(--danger); color: #fff; }
.badge-dropped { background: #c9c6c0; color: #3b3835; }
.badge-delta { background: #dceafb; color: #1d5aa0; }

/* ── Timeline ────────────────────────────── */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 1rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border-light); font-size: 0.9rem; flex-wrap: wrap; }
.tl-when { color: var(--muted); min-width: 130px; }
.tl-depot { font-weight: 600; min-width: 110px; }
.timeline .tl-cancelled .tl-text { color: var(--danger); font-weight: 600; }
.timeline .tl-dropped .tl-text { color: var(--muted); }

/* ── Dropzone & upload results ───────────── */
.dropzone {
  margin-top: 1rem; border: 2px dashed var(--border); border-radius: 8px; background: var(--surface);
  padding: 2.5rem 2rem; text-align: center; color: var(--muted); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover { border-color: var(--accent); background: #fdeee4; outline: none; }
.dropzone-inner p { margin: 0.5rem 0 0; }
.upload-results { list-style: none; padding: 0; margin-top: 1rem; }
.upload-result { display: flex; justify-content: space-between; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 1rem; margin-bottom: 0.5rem; font-size: 0.9rem; }
.upload-result .result-name { font-weight: 600; }
.upload-result.pending .result-status { color: var(--warn); }
.upload-result.success { border-left: 4px solid var(--ok); }
.upload-result.failed { border-left: 4px solid var(--danger); }
.upload-result.failed .result-status { color: var(--danger); }
.batches-table .batch-failed td { color: var(--muted); }
.users-table .user-inactive td { color: var(--muted); }

/* ── Modal ───────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(35, 31, 32, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal { background: var(--surface); border-radius: 10px; width: min(1000px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-head p { margin: 0.25rem 0 0; }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1rem 1.25rem; overflow: auto; }
.change-group { margin-bottom: 1.25rem; }
.change-group h3 { font-size: 0.95rem; margin: 0 0 0.4rem; display: flex; align-items: center; gap: 0.5rem; }
.change-group .count { background: var(--border); border-radius: 999px; padding: 0 0.5rem; font-size: 0.78rem; }
.change-cancelled h3 { color: var(--danger); }
.change-cancelled table tr { background: var(--cancelled-bg); }
.change-dropped h3 { color: var(--muted); }
.change-dropped table tr { background: var(--dropped-bg); }
.change-new h3 { color: var(--ok); }

/* ── Login screens ───────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); margin: 0; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 2rem 2.25rem; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .75rem; }
.login-card h1 { margin: 0; font-size: 1.3rem; }
.login-card label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.login-card input[type="email"], .login-card input[type="password"] { width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 6px; font-size: .95rem; }
.login-error { color: var(--danger); font-size: .9rem; margin: 0; }
.login-flash { color: var(--muted); font-size: .9rem; margin: 0; }
.login-lockup-sm { font-size: 1.5rem; color: var(--ink); margin-bottom: 0.75rem; }

.login-dark {
  min-height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse 900px 600px at 50% 45%, #3a3436 0%, #2c2728 45%, #231F20 100%); color: #fff;
}
.login-stage-wrap { display: flex; flex-direction: column; align-items: center; gap: 40px; padding: 2rem; }
.login-stage { display: flex; align-items: center; gap: 44px; flex-wrap: wrap; justify-content: center; }
.login-stage-lockup { font-size: 3.4rem; color: #fff; }
.login-divider { width: 1px; height: 96px; background: rgba(255,255,255,0.18); }
.login-label { font-size: 1.6rem; font-weight: 300; color: rgba(255,255,255,0.85); }
.login-dark-form { display: flex; flex-direction: column; gap: 12px; position: relative; width: 340px; }
.login-dark-form input[type="email"], .login-dark-form input[type="password"] {
  width: 100%; padding: 13px 58px 13px 16px; border: 1px solid #3d3839; border-radius: 6px; background: #2e2a2b; color: #fff; font-family: inherit; font-size: 15px;
}
.login-dark-form input::placeholder { color: #8d8a87; }
.login-dark-form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login-go { position: absolute; right: -26px; top: 44px; width: 58px; height: 58px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 22px rgba(241, 101, 34, 0.45); }
.login-go:hover { background: var(--accent-dark); }
.login-remember-dark { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 300; color: rgba(255,255,255,0.75); }
.login-forgot-dark { margin: 0; font-size: 14.5px; font-weight: 300; color: rgba(255,255,255,0.85); }
.login-forgot-dark a { color: var(--accent); text-decoration: none; font-weight: 500; }
.login-note { color: rgba(255,255,255,0.8); font-size: 14px; }
.login-note-error { color: #ff8a70; font-weight: 500; }
.login-tagline { margin: 0; font-size: 1.05rem; font-weight: 300; color: rgba(255,255,255,0.7); text-align: center; }
.login-foot { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255,255,255,0.35); }

@media (max-width: 760px) {
  .login-divider { display: none; }
  .login-stage { flex-direction: column; gap: 24px; }
  .login-go { right: 8px; }
  .job-title { min-width: 0; }
  .col-wo { display: none; }
}

/* ── Overview gauges ─────────────────────── */
.gauge-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.gauge {
  margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.6rem 0.5rem 0.7rem; display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  transition: background 0.3s, border-color 0.3s;
}
.gauge-today { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(241, 101, 34, 0.18); }
.gauge-done { background: var(--despatched-bg); border-color: #9ed3b0; }
.gauge-packed { background: var(--packed-bg); }
.gauge-empty { opacity: 0.6; }
.gauge-day { display: flex; gap: 0.4rem; align-items: baseline; }
.gauge-dow { font-weight: 600; }
.gauge-date { font-size: 0.8rem; color: var(--muted); }
.gauge svg path { fill: none; stroke-width: 12; stroke-linecap: butt; }
.gauge-track { stroke: var(--border); }
.gauge-packed { stroke: #f0b429; }
.gauge-despatched { stroke: var(--ok); }
.gauge-done .gauge-track { stroke: #cfe9d8; }
.gauge-num { font-family: 'Poppins', sans-serif; font-size: 22px; font-weight: 600; fill: var(--text); }
.gauge-of { font-size: 13px; font-weight: 400; fill: var(--muted); }
.gauge-legend { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.78rem; color: var(--muted); align-self: stretch; padding: 0 0.5rem; }
.gauge-key { display: flex; align-items: center; gap: 0.4rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.swatch-packed { background: #f0b429; }
.swatch-despatched { background: var(--ok); }
.swatch-open { background: var(--border); }
