/* BluePearl CargoTrack — portal styles. Brand colours come from Settings (see brand_css()). */
:root {
  --red: #1d4ed8;          /* brand colour: buttons, active menu, accents (set in Settings) */
  --brand-rgb: 29,78,216;
  --sidebar: #0b1220;
  --red-dark: #b01217;
  --red-soft: #fdecec;
  --ink: #111111;          /* sidebar, headings */
  --text: #1f2328;
  --muted: #5f6670;
  --line: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ok: #15803d;  --ok-soft: #e8f6ec;
  --warn: #b45309; --warn-soft: #fff4e0;
  --orange: #ea580c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --side: 248px;
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.85rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
small, .muted { color: var(--muted); }
.ico { flex: none; vertical-align: middle; }
:focus-visible { outline: 3px solid rgba(var(--brand-rgb),.35); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--sidebar); color: #e7e7e7;
  display: flex; flex-direction: column; padding: 18px 14px; z-index: 40; overflow-y: auto;
}
.sidebar .brand { display: block; padding: 4px 8px 16px; }
.sidebar .brand img { display: block; width: 132px; height: auto; }
.me { display: flex; gap: 10px; align-items: center; background: #161616; border-radius: 12px; padding: 12px; margin-bottom: 18px; }
.me-ico { color: #fff; }
.me b { display: block; color: #fff; font-size: .95rem; }
.me small { display: block; color: #a3a3a3; font-size: .75rem; word-break: break-all; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; color: #d4d4d4; padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
.nav a:hover { background: #1a1a1a; color: #fff; text-decoration: none; }
.nav a.active { background: rgba(var(--brand-rgb), .22); color: #fff; box-shadow: inset 3px 0 0 var(--red); }
.nav a.active .ico { color: #fff; }
.nav .logout { margin-top: 8px; }
.main { min-height: 100vh; display: flex; flex-direction: column; }
.has-shell .main { margin-left: var(--side); }
.topbar { display: none; }
.content { flex: 1; width: 100%; max-width: 1320px; padding: 32px 36px 40px; margin: 0 auto; }
.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 36px; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }
.scrim { display: none; }

.pub-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.pub-top .brand img { display: block; width: 100px; height: auto; }
.pub-top nav { display: flex; gap: 16px; align-items: center; }
.pub-top nav a:not(.btn) { color: var(--ink); font-weight: 500; }

@media (max-width: 980px) {
  .has-shell .main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; background: var(--sidebar); color: #fff; padding: 10px 14px; }
  .topbar-title { font-weight: 700; flex: 1; }
  .topbar-user { font-size: .8rem; color: #bbb; }
  .content { padding: 20px 16px 32px; }
  .foot { padding: 14px 16px; }
}

/* ---------- Page heading ---------- */
.eyebrow { color: var(--red); font-size: .75rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 4px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 20px; }
.grid > .card, .grid > * > .card:first-child { margin-top: 0; }   /* cards side by side stay the same height */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
@media (max-width: 1400px) { .g-side { grid-template-columns: minmax(0, 1fr) 320px; } }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-side { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) {
  /* minmax(0, 1fr): a wide table or chart scrolls inside its card instead of widening the page */
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid { gap: 14px; }
  .card { padding: 16px; }
  .stat { padding: 16px 10px; }
  .stat b { font-size: 1.6rem; }
  .stat span { font-size: .82rem; }
  h1 { font-size: 1.5rem; }
  .page-head { margin-bottom: 16px; }
  .ship-no { font-size: 1.2rem; }
  .route { gap: 8px; }
  .facts, .trip-stats { gap: 8px; }
  .find-row .btn { padding: 6px 10px; }
  #routeMap { height: 300px; }
  .actions .btn { flex: 1 1 auto; }
  th, td { padding: 10px 8px; }
  .sticky-panel { position: static; }
  dialog { padding: 20px; }
}

.stat { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 22px 16px; color: var(--text); border: 1px solid transparent; transition: border-color .15s, transform .15s; }
a.stat:hover { text-decoration: none; border-color: #f3b7b9; transform: translateY(-1px); }
.stat .ico { color: var(--red); }
.stat b { font-size: 2rem; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.selected { border-color: var(--red); }
.stat-row { display: flex; align-items: center; gap: 14px; text-align: left; padding: 18px; }
.stat-row .stat-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--red-soft); color: var(--red); display: grid; place-items: center; flex: none; }
.stat-row b { display: block; font-size: 1.5rem; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat-row span { color: var(--muted); font-size: .85rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #6b7280; font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #fafafa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .86em; }
.nowrap { white-space: nowrap; }
.switch-form { display: inline; margin: 0; }
.toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: var(--text); }
.toggle .knob { width: 38px; height: 22px; border-radius: 999px; background: #d1d5db; position: relative; transition: background .15s; flex: none; }
.toggle .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.toggle.on .knob { background: var(--ok); }
.toggle.on .knob::after { left: 19px; }
.toggle[disabled] { cursor: not-allowed; opacity: .55; }
.cp-edit { border: 2px solid var(--red); }
.wide-cell { min-width: 220px; }

/* ---------- Badges, progress ---------- */
.badge { --c: #64748b; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap;
  color: color-mix(in srgb, var(--c) 80%, #000); background: color-mix(in srgb, var(--c) 13%, #fff); }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #f1f2f4; color: #374151; }
.pill-red { background: var(--red-soft); color: var(--red-dark); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.progress { height: 10px; background: #eceef1; border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, rgba(var(--brand-rgb), .55), var(--red)); border-radius: 999px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; color: var(--ink); }
.field { margin-bottom: 16px; }
.field small { display: block; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=tel], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid #d5d8dd; border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.15); }
input[readonly] { background: #f7f7f8; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.check input { width: 18px; height: 18px; accent-color: var(--red); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 700px) { .row2, .row3 { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; flex: 0 1 200px; }
.input-icon { position: relative; }
.input-icon .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; }
.input-icon input { padding-left: 40px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; font-size: .92rem; border-radius: 999px; padding: 10px 20px; min-height: 42px;
  border: 1px solid transparent; cursor: pointer; background: #111; color: #fff; text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.15); }
.btn-red { background: var(--red); }
.btn-red:hover { background: var(--red-dark); filter: none; }
.btn-ghost { background: #fff; color: var(--ink); border-color: #d5d8dd; }
.btn-ghost:hover { background: #f7f7f8; filter: none; }
.btn-danger { background: #fff; color: var(--red-dark); border-color: #f3b7b9; }
.btn-danger:hover { background: var(--red-soft); filter: none; }
.btn-sm { padding: 6px 14px; min-height: 34px; font-size: .84rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px; cursor: pointer; display: inline-grid; place-items: center; border-radius: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--red); font: inherit; cursor: pointer; }

/* ---------- Alerts, empty ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; border: 1px solid; font-weight: 500; }
.alert-ok { background: var(--ok-soft); border-color: #bfe5c9; color: #14532d; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.alert-warn { background: var(--warn-soft); border-color: #f6d9a6; color: #78350f; }
.alert ul { margin: 6px 0 0; padding-left: 18px; font-weight: 400; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ico { color: #c4c8ce; }
.empty-title { font-weight: 700; color: var(--ink); margin: 10px 0 4px; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); background: radial-gradient(1200px 600px at 0% 100%, rgba(var(--brand-rgb), .35) 0%, var(--sidebar) 55%); color: #fff; }
.login-left { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; color: var(--text); border-radius: 22px; padding: 32px; box-shadow: 0 30px 60px rgba(0,0,0,.35); }
.login-card .logo { display: block; width: 110px; margin-bottom: 18px; }
.login-card h1 { font-size: 1.6rem; }
.login-right { display: flex; flex-direction: column; justify-content: center; padding: 40px; gap: 18px; }
.login-right h2 { color: #fff; font-size: 2.1rem; font-weight: 800; max-width: 520px; }
.login-right p { color: #c9c4be; max-width: 520px; }
.dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) grayscale(.6); }
#loginMap { height: 300px; background: #111; border-radius: 16px; overflow: hidden; border: 1px solid #2a2a2a; }
.regions { display: flex; flex-wrap: wrap; gap: 6px 14px; color: #bbb; font-size: .85rem; }
.regions span::before { content: '●'; color: var(--red); margin-right: 6px; }
@media (max-width: 900px) { .login-page { grid-template-columns: 1fr; } .login-right { display: none; } }

/* ---------- Track ---------- */
.track-search { display: flex; gap: 10px; flex-wrap: wrap; }
.track-search .input-icon { flex: 1 1 320px; }
.ship-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.ship-no { font-size: 1.5rem; font-weight: 800; color: var(--ink); letter-spacing: .01em; }
.route { display: flex; align-items: center; gap: 14px; margin: 18px 0 12px; flex-wrap: wrap; }
.route .place b { display: block; font-size: 1.1rem; color: var(--ink); }
.route .place small { text-transform: uppercase; letter-spacing: .1em; font-size: .7rem; }
.route .arrow { flex: 1; min-width: 40px; height: 2px; background: repeating-linear-gradient(90deg, #d1d5db 0 8px, transparent 8px 14px); position: relative; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.facts div { background: #f7f7f8; border-radius: 12px; padding: 12px 14px; }
.facts small { display: block; text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; }
.facts b { color: var(--ink); font-weight: 600; word-break: break-word; }
@media (max-width: 800px) { .facts { grid-template-columns: 1fr 1fr; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 22px 30px; }
.timeline li::before { content: ''; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: #e5e7eb; }
.timeline li:last-child::before { display: none; }
.timeline .dot { position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid #cbd0d6; }
.timeline li:first-child .dot { border-color: var(--red); background: var(--red); box-shadow: 0 0 0 4px rgba(var(--brand-rgb),.15); }
.timeline .t-desc { font-weight: 600; color: var(--ink); }
.timeline .t-meta { color: var(--muted); font-size: .85rem; display: flex; gap: 6px 14px; flex-wrap: wrap; }

/* ---------- Fleet ---------- */
.fleet-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
#fleetMap { height: 640px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #e5e7eb; }
.vehicle-list { display: flex; flex-direction: column; gap: 10px; max-height: 640px; overflow-y: auto; padding-right: 4px; }
.vehicle { background: #fff; border-radius: 12px; padding: 14px; box-shadow: var(--shadow); cursor: pointer; border: 1px solid transparent; text-align: left; width: 100%; font: inherit; color: inherit; }
.vehicle:hover, .vehicle.active { border-color: var(--red); }
.vehicle .v-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.vehicle .plate { font-weight: 800; color: var(--ink); }
.vehicle .v-meta { color: var(--muted); font-size: .82rem; margin-top: 4px; display: flex; gap: 4px 12px; flex-wrap: wrap; }
.vehicle .waybill { color: var(--orange); font-weight: 600; font-size: .85rem; margin-top: 4px; }
.vehicle.nogps { opacity: .7; }
.fleet-count { background: #111; color: #fff; border-radius: 12px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; }
.fleet-count b { font-size: 1.6rem; }
@media (max-width: 1100px) { .fleet-layout { grid-template-columns: 1fr; } #fleetMap { height: 420px; } .vehicle-list { max-height: none; } }
/* Keep maps under the top bar and the phone menu (Leaflet's own layers use z-index 400+) */
.leaflet-container { z-index: 0; isolation: isolate; }
.leaflet-popup-content { font-family: 'Outfit', system-ui, sans-serif; font-size: 13px; }
.truck-pin { background: var(--red); color: #fff; border: 2px solid #fff; border-radius: 50%; width: 30px !important; height: 30px !important; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.truck-pin.idle { background: #111; }
.truck-pin.old { background: #9ca3af; }

/* ---------- Updates ---------- */
.sticky-panel { position: sticky; top: 20px; }
.sel-count { font-weight: 700; color: var(--red); }
.result-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 260px; overflow-y: auto; }
.result-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f0f1f3; font-size: .9rem; }
details.adv { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
details.adv summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }
dialog { border: 0; border-radius: 18px; padding: 26px; max-width: 480px; width: calc(100% - 32px); box-shadow: 0 30px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.5); }
#qrReader { width: 100%; }

/* ---------- Reports ---------- */
.chart-box { position: relative; height: 300px; }
.bar-cell { display: flex; align-items: center; gap: 10px; }
.bar-cell .bar-track { flex: 1; min-width: 40px; max-width: 220px; }
.bar-cell .bar { display: block; height: 8px; border-radius: 999px; background: var(--red); min-width: 2px; }

/* ---------- Route picker ---------- */
.find-row { display: flex; gap: 8px; }
.find-row input { flex: 1; }
.find-row input.is-loading { background: #f7f7f8 linear-gradient(90deg, transparent, rgba(var(--brand-rgb),.08), transparent) 0 0 / 200% 100%; animation: rp-load 1s linear infinite; }
@keyframes rp-load { to { background-position: -200% 0; } }
.route-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 10px; font-size: .88rem; }
#routeMap { height: 380px; border-radius: 12px; overflow: hidden; background: #e5e7eb; }
.route-summary { margin: 10px 0 0; padding: 10px 14px; background: #f7f7f8; border-radius: 10px; }
.route-results { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; max-height: 260px; overflow-y: auto; }
.route-hit { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid #f0f1f3; padding: 8px 6px; font: inherit; font-size: .9rem; cursor: pointer; color: var(--text); }
.route-hit:hover { background: #fff7f7; }
.trip-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.trip-stats div { background: #f7f7f8; border-radius: 12px; padding: 12px 14px; }
.trip-stats small { display: block; text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; color: var(--muted); }
.trip-stats b { color: var(--ink); }
@media (max-width: 800px) { .trip-stats { grid-template-columns: 1fr 1fr; } }

/* ---------- QR ---------- */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.qr-box #qr { background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--line); }
.qr-box #qr img, .qr-box #qr canvas { display: block; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; color: var(--muted); font-size: .9rem; }

/* ---------- Phones: rules that must come after the ones above ---------- */
@media (max-width: 700px) {
  .filters select, .filters input[type=search] { flex: 1 1 100%; width: 100%; }
  .filters .btn { flex: 1 1 auto; }
  .filters .check { flex: 1 1 auto; }
}

/* ---------- Print (Reports PDF) ---------- */
@media print {
  .sidebar, .topbar, .foot, .no-print, .scrim { display: none !important; }
  .has-shell .main { margin: 0; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .chart-box { height: 240px; }
}
