:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b2330;
  --muted: #5d6878;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e6eefb;
  --good: #1e7a46;
  --good-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #181d25;
    --surface-2: #1f2530;
    --border: #2c3442;
    --text: #e6e9ef;
    --muted: #97a1b2;
    --accent: #6ea2f5;
    --accent-text: #0d1420;
    --accent-soft: #1d2b42;
    --good: #5cc98b;
    --good-soft: #17301f;
    --warn: #e6ad55;
    --warn-soft: #33270f;
    --bad: #f08880;
    --bad-soft: #3a1b19;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 14px; font-weight: 800;
}
a.brand { color: var(--text); text-decoration: none; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a {
  color: var(--muted); font-weight: 600; text-decoration: none;
  padding: 7px 12px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1320px; margin: 0 auto; padding: 16px; outline: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 22px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- layout ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
.grid-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid-2, .grid-even { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.space { justify-content: space-between; }
.row.center { justify-content: center; }
.nowrap { flex-wrap: nowrap; white-space: nowrap; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 12px; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; width: 100%; min-width: 0;
}
input:disabled { background: var(--surface-2); color: var(--muted); }
input[type="checkbox"] { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 70px; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 7px; padding: 7px 13px; text-decoration: none; display: inline-block;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--bad); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.max-h { max-height: 50vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover td { background: var(--surface-2); }
tr.row-flag td { background: var(--bad-soft); }
tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }
.edit-table td { padding: 3px 4px; }
.edit-table input { padding: 4px 6px; }
.w-90 { width: 90px; }
.w-120 { width: 120px; }
.num-in { text-align: right; }
.clamp { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- bits ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.stat .label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.bad .value { color: var(--bad); }
.stat.warn .value { color: var(--warn); }
.stats.mb-16 .stat { background: var(--surface); border: 1px solid var(--border); }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; margin-right: 2px; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.bad-text { color: var(--bad); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.good-text { color: var(--good); font-weight: 600; }

.notice { border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.good { background: var(--good-soft); color: var(--good); }
.notice-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }

.bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 99px; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty-state { text-align: center; padding: 40px 16px; }

.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.subtab { padding: 8px 12px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li + li { border-top: 1px solid var(--border); }
.feed-item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: start; padding: 9px 4px; color: var(--text); text-decoration: none; border-radius: 6px; }
.feed-item:hover { background: var(--surface-2); }
.feed-item .badge { justify-self: start; margin-top: 2px; }
.feed-title { font-weight: 600; }

.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checklist li { display: flex; gap: 8px; align-items: center; }
.checklist .tick { width: 20px; height: 20px; border-radius: 99px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--surface-2); color: var(--muted); flex: none; }
.checklist li.ok .tick { background: var(--good-soft); color: var(--good); }

dl.meta { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
dl.meta dt { color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 2px; }
dl.meta dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.doc-card h3 { font-size: 15px; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.photo figcaption { display: flex; gap: 4px; padding: 4px; }
.photo figcaption input { padding: 3px 6px; font-size: 12px; }

.danger-zone { border-color: var(--bad); }
.logo-preview { max-height: 48px; max-width: 180px; display: block; }
.status-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.dialog.wide { width: min(900px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 14, 20, 0.5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dialog-body { padding: 16px; }

/* ---------- dock timeline ---------- */
.tl-wrap { overflow-x: auto; }
.tl-grid { display: grid; position: relative; min-width: 100%; }
.tl-corner, .tl-head { position: sticky; top: 0; background: var(--surface); z-index: 3; padding: 4px 8px 8px; border-bottom: 1px solid var(--border); }
.tl-head { grid-row: 1; border-left: 1px solid var(--border); }
.tl-corner { grid-row: 1; grid-column: 1; }
.tl-dock { font-weight: 700; }
.mt-4 { margin-top: 4px; }
.mb-4 { margin-bottom: 4px; }
.tl-time { font-size: 11px; color: var(--muted); text-align: right; padding: 2px 8px 0 0; line-height: 1; font-variant-numeric: tabular-nums; border-top: 1px solid var(--border); }
.tl-time.half { border-top: 0; }
.tl-slot { border: 0; border-left: 1px solid var(--border); border-top: 1px dashed transparent; background: transparent; cursor: pointer; padding: 0; min-height: 26px; }
.tl-slot.hour { border-top: 1px solid var(--border); }
.tl-slot:not(.hour) { border-top: 1px dashed var(--surface-2); }
.tl-slot.closed { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, transparent 4px 9px); cursor: not-allowed; }
.tl-slot:hover:not(.closed) { background: var(--accent-soft); }
.tl-now { height: 2px; background: var(--bad); z-index: 2; pointer-events: none; align-self: start; }
.tl-appt {
  z-index: 2; margin: 1px 3px; border-radius: 6px; padding: 3px 6px; text-align: left; font: inherit; font-size: 12px; line-height: 1.3;
  border: 1px solid var(--accent); border-left-width: 4px; background: var(--accent-soft); color: var(--text); cursor: pointer; overflow: hidden; min-width: 0;
}
.tl-appt:hover { filter: brightness(0.97); }
.tl-appt .small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-appt-top { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-appt.st-done { border-color: var(--good); background: var(--good-soft); }
.tl-appt.st-arrived, .tl-appt.st-unloading { border-color: var(--accent); background: var(--surface); border-style: solid; }
.tl-appt.st-unloading { box-shadow: inset 0 0 0 1px var(--accent); }
.tl-appt.st-no_show { border-color: var(--bad); background: var(--bad-soft); opacity: 0.7; }
.tl-appt.fl-late, .tl-appt.fl-overrun { border-color: var(--warn); background: var(--warn-soft); }
.tl-appt.fl-missed { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- charts ---------- */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 70px; gap: 10px; align-items: center; position: relative; padding: 2px 0; border-radius: 6px; }
.hbar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 14px; display: flex; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.tip {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; pointer-events: none;
  background: var(--text); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 6px; opacity: 0; transition: opacity .12s;
  width: max-content; max-width: min(280px, 70vw);
}
.hbar:hover .tip, .hbar:focus .tip, .col:hover .tip, .col:focus .tip { opacity: 1; }
.hbar:hover, .hbar:focus { background: var(--surface-2); outline-offset: 2px; }
.cols-wrap { display: grid; grid-template-columns: 36px 1fr; gap: 6px; }
.cols-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); text-align: right; height: 160px; }
.cols { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.col { position: relative; display: grid; grid-template-rows: 160px auto; gap: 4px; border-radius: 4px; }
.col-track { display: flex; align-items: flex-end; border-bottom: 1px solid var(--border); }
.col-fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.col-label { font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; }
.col:hover .col-fill, .col:focus .col-fill { filter: brightness(1.15); }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-weight: 600;
  max-width: calc(100vw - 32px);
}
footer { max-width: 1320px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar-inner { gap: 8px; }
  .tabs a { padding: 6px 8px; font-size: 13px; }
  .hbar { grid-template-columns: 90px 1fr 56px; }
  dl.meta { grid-template-columns: 90px 1fr; }
}

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  @page { margin: 14mm; }
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  .topbar, main, footer, .toast, dialog { display: none !important; }
  #print-area { display: block; }
  .pq-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; border-bottom: 2px solid #1f5fbf; padding-bottom: 10px; margin-bottom: 14px; }
  .pq-head img { max-height: 60px; max-width: 220px; }
  .pq-company { font-size: 9pt; color: #333; white-space: pre-line; }
  .pq-company strong { font-size: 13pt; color: #000; }
  .pq-title { text-align: right; }
  .pq-title h1 { font-size: 18pt; color: #1f5fbf; }
  .pq-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; font-size: 9.5pt; margin-bottom: 14px; }
  .pq-meta > div { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
  .pq-meta span { color: #555; }
  .pq-meta b { font-weight: 600; }
  #print-area table { font-size: 9.5pt; }
  #print-area th, #print-area td { border-bottom: 1px solid #ccc; padding: 4px 6px; color: #000; }
  .pq-notes { margin-top: 14px; font-size: 9pt; color: #333; white-space: pre-line; }
  .pq-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
  .pq-photos figure { margin: 0; break-inside: avoid; }
  .pq-photos img { width: 100%; max-height: 55mm; object-fit: cover; }
  .pq-photos figcaption { font-size: 8pt; color: #333; }
  .pq-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
  .pq-sign div { border-top: 1px solid #000; padding-top: 4px; font-size: 9pt; }
  tr { break-inside: avoid; }
}

/* ---------- utilities (no inline styles: the CSP forbids them) ---------- */
.sub-h { margin: 16px 0 8px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.w-auto { width: auto; }
.w-240 { width: 240px; max-width: 100%; }
.w-260 { width: 260px; max-width: 100%; }
