:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #667085; --line: #e3e6eb;
  --brand: #1f4e79; --brand-dark: #173b5c;
  --red: #b42318; --red-bg: #fef3f2; --amber: #b54708; --amber-bg: #fffaeb;
  --green: #067647; --green-bg: #ecfdf3; --blue: #175cd3; --blue-bg: #eff8ff; --grey-bg: #f2f4f7;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); font-size: .9em; }

/* Top bar */
.topbar { background: var(--brand); color: #fff; }
.topbar .inner { max-width: 1150px; margin: auto; padding: .6rem 1rem; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1.2rem; }
.topbar .brand { font-weight: 700; margin-right: auto; color: #fff; text-decoration: none; }
.topbar a, .topbar button { color: #dbe7f3; text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.topbar a:hover, .topbar button:hover, .topbar a.active { color: #fff; }
.topbar form { display: inline; }

main { max-width: 1150px; margin: auto; padding: 1.2rem 1rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Buttons */
.btn { display: inline-block; background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: .5rem 1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--brand-dark); }
.btn.light { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.btn.small { padding: .25rem .65rem; font-size: .85rem; }

/* Cards & tiles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 10px; padding: .8rem 1rem; text-decoration: none; color: inherit; }
.tile .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.tile.red { border-left-color: var(--red); } .tile.red .num { color: var(--red); }
.tile.amber { border-left-color: var(--amber); } .tile.amber .num { color: var(--amber); }
.tile.blue { border-left-color: var(--blue); } .tile.blue .num { color: var(--blue); }
.tile.green { border-left-color: var(--green); } .tile.green .num { color: var(--green); }
.section-title.red { color: var(--red); } .section-title.amber { color: var(--amber); }

/* Tables (scroll sideways on phones) */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fafbfc; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.nowrap { white-space: nowrap; }
.empty { padding: 1rem; color: var(--muted); }

/* Status badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--grey-bg); }
.badge.PENDING { background: var(--amber-bg); color: var(--amber); }
.badge.ARRANGED { background: var(--blue-bg); color: var(--blue); }
.badge.DISPATCHED { background: #f4f3ff; color: #5925dc; }
.badge.DELIVERED { background: var(--green-bg); color: var(--green); }
.badge.overdue { background: var(--red-bg); color: var(--red); }
.restrict { display: inline-block; background: var(--red-bg); color: var(--red); border-radius: 6px; padding: .05rem .45rem; font-size: .82rem; font-weight: 600; }

/* Forms */
form.stack > div { margin-bottom: .9rem; }
form.stack label { display: block; font-weight: 600; margin-bottom: .25rem; }
input:not([type=checkbox]):not([type=radio]), select, textarea { width: 100%; max-width: 520px; padding: .5rem .6rem; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; background: #fff; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; }
.helptext { display: block; color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.errorlist { color: var(--red); margin: .2rem 0; padding-left: 1.1rem; font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; }

/* Messages */
.msg { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--green-bg); color: var(--green); font-weight: 600; }
.msg.error { background: var(--red-bg); color: var(--red); }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; white-space: pre-line; }

.login-box { max-width: 380px; margin: 4rem auto; }

/* Phones: delivery tables become stacked cards so nothing hides off-screen */
@media (max-width: 700px) {
  table.cards thead { display: none; }
  table.cards tr { display: block; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  table.cards tr:last-child { border-bottom: 0; }
  table.cards td { display: grid; grid-template-columns: 6.8rem 1fr; gap: .5rem; border: 0; padding: .2rem .9rem; white-space: normal; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; text-transform: uppercase; padding-top: .15rem; }
  table.cards td.action { display: block; padding-top: .4rem; }
  table.cards td.action::before { content: none; }
}

/* Order flow */
.badge.LOADING { background: #fdf2fa; color: #c11574; }
.chip { display: inline-block; background: var(--amber-bg); color: var(--amber); border-radius: 6px; padding: 0 .4rem; margin: .1rem .15rem 0 0; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.waiting { margin: .6rem 0 0; }
.steps { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .7rem; }
.step { font-size: .78rem; padding: .2rem .6rem; border-radius: 999px; background: var(--grey-bg); color: var(--muted); }
.step.done { background: var(--green-bg); color: var(--green); }
.step.done::before { content: "✓ "; }
.step.current { background: var(--brand); color: #fff; font-weight: 600; }
.msgbox { white-space: pre-wrap; font: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .7rem; margin: .5rem 0; }
.factory { border-left: 5px solid var(--green); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .45rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
details.card summary { cursor: pointer; }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: .7rem 0; border-top: 1px solid var(--line); }
input[type=checkbox] + .helptext, .stack div > input[type=checkbox] { vertical-align: middle; }

/* Watch-word alerts and phone boxes */
.alert-box { background: var(--red-bg); color: var(--red); border: 1px solid #f5c2bd; border-left: 5px solid var(--red); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
.alert-box p, .alert-box li { color: var(--text); }
.alert-box ul { margin: .2rem 0 .5rem; }
.phone-list { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; max-width: 520px; }
.phone-list .phone-box { width: 11rem; }

/* Payments */
.promise-box { background: var(--amber-bg); color: var(--amber); border: 1px solid #f7d9a4; border-left: 5px solid var(--amber); border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; }
.promise-box .muted { color: var(--muted); }
dialog.popup { position: fixed; top: 4.5rem; left: 50%; transform: translateX(-50%); margin: 0; z-index: 10; width: min(92vw, 420px);
  border: 1px solid var(--line); border-top: 5px solid var(--amber); border-radius: 10px; padding: 1rem 1.2rem; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog.popup p { margin: .5rem 0; }
.tile .num.small { font-size: 1.2rem; }
.badge.wrap { white-space: normal; }
.badge.wrap { border-radius: 8px; }

/* Freight quotes on the truck page */
.quotes { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; background: var(--bg); }
.quotes h3 { margin: 0 0 .4rem; font-size: 1rem; }
tr.dim td { opacity: .55; }
.quote-add { border-top: 1px dashed var(--line); padding-top: .7rem; }
.quote-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .5rem .8rem; margin: .5rem 0 .6rem; }
.quote-grid label { font-weight: 600; font-size: .85rem; display: block; margin-bottom: .15rem; }

/* Inventory */
.subnav { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin: -.3rem 0 1rem; font-size: .9rem; }
.subnav a { text-decoration: none; }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.card.entry { display: flex; flex-direction: column; gap: .3rem; text-decoration: none; color: inherit; margin: 0; }
.card.entry:hover { border-color: var(--brand); }
.plus { color: var(--green); font-weight: 600; } .minus { color: var(--red); }
table.lines select, table.lines input { min-width: 8rem; }
.inline-decide input { width: 10rem; margin-bottom: .3rem; }
input[type=radio] { width: 1.05rem; height: 1.05rem; margin: 0 .4rem 0 0; vertical-align: -2px; }
form.stack fieldset { border: 0; padding: 0; margin: 0; }
form.stack fieldset legend { font-weight: 600; padding: 0; margin-bottom: .25rem; }
form.stack fieldset label { display: inline-flex; align-items: center; font-weight: 400; margin-right: 1.2rem; }

/* Directors: authority page + printing the dashboard */
.power-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .8rem; margin: .6rem 0 1rem; }
.power-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .9rem .7rem; margin: 0; }
.power-grid legend { font-weight: 700; padding: 0 .3rem; }
label.tick { display: flex; gap: .55rem; align-items: flex-start; margin: .45rem 0; cursor: pointer; font-weight: 400; }
label.tick input { margin-top: .2rem; flex: none; }
.card.authority.off { opacity: .6; }
@media print {
  .topbar, .no-print, .msg { display: none !important; }
  body { background: #fff; font-size: 12px; }
  main { max-width: none; padding: 0; }
  .table-wrap { border: 0; overflow: visible; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile, tr { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* Ask box + knowledge notes */
.ask-box { display: flex; gap: .5rem; max-width: 820px; }
.ask-box input { max-width: none !important; font-size: 1.05rem; padding: .7rem .9rem !important; }
.examples { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.examples form { display: inline; }
.chip-btn { background: var(--blue-bg); color: var(--blue); border: 1px solid #c7defc; border-radius: 999px; padding: .3rem .8rem; font: inherit; font-size: .9rem; cursor: pointer; }
.chip-btn:hover { background: #dcecff; }
.answer-card h3, .ai-box h3 { font-size: 1.02rem; }
.answer-card.denied { border-left: 5px solid var(--amber); }
.badge.exact { background: var(--green-bg); color: var(--green); }
.badge.ai { background: #f4f3ff; color: #5925dc; }
.ai-box { border-left: 5px solid #7a5af8; }
.ai-answer { white-space: normal; }
.feedback { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.feedback .chosen { border-color: var(--brand); font-weight: 700; }
.note-body h3, .note-body h4, .note-body h5 { margin: 1rem 0 .4rem; }
.note-body p:first-child, .note-body h3:first-child { margin-top: 0; }
.note-body code { background: var(--grey-bg); padding: 0 .3rem; border-radius: 4px; }
.missing-link { color: var(--red); border-bottom: 1px dashed var(--red); }
.diff table.diff { font-size: .85rem; width: 100%; }
.diff .diff_add { background: #d1fadf; } .diff .diff_sub { background: #fee4e2; } .diff .diff_chg { background: #fef0c7; }
.diff td { padding: .15rem .4rem; border: 0; white-space: pre-wrap; } .diff th { display: none; }
@media (max-width: 700px) { .ask-box { flex-direction: column; } }
.note-preview { margin-top: .5rem; border-top: 1px dashed var(--line); padding-top: .4rem; }
.note-preview summary { cursor: pointer; }
.tick.included { opacity: .65; cursor: default; }

/* ---------- Header v2: tidy menu, profile circle, search button, phone layouts ---------- */
.topbar .inner { flex-wrap: nowrap; gap: 1.4rem; padding: .55rem 1rem; min-height: 56px; }
.topbar .brand { margin-right: 0; white-space: nowrap; font-size: 1.05rem; letter-spacing: .01em; }
.topbar .brand span { font-weight: 400; opacity: .75; }
.mainnav { display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; flex: 1; align-items: center; }
.mainnav a { padding: .35rem 0; border-bottom: 2px solid transparent; }
.mainnav a.active { border-bottom-color: #fff; }
.userbox { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; color: #dbe7f3 !important; }
.icon-btn:hover { background: rgba(255,255,255,.12); color: #fff !important; }
.menu-btn { display: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%;
  background: #fff; color: var(--brand) !important; font-weight: 700; font-size: .85rem; text-decoration: none; }
.avatar.active, .avatar:hover { box-shadow: 0 0 0 3px rgba(255,255,255,.45); }
.avatar.big { width: 64px; height: 64px; font-size: 1.4rem; background: var(--brand); color: #fff !important; flex: none; }

/* Search: round button bottom-right + search-engine style box */
.search-fab { position: fixed; right: 22px; bottom: 22px; width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; box-shadow: 0 8px 24px rgba(23,59,92,.35); display: flex; align-items: center; justify-content: center; z-index: 50; }
.search-fab:hover { background: var(--brand-dark); transform: translateY(-1px); }
.search-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 100; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.search-overlay[hidden] { display: none; }
.search-panel { width: 100%; max-width: 680px; background: var(--card); border-radius: 18px; padding: 1.1rem 1.2rem 1.2rem; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.search-field { display: flex; align-items: center; gap: .6rem; border: 2px solid var(--brand); border-radius: 999px; padding: .3rem .35rem .3rem 1rem; color: var(--muted); }
.search-field input { border: 0 !important; outline: none; padding: .55rem 0 !important; font-size: 1.08rem; max-width: none !important; background: transparent !important; color: var(--text); }
.search-field .btn { border-radius: 999px; padding: .55rem 1.2rem; }
.search-hints { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }
body.searching { overflow: hidden; }
/* Ask page box looks the same */
.ask-box { border: 2px solid var(--brand); border-radius: 999px; padding: .3rem .35rem .3rem 1rem; background: #fff; align-items: center; }
.ask-box input { border: 0 !important; outline: none; background: transparent !important; }
.ask-box .btn { border-radius: 999px; }

/* Profile page */
.profile-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.2rem; }
.can-list { margin: 0; padding-left: 1.2rem; columns: 2; }
.can-list li { margin: .15rem 0; break-inside: avoid; }
.profile-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.profile-actions form { display: inline; }
.btn.danger { color: var(--red); }

/* Bottom tab bar (directors, phones only) */
.tabbar { display: none; }

@media (max-width: 860px) {
  /* everyone except directors: menu folds into ☰ */
  body:not(.director) .menu-btn { display: inline-flex; order: 3; }
  body:not(.director) .topbar .inner { flex-wrap: wrap; }
  body:not(.director) .mainnav { display: none; order: 5; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0; padding: .3rem 0 .5rem; }
  body.nav-open:not(.director) .mainnav { display: flex; }
  body:not(.director) .mainnav a { padding: .65rem .2rem; border-bottom: 1px solid rgba(255,255,255,.12); }
  body:not(.director) .mainnav a.active { border-bottom-color: rgba(255,255,255,.12); font-weight: 700; }
  .userbox { order: 2; }
}
@media (max-width: 700px) {
  /* directors: app-style bottom tabs, clean top bar */
  body.director .mainnav { display: none; }
  body.director main { padding-bottom: 6.5rem; }
  body.director .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--card);
    border-top: 1px solid var(--line); padding: .35rem .3rem calc(.35rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .15rem; font-size: .72rem; color: var(--muted);
    text-decoration: none; padding: .25rem 0; font-weight: 600; }
  .tabbar a.active { color: var(--brand); }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
  body.director .search-fab { bottom: calc(76px + env(safe-area-inset-bottom)); right: 16px; width: 54px; height: 54px; }
  .search-fab { right: 16px; bottom: 16px; }
  .search-overlay { padding-top: 10vh; }
  .search-field { padding-left: .8rem; }
  .search-field .btn { padding: .5rem .9rem; }
  .can-list { columns: 1; }
}
@media print { .search-fab, .tabbar, .search-overlay { display: none !important; } }
.section-head { margin: 1.5rem 0 .6rem; }
.section-head h2 { margin: 0; }
.topbar .avatar { background: #fff; color: var(--brand) !important; }
.topbar .icon-btn { padding: 0; }
@media (max-width: 700px) {
  .ask-box { flex-direction: row; padding-left: .8rem; }
  .ask-box input { font-size: 1rem; min-width: 0; }
  .ask-box .btn { padding: .5rem .9rem; }
  body.director .topbar .avatar { display: none; }  /* phones: Profile is in the bottom tabs */
}

/* Authority: list of directors */
.people-list { display: grid; gap: .6rem; margin-bottom: 1.4rem; }
.person-row { display: flex; align-items: center; gap: .9rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: .8rem 1rem; text-decoration: none; color: inherit; }
.person-row:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(31,78,121,.08); }
.person-row.off { opacity: .6; }
.avatar.mid { width: 44px; height: 44px; font-size: 1rem; background: var(--brand); color: #fff !important; flex: none; }
.person-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.person-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; text-align: right; }
.chev { font-size: 1.6rem; color: var(--muted); line-height: 1; }
.details-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem 1rem; }
.details-grid label { display: block; font-weight: 600; margin-bottom: .25rem; }
@media (max-width: 700px) { .person-meta .muted { display: none; } }
