:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #171a20;
  --muted: #69707d;
  --line: #dde1e8;
  --accent: #e8791d;
  --accent-soft: #fdeedd;
  --primary: #2563eb;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --ok-soft: #e6f6ec;
  --warn-soft: #fff7e0;
  --day-soft: #fff3d6;
  --day-edge: #eab308;
  --night-soft: #e4e9fb;
  --night-edge: #6366f1;
  --shadow: 0 1px 4px rgba(20, 24, 34, .08);
}
[data-theme="dark"] {
  --bg: #14161b;
  --card: #1d2027;
  --text: #e8eaef;
  --muted: #9aa1ad;
  --line: #2e323b;
  --accent: #f08c33;
  --accent-soft: #3a2a17;
  --primary: #3b82f6;
  --danger: #f87171;
  --danger-soft: #3a2023;
  --ok: #4ade80;
  --ok-soft: #1c3226;
  --warn-soft: #37301a;
  --day-soft: #35301c;
  --day-edge: #ca9a04;
  --night-soft: #232a45;
  --night-edge: #818cf8;
  --shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
input, button, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- top bar / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.brand span { color: var(--accent); }
.brand.big { font-size: 26px; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 600;
}
.mainnav a.on { background: var(--accent-soft); color: var(--accent); }
.mainnav .ico { font-size: 16px; }
.topright { display: flex; gap: 6px; }
.iconbtn {
  background: none; border: 1px solid var(--line); border-radius: 9px;
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); font-size: 16px;
}
.iconbtn:hover { color: var(--text); }

.page { padding: 14px; max-width: 1280px; margin: 0 auto; }

/* mobile: nav becomes a fixed bottom tab bar */
@media (max-width: 879px) {
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .mainnav a { flex-direction: column; gap: 2px; font-size: 12px; padding: 5px 18px; }
  .mainnav .ico { font-size: 20px; }
  body { padding-bottom: 76px; }
}

/* ---------- shared bits ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font-weight: 600; min-height: 40px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.alert { border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-weight: 600; }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 13px; }
input[type=text], input[type=password], input[type=time], input[type=date], input:not([type]) {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; min-height: 40px; width: 100%;
}
input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ---------- login ---------- */
.loginwrap { display: flex; justify-content: center; padding-top: 12vh; }
.logincard { width: min(360px, 92vw); padding: 28px; display: flex; flex-direction: column; gap: 14px; text-align: center; }

/* ---------- board bar ---------- */
.boardbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.weeknav { display: flex; align-items: center; gap: 6px; flex: 1; }
.weeklabel { font-weight: 700; margin-left: 6px; }

/* ---------- week grid (desktop) ---------- */
.weekgrid { overflow-x: auto; }
.weekgrid table { border-collapse: collapse; width: 100%; min-width: 860px; }
.weekgrid th, .weekgrid td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.weekgrid th { font-size: 13px; color: var(--muted); white-space: nowrap; }
.weekgrid th.today, .weekgrid td.today { background: var(--accent-soft); }
.weekgrid .truckcell { font-weight: 800; white-space: nowrap; border-right: 1px solid var(--line); }
.weekgrid .tplcell { color: var(--muted); font-size: 13px; white-space: nowrap; }

.slot {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border-radius: 9px; padding: 7px 9px; border: 1px solid transparent;
  font-size: 13px; line-height: 1.3;
}
.slot .who { font-weight: 700; display: block; }
.slot .when { color: var(--muted); font-size: 12px; }
.slot.tDay { background: var(--day-soft); border-color: var(--day-edge); }
.slot.tNight { background: var(--night-soft); border-color: var(--night-edge); }
.slot.open { background: transparent; border: 1.5px dashed var(--danger); color: var(--danger); font-weight: 700; text-align: center; }
.slot.custom .when { color: var(--accent); font-weight: 700; }
.slot.hasnote .who::after { content: ' \1F4DD'; font-size: 11px; }

/* ---------- day list (mobile) ---------- */
.daylist { display: none; }
.daycard { margin-bottom: 12px; padding: 12px; }
.dayhead { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.dayhead .dname { font-weight: 800; font-size: 16px; }
.dayhead .dopen { color: var(--danger); font-size: 12px; font-weight: 700; margin-left: auto; }
.dayhead .dfull { color: var(--ok); font-size: 12px; font-weight: 700; margin-left: auto; }
.daycard.today { outline: 2px solid var(--accent); }
.daycard .todaytag { color: var(--accent); font-size: 12px; font-weight: 800; }
.truckrow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.truckrow .tname { font-weight: 700; width: 74px; flex-shrink: 0; font-size: 13px; }
.truckrow .slots { display: flex; gap: 8px; flex: 1; }
.truckrow .slot { flex: 1; min-height: 52px; }

@media (max-width: 879px) {
  .weekgrid { display: none; }
  .daylist { display: block; }
}

/* ---------- modal / bottom sheet ---------- */
.modalback {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 12, 16, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 880px) {
  .modalback { align-items: center; }
  .sheet { border-radius: 18px; }
}
.sheethead { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.sheethead > div { flex: 1; }
.mtitle { font-weight: 800; font-size: 17px; }
.msub { color: var(--muted); font-size: 13px; }
.mlabel { font-weight: 700; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.mlabel.block input { margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; font-weight: 600; min-height: 42px;
}
.chip.sel { border-color: var(--primary); background: var(--primary); color: #fff; }
.mrow { display: flex; align-items: flex-end; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.tfield { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.tfield input { width: 120px; }
.mactions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.spacer { flex: 1; }

/* ---------- report ---------- */
.reportbar { padding: 12px; margin-bottom: 12px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.rangerow { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.rangerow .tfield input { width: 150px; }
.rsummary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { padding: 10px 16px; border-radius: 12px; }
.stat .n { font-size: 20px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }
.drv { margin-bottom: 10px; overflow: hidden; }
.drvhead {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  cursor: pointer; width: 100%; background: none; border: none; text-align: left;
}
.drvhead .dn { font-weight: 800; font-size: 15px; flex: 1; }
.drvhead .dh { font-weight: 800; color: var(--accent); }
.drvhead .caret { color: var(--muted); }
.drvdetail { border-top: 1px solid var(--line); padding: 4px 14px 10px; }
.drvdetail table { width: 100%; border-collapse: collapse; font-size: 13px; }
.drvdetail td, .drvdetail th { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.drvdetail th { color: var(--muted); font-weight: 600; }
.drvdetail tr:last-child td { border-bottom: none; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- manage ---------- */
.msection { padding: 14px; margin-bottom: 14px; }
.msection h2 { margin: 0 0 10px; font-size: 16px; }
.mline { display: flex; gap: 8px; align-items: center; padding: 6px 0; flex-wrap: wrap; }
.mline input { flex: 1; min-width: 120px; }
.mline input.phone { flex: 0 1 150px; }
.mline input[type=time] { flex: 0 0 110px; width: 110px; }
.mline.inactive input { opacity: .45; }
.mline.addline { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 12px; }
