/* Trip Chart Builder - light theme matching Crew Roster Board */
:root {
  --bg: #f4f6fb; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #2563eb; --primary-dark: #1d4ed8; --primary-soft: #eff6ff;
  --ok: #15803d; --ok-soft: #f0fdf4; --warn: #b45309; --warn-soft: #fffbeb; --err: #b91c1c; --err-soft: #fef2f2;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: #0f172a; color: #fff; }
.topbar .brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .35); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #cbd5e1; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }

.wrap { max-width: none; margin: 0; padding: 20px 28px 48px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 16px; }
.card.narrow { max-width: 640px; margin: 40px auto; }
.page-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline { display: inline; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; }
.btn:hover { border-color: #cbd5e1; background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-small { padding: 4px 10px; font-size: 12px; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
input[type=text], input[type=number], input[type=file] { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 220px; }
input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; border: 1px solid; }
.alert-ok { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }
.alert-error { background: var(--err-soft); border-color: #fecaca; color: var(--err); }
.alert-warn { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); font-size: 13px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 18px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.chip { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--text); font-size: 13px; }
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chip:hover { text-decoration: none; border-color: #cbd5e1; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted-badge { background: #f1f5f9; color: var(--muted); }

.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f8fafc; white-space: nowrap; }
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:hover td { background: #fafcff; }
table.grid tr.kind-induction td, table.grid tr.kind-stabling td, table.grid tr.kind-standby td { background: #fbfbfd; color: #475569; }
tr.flagged td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.stops { margin-top: 6px; font-size: 12px; border-collapse: collapse; }
table.stops td { padding: 1px 8px 1px 0; border: 0; }
details summary { cursor: pointer; color: var(--primary); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; color: var(--muted); font-size: 12px; }
.stat span { display: block; font-size: 22px; font-weight: 700; color: var(--text); }
.stat-warn span { color: var(--warn); }

.legs { display: flex; flex-wrap: wrap; gap: 4px; }
.leg { padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); font-size: 12px; white-space: nowrap; }
.leg-induction, .leg-stabling { background: #f1f5f9; }
.leg-standby { background: #faf5ff; }
.leg-break { background: var(--ok-soft); color: var(--ok); }

form.rules fieldset { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px 24px; }
form.rules legend { font-weight: 700; padding: 0 6px; }
form.rules small { font-weight: 400; }

@media (max-width: 700px) {
  .wrap { padding: 16px; }
  .topbar { padding: 0 16px; gap: 12px; }
  input[type=text], input[type=number], input[type=file] { min-width: 0; width: 100%; }
  .form-row label { width: 100%; }
}
@media print {
  .topbar, .no-print, .tabs { display: none !important; }
  body { background: #fff; }
  .card, .stat { border: 0; padding: 0; }
  .leg { border: 1px solid #ddd; }
}

/* time-distance graph */
.graph-filters .filter-row { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 6px 0; }
.graph-filters .filter-row + .filter-row { border-top: 1px solid var(--line); }
.graph-filters .chips { margin: 0; }
.filter-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); min-width: 52px; }
label.toggle, label.inline-field { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
label.inline-field input[type=time] { font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
button.chip { font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.rake-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.graph-wrap { overflow-x: auto; margin: 0 0 8px; }
#graph svg { display: block; }
.g-trip:hover path:first-child { stroke-width: 5; }
@media print { .graph-wrap { overflow: visible; } }

/* small screens are not supported: the timetables, duty tables and graph need a laptop/desktop width */
.small-screen-block { display: none; }
@media (max-width: 1023px) {
  .small-screen-block { display: flex; position: fixed; inset: 0; z-index: 1000; background: var(--bg); align-items: center; justify-content: center; padding: 24px; text-align: center; }
  .small-screen-block .box { max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 24px; }
  .small-screen-block h1 { color: var(--err); font-size: 20px; }
  body > .topbar, body > main { display: none; }
}
select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input[type=time] { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
tr.duty-first td { border-top: 2px solid #cbd5e1; }
.loop-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.loop-card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.loop-card input[type=text] { width: 100%; min-width: 0; }
.loop-head { display: flex; gap: 10px; align-items: center; }
.loop-stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.loop-stats b { color: var(--text); font-size: 16px; }
.loop-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs a.tab-settings { margin-left: auto; font-weight: 500; }
.model-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px 20px; margin-bottom: 14px; }
.model-pick label.check { align-items: flex-start; }
tr.best-row td { background: var(--ok-soft); }
.guide h3 { font-size: 14px; margin: 18px 0 8px; }
.guide section.card { scroll-margin-top: 16px; }
.guide-toc ol { margin: 6px 0 0; padding-left: 20px; columns: 2; }
.guide-steps li { margin-bottom: 6px; }
.guide-table td { vertical-align: top; font-size: 13px; }
.guide-table td:first-child { font-weight: 600; white-space: nowrap; }
.badge.ok-badge { background: var(--ok-soft); color: var(--ok); }
tr.cov-missing td, tr.cov-double td { background: var(--err-soft); }
tr.cov-partial td { background: var(--warn-soft); }
a.stat { text-decoration: none; }
a.stat:hover { border-color: #cbd5e1; }
.stat-active { outline: 2px solid var(--primary); }
.duty-pick { width: 180px; min-width: 0 !important; padding: 5px 8px !important; }
/* duty circulation report */
.circ-filter { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.circ-filter .chips { margin: 0; }
.duty-card { break-inside: avoid; }
.duty-head { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 10px; }
.duty-head h2 { margin: 0 0 4px; font-size: 18px; }
.duty-kpis { display: flex; gap: 18px; flex-wrap: wrap; }
.duty-kpis div { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.duty-kpis b { font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; }
.duty-tdg-wrap { border: 1px solid var(--line); border-radius: 12px; margin: 6px 0 12px; overflow: hidden; }
.duty-tdg { display: block; width: 100%; height: auto; }
tr.circ-sign td { background: #f1f5f9; }
tr.circ-break td { background: var(--ok-soft); color: var(--ok); }
@media print { .duty-card { page-break-after: always; } .duty-card:last-of-type { page-break-after: auto; } }
/* circulation: text left, graph right, one landscape page per duty */
.duty-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.duty-split .duty-tdg-wrap { margin: 0; }
.circ-table td, .circ-table th { padding: 5px 8px; font-size: 12px; }
.app-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 14px 16px 22px; border-top: 1px solid var(--line); margin-top: 8px; }
@media print {
  @page { size: A4 landscape; margin: 10mm 10mm 14mm; }
  .app-footer { position: fixed; bottom: 0; left: 0; right: 0; border: 0; padding: 4px; font-size: 9px; background: #fff; }
  .wrap { padding: 0 0 18px; }
  .duty-card { margin: 0; }
  .duty-split { grid-template-columns: 1fr 1fr; }
  .circ-table td, .circ-table th { font-size: 10px; padding: 3px 6px; }
}
.topbar .brand-logo { width: 30px; height: 30px; }
.topbar .brand span { display: flex; flex-direction: column; line-height: 1.1; font-size: 15px; }
.topbar .brand small { font-size: 10px; font-weight: 500; color: #94A3B8; letter-spacing: .02em; }
.topbar .brand:hover { text-decoration: none; }
/* working overlay */
.busy-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; cursor: progress; }
.busy-overlay[hidden] { display: none; }
.busy-box { background: #fff; border-radius: 18px; padding: 28px 40px 24px; text-align: center; box-shadow: 0 20px 50px rgba(15,23,42,.25); min-width: 300px; }
.busy-logo { width: 120px; height: 120px; display: block; margin: 0 auto 12px; }
.busy-pct { font-size: 26px; font-weight: 800; color: var(--primary); }
.busy-msg { font-weight: 600; margin-top: 2px; }
.busy-note { color: var(--muted); font-size: 12px; margin-top: 6px; }
body.is-busy { overflow: hidden; }
@media print { .busy-overlay { display: none !important; } }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
/* duty editor */
.ed-duty { padding: 12px 16px; }
.ed-warn { box-shadow: inset 4px 0 0 var(--warn); }
.ed-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.ed-no { font-size: 16px; }
.ed-msg { color: var(--warn); margin-top: 2px; }
.ed-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ed-input { width: 110px; min-width: 0 !important; padding: 4px 8px !important; font-size: 12px !important; }
/* edit on the graph */
.graph-wrap { position: relative; }
body.g-editing #graph .dleg, body.g-editing #graph .dbreak { cursor: pointer; }
body.g-editing #graph .dleg:hover { stroke-width: 7; }
body.g-editing #graph .dbreak:hover { stroke-width: 9; }
.g-edit-panel { position: fixed; right: 20px; top: 80px; width: 380px; max-height: calc(100vh - 110px); overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(15,23,42,.18); padding: 16px 18px; z-index: 50; }
.g-edit-panel[hidden] { display: none; }
.g-edit-panel h3 { margin: 0 0 4px; font-size: 16px; }
.g-edit-panel h4 { margin: 12px 0 6px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.g-x { position: absolute; right: 10px; top: 6px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.g-opts { display: flex; flex-direction: column; gap: 6px; }
.g-opt { display: flex; justify-content: space-between; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.g-opt-ok { border-color: #bbf7d0; background: var(--ok-soft); }
.g-opt-warn { border-color: #fde68a; background: var(--warn-soft); }
.g-warn { color: var(--warn); }
.g-ok { color: var(--ok); }
.g-err { color: var(--err); }
.g-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.g-busy { padding: 20px 0; color: var(--muted); }
/* table editor: drag and drop */
tr.ed-leg { cursor: grab; }
tr.ed-leg:hover td { background: #f1f5f9; }
.ed-grip { color: var(--muted); cursor: grab; }
tr.ed-dragging { opacity: .45; }
tr.ed-break { cursor: pointer; }
tr.ed-break:hover td { background: #dcfce7; }
.ed-drag-on section.ed-duty { outline: 2px dashed transparent; transition: outline-color .1s; }
.ed-drag-on section.ed-duty.ed-over { outline-color: #2563eb; background: #eff6ff; }
.ed-drop-hint { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 14px 26px; border-radius: 12px; border: 2px dashed #94a3b8; z-index: 60; font-weight: 600; }
.ed-drop-hint.ed-over { background: #2563eb; border-color: #fff; }
.ed-drop-hint[hidden] { display: none; }

/* signed-in user in the top bar */
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-user a { color: #e2e8f0; font-size: 13px; }
.topbar-user small { color: #94a3b8; margin-left: 4px; }
.btn-ghost-dark { background: transparent; color: #cbd5e1; border: 1px solid #334155; }
.btn-ghost-dark:hover { background: #1e293b; color: #fff; }
.login-box { max-width: 420px; margin: 60px auto; }
.login-box .brand-big { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.login-box .brand-big img { width: 44px; height: 44px; }
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form-grid input, .form-grid select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e2e8f0; }
.role-admin { background: #fee2e2; color: #991b1b; }
.role-planner { background: #dbeafe; color: #1e40af; }
tr.inactive td { color: var(--muted); text-decoration: line-through; }

tr.audit-bad td { background: var(--err-soft); }
.audit-detail { max-width: 380px; word-break: break-word; }

/* live rule check while dragging */
section.ed-duty { position: relative; }
.ed-check { position: absolute; right: 12px; top: 8px; max-width: 60%; padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; z-index: 5; pointer-events: none; box-shadow: 0 4px 12px rgba(15,23,42,.15); }
.ed-drop-hint .ed-check { position: static; display: block; margin-top: 6px; max-width: none; }
.ed-check-ok { background: #dcfce7; color: #166534; }
.ed-check-bad { background: #fee2e2; color: #991b1b; }
.ed-check-err { background: #fef3c7; color: #92400e; }
/* KPI dashboard */
.kpi-cols { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; margin-top: 12px; }
.kpi-cols h3 { font-size: 14px; margin: 8px 0 6px; }
.kpi-hist { width: 100%; max-width: 680px; height: auto; display: block; }
.kpi-grid { stroke: #e2e8f0; stroke-width: 1; }
.kpi-ax { font-size: 10px; fill: #64748b; }
.kpi-fill { fill: #2563eb; }
.kpi-bar:hover .kpi-fill { fill: #1d4ed8; }
.kpi-bar:hover rect { fill: rgba(37,99,235,.06); }
.kpi-d { font-size: 11px; font-weight: 600; }
.kpi-good { color: var(--ok); }
.kpi-bad { color: var(--err); }
.stat .kpi-d { font-size: 11px; font-weight: 600; display: inline; color: inherit; }
.stat .kpi-d.kpi-good { color: var(--ok); } .stat .kpi-d.kpi-bad { color: var(--err); } .stat .kpi-d.muted { color: var(--muted); font-weight: 500; }
.topbar nav a { white-space: nowrap; }

/* approval status */
.st-draft { background: #f1f5f9; color: #475569; }
.st-checked { background: #fef3c7; color: #92400e; }
.st-approved { background: #dcfce7; color: #166534; }
