:root {
  --navy: #0b1f3a;
  --navy-2: #13294b;
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #eef2f7;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --green: #16a34a; --green-soft: #e7f6ec;
  --amber: #d97706; --amber-soft: #fdf3e2;
  --red: #dc2626; --red-soft: #fdecec;
  --violet: #7c3aed; --violet-soft: #f1ebfe;
  --sky: #0284c7; --sky-soft: #e5f4fc;
  --slate-soft: #eef1f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, .18);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.ic { flex: none; vertical-align: middle; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--ink-2); transition: background .12s, border-color .12s, box-shadow .12s; white-space: nowrap; }
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:focus-visible, .input:focus, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #fecaca; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(148, 163, 184, .15); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: default; }
.input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 11px; transition: border-color .12s, box-shadow .12s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); outline: none; }
textarea.input { min-height: 70px; resize: vertical; }
.input.money { text-align: right; font-variant-numeric: tabular-nums; }
label.field { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
label.field .input { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink); font-size: 14px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #0e7490 0%, transparent 55%), var(--navy); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 36px 32px 28px; box-shadow: var(--shadow-lg); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand img { width: 44px; height: 44px; }
.login-brand h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.login-card form { display: grid; gap: 16px; }
.login-card .btn.primary { justify-content: center; padding: 11px; font-size: 15px; }
.login-error { background: var(--red-soft); color: var(--red); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.login-foot { margin-top: 20px; text-align: center; color: var(--muted); font-size: 12px; display: flex; gap: 6px; justify-content: center; align-items: center; }

/* ---------- Shell ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--navy); color: #e2e8f0; display: flex; align-items: center; gap: 14px; padding: 0 22px; height: 60px; box-shadow: 0 2px 10px rgba(2, 6, 23, .25); }
.topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em; cursor: pointer; text-decoration: none; }
.topbar .brand img { width: 30px; height: 30px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: #94a3b8; font-size: 14px; min-width: 0; }
.crumbs b { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.userchip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #2563eb); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.role { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; }
.role.admin { background: rgba(250, 204, 21, .18); color: #fde68a; }
.role.user { background: rgba(148, 163, 184, .2); color: #cbd5e1; }
.topbar .btn.ghost { color: #cbd5e1; }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.page { max-width: 1440px; margin: 0 auto; padding: 26px 22px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-head h2 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }

/* ---------- Hub ---------- */
.hub-hello { margin-bottom: 22px; }
.hub-hello h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.hub-hello p { margin: 6px 0 0; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tile { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 22px; min-height: 170px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); cursor: pointer; text-align: left; transition: transform .15s, box-shadow .15s, border-color .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(15, 23, 42, .1); border-color: #cbd5e1; }
.tile.soon { cursor: default; opacity: .75; }
.tile.soon:hover { transform: none; box-shadow: var(--shadow); }
.tile-icon { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.tile h3 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.tile p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.tile .tile-stat { margin-top: auto; display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); }
.tile .tile-stat b { font-size: 16px; }
.tile .badge-soon { position: absolute; top: 18px; right: 18px; font-size: 11px; font-weight: 700; color: var(--muted); background: var(--slate-soft); padding: 3px 8px; border-radius: 999px; }
.hub-grid { display: grid; grid-template-columns: 1fr; gap: 20px; margin-top: 26px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: flex-start; text-align: left; width: 100%; font: inherit; color: inherit; }
button.kpi { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
button.kpi:hover { border-color: #93c5fd; transform: translateY(-1px); }
button.kpi.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 13px; padding: 5px 6px 5px 11px; border-radius: 999px; border: 0; cursor: pointer; }
.filter-chip:hover { background: #dbe7fd; }
details.collapsible > summary { list-style: none; cursor: pointer; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary .chev { transition: transform .15s; color: var(--muted); }
details.collapsible[open] > summary .chev { transform: rotate(90deg); }
details.collapsible:not([open]) > summary { border-bottom: 0; }
.kpi .kpi-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.kpi .kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 24px; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; }
.kpi .kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.money .kpi-value { color: var(--ink); }
.tone-blue { background: var(--accent-soft); color: var(--accent); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-sky { background: var(--sky-soft); color: var(--sky); }
.tone-slate { background: var(--slate-soft); color: var(--ink-2); }

/* ---------- Timeline ---------- */
.timeline { padding: 18px 22px 22px; }
.tl-track { position: relative; height: 150px; margin: 0 6px; }
.tl-axis { position: absolute; left: 0; right: 0; top: 64px; height: 4px; border-radius: 4px; background: linear-gradient(90deg, #cbd5e1, #e2e8f0); }
.tl-tick { position: absolute; top: 132px; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.tl-tick::before { content: ''; position: absolute; left: 50%; top: -66px; width: 1px; height: 10px; background: #94a3b8; }
.tl-today { position: absolute; top: 40px; bottom: 24px; width: 2px; background: var(--accent); }
.tl-today span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.tl-ship { position: absolute; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.tl-ship .dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px currentColor; background: currentColor; }
.tl-ship .lbl { font-size: 11px; font-weight: 650; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px 7px; white-space: nowrap; box-shadow: var(--shadow); color: var(--ink); }
.tl-ship .lbl small { display: block; color: var(--muted); font-weight: 500; }
.tl-ship.up { bottom: 77px; flex-direction: column-reverse; }
.tl-ship.up .lbl { margin-bottom: 6px; }
.tl-ship.down { top: 59px; }
.tl-ship.down .lbl { margin-top: 6px; }
.tl-ship:hover .lbl { border-color: currentColor; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.seg { display: inline-flex; background: var(--slate-soft); padding: 3px; border-radius: 11px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.seg .count { font-size: 11px; background: rgba(100, 116, 139, .15); padding: 1px 6px; border-radius: 999px; }
.seg button.on .count { background: var(--accent-soft); color: var(--accent); }
.searchbox { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.searchbox .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbox .input { padding-left: 34px; }
.toolbar select.input { width: auto; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
.grid td.small { max-width: 160px; }
.grid td { padding: 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.grid tbody tr { cursor: pointer; transition: background .1s; }
.grid tbody tr:hover { background: #f8fbff; }
.grid tbody tr.sel { background: var(--accent-soft); }
.grid th.r, .grid td.r { text-align: right; }
.grid .money-col { background: #fffdf5; }
.grid th.money-col { background: #fdf8e8; }
.ship-title { font-weight: 650; }
.ship-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ship-type { display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 700; letter-spacing: .03em; color: var(--ink-2); background: var(--slate-soft); border: 1px solid var(--line); padding: 1px 7px; border-radius: 6px; }
.vessel { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.vessel a { color: var(--ink-2); }
.date-main { font-weight: 600; white-space: nowrap; }
.date-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chip .d { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-in_production { background: var(--violet-soft); color: var(--violet); }
.st-awaiting_departure { background: var(--amber-soft); color: var(--amber); }
.st-on_water { background: var(--sky-soft); color: var(--sky); }
.st-arrived { background: var(--green-soft); color: var(--green); }
.st-delivered { background: var(--slate-soft); color: var(--muted); }
.soon-chip { background: var(--amber-soft); color: var(--amber); }
.late-chip { background: var(--red-soft); color: var(--red); }
.docs { display: inline-flex; gap: 3px; flex-wrap: nowrap; }
.doc { min-width: 28px; height: 24px; padding: 0 5px !important; white-space: nowrap; border-radius: 8px; display: grid; place-items: center; border: 1px dashed #cbd5e1; color: #94a3b8; background: #fff; cursor: pointer; padding: 0; font-size: 10px; font-weight: 700; }
.doc.yes { border: 1px solid #bbf7d0; background: var(--green-soft); color: var(--green); }
.doc.partial { border: 1px solid #fde68a; background: var(--amber-soft); color: var(--amber); }
.doc:hover { transform: scale(1.08); }
.doc[disabled] { cursor: default; transform: none; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
.owed { color: var(--red); font-weight: 650; }
.cards-mobile { display: none; }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--bg); z-index: 41; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.drawer-head { background: #fff; padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.drawer-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 30px; display: grid; gap: 16px; align-content: start; }
.drawer-foot { background: #fff; border-top: 1px solid var(--line); padding: 12px 22px; display: flex; gap: 8px; align-items: center; }
.drawer-foot .spacer { flex: 1; }
.group { padding: 16px 18px 18px; }
.group h3 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.group.money { border-color: #f5e6b8; background: #fffdf6; }
.group.money h3::after { content: 'Admin only'; font-size: 10px; letter-spacing: .05em; background: rgba(250, 204, 21, .25); color: #92400e; padding: 2px 7px; border-radius: 999px; margin-left: auto; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.fgrid .wide { grid-column: 1 / -1; }
.checks { display: grid; gap: 8px; }
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.check-row span { font-weight: 600; }
.check-row .seg button { padding: 4px 10px; font-size: 12px; }
.check-row .seg button.on.v-yes { color: var(--green); }
.check-row .seg button.on.v-partial { color: var(--amber); }
.pay-table { width: 100%; border-collapse: collapse; }
.pay-table th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 0 6px 6px; }
.pay-table td { padding: 3px; }
.pay-table .input { padding: 7px 8px; }
.pay-table tfoot td { padding-top: 10px; font-weight: 700; }
.history { display: grid; gap: 2px; }
.hist-item { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.hist-item:last-child { border-bottom: 0; }
.hist-ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--slate-soft); color: var(--muted); }
.hist-ic.ai { background: var(--violet-soft); color: var(--violet); }
.hist-meta { font-size: 12px; color: var(--muted); }
.hist-changes { font-size: 13px; margin-top: 3px; color: var(--ink-2); }
.hist-changes s { color: var(--muted); }
.dirty-note { color: var(--amber); font-weight: 600; font-size: 13px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; align-items: start; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 10px; word-break: break-all; }
.notice { background: var(--amber-soft); color: #92400e; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.form-row { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.form-row .input { flex: 1; min-width: 120px; }
.fx-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 16px 18px; }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal .scrim { z-index: 0; }
.modal-card { position: relative; z-index: 1; background: #fff; border-radius: 16px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal-card .card-head { position: sticky; top: 0; background: #fff; }
.modal-body { padding: 16px 18px; display: grid; gap: 12px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: all .2s; z-index: 80; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .brand span, .userchip .uname { display: none; }
  .page { padding: 18px 14px 50px; }
  .table-wrap { display: none; }
  .cards-mobile { display: grid; gap: 10px; padding: 12px; }
  .m-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; display: grid; gap: 8px; cursor: pointer; }
  .m-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
  .fgrid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; flex-direction: column; gap: 8px; }
  .kpi .kpi-value { font-size: 20px; }
  .timeline { overflow-x: auto; }
  .tl-track { min-width: 900px; }
  .page-head h1 { font-size: 22px; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
