:root {
  --navy: #0b3c5d;
  --navy-soft: #e3ebf1;
  --orange: #f28c28;
  --orange-soft: #fdebd8;
  --teal: #1d7874;
  --teal-soft: #dcefed;
  --green: #2e7d4f;
  --green-soft: #e1f2e7;
  --red: #b3261e;
  --red-soft: #fbe4e2;
  --text: #0b2a3c;
  --muted: #5f7180;
  --line: #dde4ea;
  --bg: #f5f7f9;
  --card: #ffffff;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.5; background: var(--bg); }
a { color: var(--navy); }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.small { font-size: 13px; }

/* --- top bar --- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
/* Every page of the test site (TEST_SITE=true) starts with this, so nobody takes it for the real one. */
.test-banner { background: repeating-linear-gradient(45deg, #fde68a, #fde68a 12px, #fcd34d 12px, #fcd34d 24px); color: #78350f; font-weight: 600; text-align: center; padding: 6px 14px; font-size: 14px; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; height: 56px; }
.brand { font-weight: 700; color: var(--navy); text-decoration: none; font-size: 17px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--orange); color: #fff; font-size: 12px; text-align: center; margin-left: 4px; }

@media (max-width: 1100px) {
  .topbar-inner { gap: 12px; padding: 0 14px; }
  .nav a { padding: 8px 8px; }
  .user .username { display: none; }
}
@media (max-width: 860px) { .brand { font-size: 15px; } .nav { gap: 0; } }

.page { max-width: 1320px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* --- cards and grids --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 960px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 960px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.kpi:hover { border-color: var(--navy); }
.kpi.active { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }
.kpi .num { font-size: 26px; font-weight: 700; color: var(--navy); }
.kpi .label { font-size: 13px; color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 20px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.facts dd { margin: 2px 0 0; font-weight: 500; word-break: break-word; }

/* --- badges --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.pre_departure { background: var(--navy-soft); color: var(--navy); }
.badge.in_transit { background: var(--teal-soft); color: var(--teal); }
.badge.at_destination { background: var(--orange-soft); color: #8a4b0f; }
.badge.delivered { background: var(--green-soft); color: var(--green); }
.badge.sea, .badge.air, .badge.express, .badge.unknown { background: #eef1f4; color: var(--muted); }
.badge.warn { background: var(--orange-soft); color: #8a4b0f; }
.badge.danger { background: var(--red-soft); color: var(--red); }
.badge.ok { background: var(--green-soft); color: var(--green); }
.est { color: var(--muted); font-size: 12px; font-style: italic; }

/* --- tables --- */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafcfd; }
table.list td.num, table.list th.num { text-align: right; }
.ci { font-family: var(--mono); font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* --- forms and buttons --- */
input[type=text], input[type=search], input[type=date], input[type=url], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
textarea { width: 100%; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy-soft); border-color: var(--navy); }
.search { width: 100%; max-width: 520px; font-size: 16px; padding: 10px 14px; }
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: #082d46; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--muted); font-size: 14px; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 36px; text-align: center; background: #fff; }
.dropzone.drag { border-color: var(--navy); background: var(--navy-soft); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: var(--navy-soft); }
.messages li.success { background: var(--green-soft); }
.messages li.warning, .messages li.error { background: var(--orange-soft); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .when { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.timeline li.estimated .what { color: var(--muted); }

.empty { padding: 28px; text-align: center; color: var(--muted); }
.callout { padding: 12px 14px; border-radius: 8px; background: var(--orange-soft); }
.callout.ok { background: var(--green-soft); }

/* --- grid page (Tabulator) --- */
#grid { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.tabulator { font-size: 14px; }
.tabulator .tabulator-header .tabulator-col { background: #fafbfc; }
.tabulator .tabulator-row .tabulator-cell.editable { background: #fff6dd; }
.tabulator .tabulator-row:hover .tabulator-cell.editable { background: #ffefc2; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: .95; pointer-events: auto; }
.toast-action { margin-left: 10px; font: inherit; font-weight: 600; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.6); border-radius: 6px; padding: 2px 10px; cursor: pointer; }
.toast-action:hover { background: rgba(255,255,255,.15); }
form.inline { display: inline; }

/* --- page pieces added with the templates --- */
input[type=password], input[type=email] { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.login-card { max-width: 400px; margin: 48px auto; }
.login-card input { width: 100%; }
.btn.wide { width: 100%; }
.top-gap { margin-top: 12px; }
.top-gap-lg { margin-top: 32px; }
.toolbar.flush { margin-bottom: 0; }
.search.narrow { width: 260px; max-width: 100%; }
.pre { white-space: pre-line; }
.strike { text-decoration: line-through; }
.ok-text { color: var(--green); }
details > summary { cursor: pointer; color: var(--navy); font-weight: 600; }
.stack-tight > * + * { margin-top: 8px; }

/* view chips on the board are radio buttons inside the filter form */
label.kpi { cursor: pointer; position: relative; }
label.kpi input { position: absolute; opacity: 0; pointer-events: none; }
label.kpi:has(input:checked) { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); background: var(--navy-soft); }
label.kpi:has(input:focus-visible) { outline: 2px solid var(--orange); }
.kpi .num, .kpi .label { display: block; }
.kpi.static:hover { border-color: var(--line); }

.totals { margin-bottom: 16px; }
.results-meta { margin: 0 0 8px; }
table.list.compact th, table.list.compact td { padding: 7px 10px; }
table.list tfoot th { background: #fafbfc; border-top: 1px solid var(--line); color: var(--text); font-size: 13px; text-transform: none; }
table.list td.date { white-space: nowrap; }
table.board td { font-size: 14px; }

/* shipment page */
.todo { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card.highlight { border-color: var(--orange); box-shadow: inset 0 0 0 1px var(--orange); }
.edit-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.edit-grid .span-all { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.edit-grid input, .edit-grid select { width: 100%; }
h3.kind { margin: 14px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.doc-list li:last-child { border-bottom: none; }
.kind-form { margin-left: auto; }
.kind-form select { padding: 2px 6px; font-size: 12px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.history li:last-child { border-bottom: none; }
.history .when { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.compact-facts { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 14px; }
.compact-facts dd { font-size: 13px; }

/* uploads */
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.dropzone input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone.small-zone { padding: 18px; }
.picked { color: var(--navy); font-weight: 600; word-break: break-word; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { display: none; }
.steps-list { margin: 0; padding-left: 20px; }
.steps-list li + li { margin-top: 8px; }
@media (max-width: 720px) { .edit-grid { grid-template-columns: 1fr; } }

.error-text { color: var(--red); }

/* AI readings: always shown as suggestions */
.badge.ai { background: #ede7f6; color: #5e35b1; }
.ai-note { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: #f6f3fb; }
.ai-summary { justify-content: space-between; }
.warn-text { color: #8a4b0f; }

/* the Table page: the box for a new shipment, and the row it adds */
.new-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; padding: 10px 14px; }
.new-row input[type=text] { width: 300px; max-width: 100%; }
.tabulator .tabulator-row.row-new .tabulator-cell { background: #fff1c1; transition: background 1s; }
/* goods lines under a shipment on the Table page: their goods cells are typed (yellow); the
   shipment's own columns are typed on the shipment's row only */
.tabulator .tabulator-row.line-row .tabulator-cell { background: #f7f9fb; font-size: 13px; }
.tabulator .tabulator-row.line-row .tabulator-cell.editable { background: #f7f9fb; }
.tabulator .tabulator-row.line-row .tabulator-cell.goods { background: #fff6dd; }
.tabulator .tabulator-row.line-row:hover .tabulator-cell.goods { background: #ffefc2; }
.tabulator .tabulator-cell .btn.small { padding: 1px 8px; font-size: 12px; line-height: 1.4; }

/* the journey at the top of a shipment: origin port, stops, destination port, customs, warehouse, POD */
.journey { display: grid; grid-template-columns: repeat(var(--steps, 6), minmax(0, 1fr)); gap: 0; margin-bottom: 16px; padding: 20px 24px; }
.journey-step { position: relative; padding: 22px 14px 0 0; min-width: 0; overflow-wrap: anywhere; }
.journey-step .dot { position: absolute; top: 0; left: 0; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--line); z-index: 1; }
.journey-step::before { content: ""; position: absolute; top: 5px; left: 14px; right: 0; height: 4px; background: var(--line); }
.journey-step:last-child::before { display: none; }
.journey-step.done .dot { background: var(--teal); border-color: var(--teal); }
.journey-step.done::before { background: var(--teal); }
.journey-step.probable .dot { background: #fff; border-style: dashed; }
.journey-step.probable::before { background: repeating-linear-gradient(90deg, var(--teal) 0 6px, transparent 6px 10px); }
.journey-step.current .dot { border-color: var(--orange); background: var(--orange-soft); }
.journey-step .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.journey-step.current .label { color: #8a4b0f; font-weight: 700; }
.journey-step .place { font-weight: 700; color: var(--navy); margin: 2px 0 4px; }
.journey-step .lines { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: baseline; }
.journey-step .lines .day { white-space: nowrap; }
.journey-step .lines .wide { grid-column: 1 / -1; }
.journey-step .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
@media (max-width: 900px) { .journey { grid-template-columns: 1fr; gap: 16px; } .journey-step::before { display: none; } }

.badge.sample { background: #fff1c1; color: #7a5a00; }
.facts .wide, .edit-grid .wide { grid-column: 1 / -1; }

/* the four papers on a shipment page */
.checklist { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.checklist li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 10px; border-radius: 8px; background: var(--bg); overflow-wrap: anywhere; }
.checklist .mark { width: 18px; text-align: center; font-weight: 700; }
.checklist li.have .mark { color: var(--teal); }
.checklist li.missing .mark { color: var(--orange); }
.checklist li.not-needed { color: var(--muted); }
.checklist form { margin-left: auto; }

/* private files and the preview page */
.badge.private { background: #efe6f7; color: #5b2a86; }
.preview-title { overflow-wrap: anywhere; }
.preview-frame { display: block; width: 100%; height: 78vh; border: 0; border-radius: 6px; background: #f4f6f8; }
.preview-picture { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.preview-sheet { max-height: 70vh; overflow: auto; }
.preview-sheet td { white-space: nowrap; font-size: 13px; }
.preview-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 70vh; overflow: auto; margin: 0; font-size: 13px; }

/* The "Ask AI" panel (templates/base.html, static/js/assistant.js). */
.assistant-open { position: fixed; right: 20px; bottom: 20px; z-index: 40; border: 0; border-radius: 999px; padding: 10px 18px; background: var(--navy); color: #fff; font: inherit; font-weight: 600; box-shadow: 0 4px 14px rgba(11, 60, 93, 0.25); cursor: pointer; }
.assistant-open[hidden] { display: none; }
.assistant { position: fixed; right: 20px; bottom: 20px; z-index: 41; display: flex; flex-direction: column; width: 400px; max-width: calc(100vw - 24px); height: 70vh; max-height: 640px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); }
.assistant[hidden] { display: none; }
.assistant-head { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.assistant-head .muted { grid-column: 1 / -1; }
.assistant-actions { display: flex; gap: 6px; }
.assistant-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; }
.assistant-msg { max-width: 92%; line-height: 1.45; }
.assistant-msg.user { align-self: flex-end; padding: 8px 12px; border-radius: 12px 12px 2px 12px; background: var(--navy-soft); white-space: pre-wrap; }
.assistant-msg.reply p { margin: 0 0 6px; }
.assistant-msg.reply ul { margin: 0 0 6px; padding-left: 18px; }
.assistant-msg.pending { color: var(--muted, #6b7785); font-style: italic; }
.assistant-msg.error { color: #a32020; }
.assistant-form { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.assistant-form textarea { resize: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.assistant-choice { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.assistant-level { display: inline-flex; flex-shrink: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.assistant-level label { padding: 2px 10px; font-size: 0.85em; cursor: pointer; }
.assistant-level input { position: absolute; opacity: 0; pointer-events: none; }
.assistant-level label:has(input:checked) { background: var(--navy); color: #fff; }
.assistant-level label:has(input:focus-visible) { outline: 2px solid var(--orange); outline-offset: -2px; }
@media (max-width: 640px) {
  .assistant { left: 0; right: 0; bottom: 0; width: auto; max-width: none; height: 85vh; border-radius: 12px 12px 0 0; }
}
