:root {
  --bg: hsl(40 20% 96%);
  --card: hsl(40 28% 98%);
  --fg: hsl(30 12% 12%);
  --muted: hsl(40 12% 92%);
  --muted-fg: hsl(35 7% 40%);
  --border: hsl(38 12% 85%);
  --primary: hsl(20 85% 40%);
  --primary-fg: hsl(40 30% 98%);
  --daily: hsl(20 85% 40%);
  --daily-soft: hsl(22 80% 92%);
  --truck: hsl(205 62% 34%);
  --truck-soft: hsl(205 55% 91%);
  --danger: hsl(4 72% 40%);
  --today-ring: hsl(20 85% 40%);
  --shadow: 0 1px 2px hsl(30 20% 10% / .06), 0 8px 24px hsl(30 20% 10% / .08);
  --radius: 12px;
  --font: 'Satoshi', system-ui, -apple-system, sans-serif;
  --display: 'Cabinet Grotesk', 'Satoshi', system-ui, sans-serif;
  color-scheme: light;
}
:root.dark {
  --bg: hsl(30 8% 9%);
  --card: hsl(30 7% 12%);
  --fg: hsl(40 12% 92%);
  --muted: hsl(30 6% 18%);
  --muted-fg: hsl(40 6% 62%);
  --border: hsl(30 6% 20%);
  --primary: hsl(22 88% 52%);
  --primary-fg: hsl(30 25% 8%);
  --daily: hsl(22 88% 56%);
  --daily-soft: hsl(22 45% 18%);
  --truck: hsl(205 70% 62%);
  --truck-soft: hsl(205 35% 18%);
  --danger: hsl(4 68% 58%);
  --shadow: 0 1px 2px hsl(0 0% 0% / .3), 0 8px 24px hsl(0 0% 0% / .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted-fg); }
.err { color: var(--danger); font-size: 13px; min-height: 1em; margin: 6px 0 0; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 800; font-size: 19px; letter-spacing: -.01em; }
.brand .logo { width: 26px; height: 26px; }
.brand-lg { font-size: 28px; justify-content: center; }
.brand-lg .logo { width: 38px; height: 38px; }

/* Gate */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 340px; text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 32px 24px; box-shadow: var(--shadow); }
.gate-card p { margin: 8px 0 20px; }
#gateInput { width: 100%; text-align: center; font-size: 28px; letter-spacing: .4em; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); margin-bottom: 12px; }
#gateInput:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 15px; min-height: 44px; transition: transform .08s, background .15s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--muted); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; background: transparent; border: 0; border-radius: 10px; }
.icon-btn:hover { background: var(--muted); }
.icon-btn svg { width: 22px; height: 22px; }

/* Layout */
.app { max-width: 1280px; margin: 0 auto; padding: env(safe-area-inset-top) 0 calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); z-index: 20; }
.top-actions { display: flex; align-items: center; gap: 2px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--muted); color: var(--muted-fg); margin-right: 4px; white-space: nowrap; }
.pill.warn { background: hsl(40 90% 88%); color: hsl(30 70% 28%); }
:root.dark .pill.warn { background: hsl(40 40% 20%); color: hsl(40 80% 70%); }
.pill.ro { background: var(--truck-soft); color: var(--truck); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px 4px; flex-wrap: wrap; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav h1 { font-family: var(--display); font-weight: 800; font-size: 22px; margin: 0 4px; min-width: 150px; text-align: center; letter-spacing: -.01em; }
.seg { display: inline-flex; background: var(--muted); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 700; font-size: 14px; color: var(--muted-fg); display: inline-flex; align-items: center; gap: 6px; }
.seg button.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px hsl(0 0% 0% / .12); }

.filters { display: flex; gap: 6px; padding: 8px 14px 10px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--border); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot-daily { background: var(--daily); }
.dot-trucking { background: var(--truck); }

.layout { display: grid; grid-template-columns: 1fr; gap: 14px; padding: 0 14px; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .day-panel { position: sticky; top: 72px; max-height: calc(100dvh - 90px); overflow: auto; }
}

/* Month grid */
.cal-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--border); }
.dow span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-fg); padding: 8px 6px; text-align: center; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cell { border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: transparent; text-align: left; padding: 5px; min-height: 64px; display: flex; flex-direction: column; gap: 3px; min-width: 0; position: relative; }
.cell:nth-child(7n) { border-right: 0; }
.cell.out { background: color-mix(in srgb, var(--muted) 45%, transparent); }
.cell.out .num { color: var(--muted-fg); opacity: .6; }
.cell.weekend:not(.out) { background: color-mix(in srgb, var(--muted) 25%, transparent); }
.cell.sel { box-shadow: inset 0 0 0 2px var(--primary); }
.num { font-weight: 700; font-size: 13px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cell.today .num { background: var(--primary); color: var(--primary-fg); }
.marks { display: flex; gap: 3px; flex-wrap: wrap; }
.mark { font-size: 11px; font-weight: 800; border-radius: 6px; padding: 1px 5px; line-height: 1.4; display: inline-flex; align-items: center; gap: 3px; }
.mark-daily { background: var(--daily-soft); color: var(--daily); }
.mark-trucking { background: var(--truck-soft); color: var(--truck); }
.mark svg { width: 11px; height: 11px; }
.previews { display: none; }
@media (min-width: 700px) {
  .cell { min-height: 108px; padding: 6px; }
  .marks { display: none; }
  .previews { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .pv { font-size: 12px; font-weight: 600; line-height: 1.3; padding: 2px 6px; border-radius: 5px; border-left: 3px solid; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pv-daily { background: var(--daily-soft); border-color: var(--daily); }
  .pv-trucking { background: var(--truck-soft); border-color: var(--truck); }
  .pv-more { font-size: 11px; color: var(--muted-fg); font-weight: 700; padding-left: 4px; }
}

/* Week view */
.week { display: flex; flex-direction: column; }
.wk-day { display: grid; grid-template-columns: 64px 1fr; border-bottom: 1px solid var(--border); background: transparent; border-left: 0; border-right: 0; border-top: 0; text-align: left; padding: 0; }
.wk-day:last-child { border-bottom: 0; }
.wk-day.sel { box-shadow: inset 3px 0 0 var(--primary); background: color-mix(in srgb, var(--primary) 5%, transparent); }
.wk-date { padding: 12px 8px; text-align: center; border-right: 1px solid var(--border); }
.wk-date b { display: block; font-family: var(--display); font-size: 22px; line-height: 1.1; }
.wk-date small { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-fg); }
.wk-day.today .wk-date b { color: var(--primary); }
.wk-notes { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wk-empty { color: var(--muted-fg); font-size: 13px; padding-top: 4px; }

/* Day panel */
.day-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.dp-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dp-head h2 { font-family: var(--display); font-weight: 800; font-size: 20px; margin: 0; letter-spacing: -.01em; }
.dp-head span { font-size: 13px; color: var(--muted-fg); font-weight: 600; }
.dp-sec { margin-top: 14px; }
.dp-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.dp-sec-head h3 { min-width: 0; line-height: 1.3; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; margin: 0; display: flex; align-items: center; gap: 7px; }
.add-btn { flex: none; white-space: nowrap; border: 1px dashed var(--border); background: transparent; border-radius: 9px; padding: 6px 10px; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 5px; min-height: 36px; }
.add-btn svg { width: 15px; height: 15px; }
.add-daily { color: var(--daily); border-color: color-mix(in srgb, var(--daily) 40%, transparent); }
.add-trucking { color: var(--truck); border-color: color-mix(in srgb, var(--truck) 40%, transparent); }
.note { width: 100%; text-align: left; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 10px 12px; border-left: 4px solid; display: block; margin-bottom: 8px; }
.note-daily { border-left-color: var(--daily); }
.note-trucking { border-left-color: var(--truck); }
.note-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted-fg); font-weight: 700; margin-bottom: 3px; }
.note-body { white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.note.pending { opacity: .75; border-style: dashed; }
.badge { font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 5px; background: hsl(40 90% 88%); color: hsl(30 70% 28%); }
.empty { border: 1px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted-fg); font-size: 14px; }
.wk-note { font-size: 13px; padding: 5px 8px; border-radius: 6px; border-left: 3px solid; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-note b { font-weight: 800; margin-right: 4px; }

/* FAB */
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); display: inline-flex; align-items: center; gap: 8px; background: var(--primary); color: var(--primary-fg); border: 0; border-radius: 999px; padding: 14px 22px 14px 18px; font-weight: 800; font-size: 17px; box-shadow: 0 8px 24px hsl(20 85% 30% / .35); z-index: 30; }
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(.96); }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; background: hsl(30 20% 5% / .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.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)); box-shadow: var(--shadow); animation: up .22s cubic-bezier(.2,.8,.2,1); max-height: 94dvh; overflow: auto; }
.sheet-tall { min-height: 70dvh; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(24px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-family: var(--display); font-weight: 800; font-size: 21px; margin: 0; }
.seg-cat { display: grid; grid-template-columns: 1fr 1fr; width: 100%; margin-bottom: 12px; }
.seg-cat button { justify-content: center; padding: 10px 8px; }
.seg-cat button[data-cat="trucking"].on { color: var(--truck); }
.seg-cat button[data-cat="daily"].on { color: var(--daily); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted-fg); min-width: 0; }
.field em { font-style: normal; font-weight: 500; }
.field input { border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 10px; font-size: 16px; min-height: 44px; width: 100%; min-width: 0; -webkit-appearance: none; }
textarea#edBody, #searchInput { width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: 12px; padding: 12px; font-size: 17px; line-height: 1.45; resize: vertical; }
textarea#edBody:focus, #searchInput:focus, .field input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.interim { color: var(--muted-fg); }

.dictate { display: flex; align-items: center; gap: 14px; background: var(--muted); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.mic { flex: none; width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-fg); display: grid; place-items: center; position: relative; box-shadow: 0 4px 14px hsl(20 85% 30% / .3); }
.mic svg { width: 30px; height: 30px; }
.mic.live { background: var(--danger); }
.mic.live::before, .mic.live::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--danger); animation: ring 1.4s ease-out infinite; }
.mic.live::after { animation-delay: .7s; }
@keyframes ring { from { transform: scale(1); opacity: .7; } to { transform: scale(1.6); opacity: 0; } }
.mic-text { display: flex; flex-direction: column; min-width: 0; }
.mic-text strong { font-size: 16px; }
.mic-text span { font-size: 13px; }

.sheet-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.spacer { flex: 1; }

.results { margin-top: 12px; }
.res-date { font-size: 12px; font-weight: 800; color: var(--muted-fg); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 6px; }
mark { background: hsl(45 95% 70%); color: inherit; border-radius: 3px; padding: 0 1px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: 14px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }

.skel { background: linear-gradient(90deg, var(--muted) 25%, color-mix(in srgb, var(--muted) 50%, var(--card)) 50%, var(--muted) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; height: 54px; margin-bottom: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (max-width: 420px) {
  .nav h1 { font-size: 19px; min-width: 120px; }
  .toolbar { padding-top: 10px; }
  .pill { display: none; }
  .pill.warn, .pill.ro { display: inline-block; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
