:root {
  --bg: #f4f6fa; --panel: #ffffff; --ink: #172033; --muted: #5c6880; --line: #e1e6ef; --line2: #eef1f6;
  --brand: #2457d6; --brand-ink: #ffffff; --ok: #1f8a5b; --warn: #b7791f; --bad: #c53030;
  --confirmed: #3b82f6; --inhouse: #16a34a; --hold: #a855f7; --out: #94a3b8; --ota: #f59e0b;
  --oos: #ef4444; --blocked: #64748b; --today: #fff7e0; --weekend: #f8fafc;
  --col: 66px; --row: 34px; --left: 210px; --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: #b9c3d6; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); border-color: #f1c4c4; }
button.ok { color: var(--ok); border-color: #bfe3d1; }
button.icon { border: none; background: none; font-size: 20px; padding: 2px 8px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select { font-size: 14px; color: var(--ink); }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0; } h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--line2); color: var(--muted); white-space: nowrap; }
.chip.confirmed { background: #e0ecff; color: #1d4ed8; } .chip.in_house { background: #dcfce7; color: #166534; }
.chip.hold { background: #f3e8ff; color: #7e22ce; } .chip.checked_out { background: #eef2f7; color: #475569; }
.chip.cancelled, .chip.no_show { background: #fee2e2; color: #991b1b; }
.chip.high { background: #fee2e2; color: #991b1b; } .chip.medium { background: #fef3c7; color: #92400e; } .chip.low { background: #e0ecff; color: #1d4ed8; }
.chip.dirty { background: #fee2e2; color: #991b1b; } .chip.clean { background: #dcfce7; color: #166534; } .chip.inspected { background: #dbeafe; color: #1e40af; }

/* shell */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); display: inline-block; }
nav.tabs { display: flex; gap: 2px; }
nav.tabs a { padding: 7px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; }
nav.tabs a.on { background: #e8efff; color: var(--brand); font-weight: 600; }
.bizdate { font-size: 12px; color: var(--muted); }
main { padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card b { font-size: 24px; display: block; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 7px 8px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #f7f9fd; }

/* login */
.login { max-width: 360px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }

/* calendar / tape chart */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.problems { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid #f3d27a; background: #fffaeb; border-radius: var(--radius); margin-bottom: 10px; cursor: pointer; }
.problems.none { border-color: #bfe3d1; background: #f0fbf5; cursor: default; }
.tape { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 170px); position: relative; }
.tape-inner { min-width: max-content; }
.trow { display: flex; height: var(--row); border-bottom: 1px solid var(--line2); position: relative; }
.trow .lab { width: var(--left); min-width: var(--left); position: sticky; left: 0; z-index: 6; background: var(--panel); padding: 0 10px; display: flex; align-items: center; gap: 6px; border-right: 1px solid var(--line); font-size: 13px; overflow: hidden; white-space: nowrap; }
.trow .cells { display: flex; position: relative; }
.cell { width: var(--col); min-width: var(--col); height: var(--row); border-right: 1px solid var(--line2); }
.cell.today { background: var(--today); } .cell.weekend { background: var(--weekend); }
.cell.drop { background: #dbe7ff !important; }
.head { position: sticky; top: 0; z-index: 12; background: var(--panel); height: 52px; border-bottom: 1px solid var(--line); }
.head .lab { height: 52px; font-weight: 600; }
.head .cell { height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.head .cell b { font-size: 16px; color: var(--ink); }
.head .cell.today b { color: var(--brand); }
.trow.type { background: #fafbfd; height: 30px; }
.trow.type .lab { background: #fafbfd; font-size: 12px; color: var(--muted); }
.trow.type .cell { height: 30px; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.trow.type .cell .n { font-weight: 700; color: var(--ink); } .trow.type .cell .n.zero { color: var(--bad); }
.trow.type .cell .p { color: var(--muted); } .trow.type .cell.stop { background: repeating-linear-gradient(45deg,#fff,#fff 4px,#fdecec 4px,#fdecec 8px); }
.trow.space { background: #f6f8fc; }
.trow.space .lab { background: #f6f8fc; font-weight: 600; }
.trow.unit .lab { padding-left: 24px; }
.trow.section .lab { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg); }
.trow.section { background: var(--bg); height: 26px; }
.trow.section .cell { height: 26px; border-right-color: transparent; }
.hk { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.hk.dirty { background: var(--bad); } .hk.clean { background: var(--ok); } .hk.inspected { background: var(--brand); }
.g-tag { font-size: 10px; padding: 0 5px; border-radius: 4px; background: #fde7f3; color: #9d174d; }
.bar { position: absolute; top: 4px; height: calc(var(--row) - 8px); border-radius: 6px; color: #fff; font-size: 12px; padding: 0 8px; display: flex; align-items: center; gap: 4px; overflow: hidden; white-space: nowrap; cursor: pointer; z-index: 4; box-shadow: 0 1px 2px rgba(0,0,0,.15); touch-action: none; user-select: none; }
.bar.confirmed { background: var(--confirmed); } .bar.in_house { background: var(--inhouse); } .bar.hold { background: var(--hold); }
.bar.checked_out { background: var(--out); } .bar.ota { box-shadow: inset 4px 0 0 var(--ota), 0 1px 2px rgba(0,0,0,.15); }
.bar.ghost { background: repeating-linear-gradient(45deg, #cbd5e1, #cbd5e1 5px, #e2e8f0 5px, #e2e8f0 10px); color: #334155; cursor: default; box-shadow: none; z-index: 3; }
.bar.block { background: repeating-linear-gradient(45deg, var(--blocked), var(--blocked) 6px, #7b8798 6px, #7b8798 12px); }
.bar.block.out_of_service { background: repeating-linear-gradient(45deg, var(--oos), var(--oos) 6px, #f26b6b 6px, #f26b6b 12px); }
.bar .grip { position: absolute; right: 0; top: 0; bottom: 0; width: 8px; cursor: ew-resize; background: rgba(255,255,255,.25); }
.bar.dragging { opacity: .5; }
.bar .flag { background: rgba(0,0,0,.25); border-radius: 4px; padding: 0 4px; font-size: 10px; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); align-items: center; }
.legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; background: var(--c); }

/* drawer */
.drawer-back { position: fixed; inset: 0; background: rgba(15,23,42,.25); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); z-index: 41; box-shadow: -8px 0 24px rgba(15,23,42,.15); display: flex; flex-direction: column; }
.drawer-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer-body { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.lineblock { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.events { font-size: 12px; } .events li { margin-bottom: 6px; }
.banner { padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.banner.bad { background: #fee2e2; color: #991b1b; } .banner.warn { background: #fef3c7; color: #92400e; } .banner.info { background: #e0ecff; color: #1e3a8a; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; }
.modal { background: var(--panel); border-radius: 10px; width: min(820px, calc(100vw - 32px)); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(15,23,42,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.opt { cursor: pointer; } .opt.sel td { background: #e8efff; } .opt.no td { color: var(--muted); }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; }
.toast { padding: 9px 14px; border-radius: 8px; background: #0f172a; color: #fff; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 80vw; }
.toast.error { background: #b91c1c; } .toast.warn { background: #92400e; }

@media (max-width: 760px) {
  :root { --left: 120px; --col: 54px; }
  .top { flex-wrap: wrap; }
  main { padding: 10px; }
}

/* reporting workspace */
.rw { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 14px; align-items: start; }
.rw-side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; position: sticky; top: 64px; max-height: calc(100vh - 90px); overflow: auto; }
.rw-sidehead { font-weight: 700; margin-bottom: 6px; }
.rw-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 4px; }
.rw-view { display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px; font-size: 13px; }
.rw-view a { color: var(--ink); text-decoration: none; flex: 1; }
.rw-view.on { background: #e8efff; } .rw-view.on a { color: var(--brand); font-weight: 600; }
.rw-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rw-ask { display: flex; gap: 8px; }
.rw-explain { padding: 8px 12px; border: 1px solid #cfdcff; background: #eef4ff; border-radius: var(--radius); font-size: 13px; }
.rw-builder { display: flex; flex-direction: column; gap: 8px; }
.rw-row { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rw-builder > .rw-row { display: flex; }
.rw-filters { display: flex; flex-direction: column; gap: 6px; }
.rw-filter { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rw-pill { display: inline-flex; gap: 2px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 2px 2px 2px 4px; }
.rw-check { flex-direction: row !important; align-items: center; gap: 6px; color: var(--ink) !important; font-size: 13px !important; }
.rw-cols summary { cursor: pointer; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; display: inline-block; }
.rw-colgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 12px; padding: 8px; max-width: 900px; }
.rw-scroll { overflow: auto; max-height: calc(100vh - 330px); }
.rw-table th.rw-th { cursor: pointer; white-space: nowrap; user-select: none; }
.rw-table th.num, .rw-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rw-table tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfd; }
@media (max-width: 900px) { .rw { grid-template-columns: 1fr; } .rw-side { position: static; max-height: none; } }
