/* ------------------------------------------------------------------
   Shipment Tracker — styles
   ------------------------------------------------------------------ */
:root {
  --ink: #0f1b2d;
  --ink-2: #16243a;
  --text: #1a2233;
  --muted: #64708a;
  --line: #e3e8ef;
  --bg: #f4f6f9;
  --card: #ffffff;
  --accent: #0f766e;
  --accent-ink: #0b5d57;
  --accent-soft: #e0f2f0;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  --sidebar-w: 220px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 11h12v10H7zM19 14h4l3 3v4h-7z' fill='none' stroke='%23fff' stroke-width='2' stroke-linejoin='round'/%3E%3Ccircle cx='11' cy='22' r='2' fill='%23fff'/%3E%3Ccircle cx='23' cy='22' r='2' fill='%23fff'/%3E%3C/svg%3E") center/100% no-repeat;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 10% -10%, #d7ebe8 0%, transparent 60%),
    radial-gradient(800px 500px at 110% 110%, #dfe7f3 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 32px 32px 24px;
}
.login-card .brand { margin-bottom: 24px; }
.login-hint { margin: 18px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #dbe3ee; padding: 20px 16px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand-sub { color: #8ea0b8; }
.sidebar .brand-name { color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #c3cedd; font-weight: 500;
}
.nav a:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(15, 118, 110, .35); color: #fff; }
.ico { width: 18px; height: 18px; flex: none; opacity: .9; background: currentColor; -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.ico-dash { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3h8v8H3zM13 3h8v5h-8zM13 10h8v11h-8zM3 13h8v8H3z' fill='%23000'/%3E%3C/svg%3E"); }
.ico-box { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 2 7v10l10 5 10-5V7L12 2zm0 2.2 7.5 3.8L12 11.8 4.5 8 12 4.2zM4 9.6l7 3.5v7.2l-7-3.5V9.6zm9 10.7v-7.2l7-3.5v7.2l-7 3.5z' fill='%23000'/%3E%3C/svg%3E"); }
.ico-clock { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm0 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16zm-1 3h2v5.4l3.6 2.1-1 1.7L11 13.5V7z' fill='%23000'/%3E%3C/svg%3E"); }
.ico-users { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm0 2c-3.3 0-7 1.7-7 4v3h14v-3c0-2.3-3.7-4-7-4zm8-2a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 2c-.5 0-1 .1-1.5.2 1.5 1 2.5 2.3 2.5 3.8v3h5v-3c0-2.2-3.3-4-6-4z' fill='%23000'/%3E%3C/svg%3E"); }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: grid; place-items: center; flex: none; }
.user-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.user-role { font-size: 12px; color: #8ea0b8; }
.sidebar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sidebar .btn-ghost { color: #c3cedd; border-color: rgba(255,255,255,.14); }
.sidebar .btn-ghost:hover { background: var(--ink-2); color: #fff; }

.main { padding: 28px 24px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards / grid ---------- */
.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); gap: 12px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi .kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi.tone-ok .kpi-value { color: var(--ok); }
.kpi.tone-warn .kpi-value { color: var(--warn); }
.kpi.tone-danger .kpi-value { color: var(--danger); }
.kpi.tone-accent .kpi-value { color: var(--accent-ink); }

/* ---------- Bars ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr auto; align-items: center; gap: 12px; font-size: 13px; }
.bar-row .bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; background: #eef1f5; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-fill.soft { background: #8ec7c0; }
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px; line-height: 1.2; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f6f8fb; border-color: #cfd7e2; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { background: #fff; border-color: #f3c0c0; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #e9a3a3; }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #eef1f5; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; font: inherit; cursor: pointer; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 600; color: #3a475c; }
.field .req::after { content: " *"; color: var(--danger); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"],
input[type="email"], input[type="search"], input[type="tel"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid #cfd7e2; border-radius: 8px;
  padding: 8px 10px; outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
input[aria-invalid="true"] { border-color: var(--danger); }
select { padding-right: 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.form-note { background: var(--info-soft); color: var(--info); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid #cfd7e2; border-radius: 8px; overflow: hidden; }
.seg label { padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); background: #fff; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + label { background: var(--accent-soft); color: var(--accent-ink); }
.seg label + input + label { border-left: 1px solid #cfd7e2; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1 1 220px; }
.toolbar select, .toolbar input { width: auto; min-width: 140px; }
.toolbar input[type="search"] { min-width: 240px; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th:first-child, .tbl td:first-child { padding-left: 14px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 14px; }
.tbl th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  background: #f8fafc; position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ind { opacity: .5; margin-left: 4px; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl td.actions { white-space: nowrap; text-align: right; }
.tbl td.actions .btn { margin-left: 4px; }
.tbl tfoot td { font-weight: 600; background: #f8fafc; }
.tbl .empty { text-align: center; padding: 36px; color: var(--muted); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef1f5; color: var(--muted); }
.badge-owner { background: #ede9fe; color: #5b21b6; }
.badge-admin { background: var(--info-soft); color: var(--info); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #eef1f5; color: #3a475c; white-space: nowrap; }
.chip-yes { background: var(--ok-soft); color: var(--ok); }
.chip-no { background: var(--warn-soft); color: var(--warn); }
.chip-hcl { background: var(--info-soft); color: var(--info); }
.chip-nv { background: #ede9fe; color: #5b21b6; }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 27, 45, .45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .12s ease-out; }
.overlay.drawer { place-items: stretch end; padding: 0; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.modal.wide { max-width: 760px; }
.drawer .modal { max-width: 640px; height: 100vh; max-height: 100vh; border-radius: 0; animation: slide .18s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px; overflow: auto; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 14px 14px; }
.modal-foot .spacer { flex: 1; }
.btn-close { border: none; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.btn-close:hover { background: #eef1f5; color: var(--text); }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes slide { from { transform: translateX(30px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- Read-only view ---------- */
.view-summary { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 12px; padding: 14px 16px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 18px; align-items: start; }
.view-amount { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--accent-ink); }
.view-section { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.detail-grid .span-2 { grid-column: span 2; }
.detail-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.detail-value { font-size: 14px; color: var(--text); word-break: break-word; }
@media (max-width: 900px) {
  .view-summary { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .span-2 { grid-column: auto; }
}

/* ---------- History list ---------- */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history li { padding: 10px 12px; background: #f8fafc; border-radius: 8px; font-size: 13px; }
.history .when { color: var(--muted); font-size: 12px; }
.history .diff { margin-top: 4px; font-size: 12.5px; color: #3a475c; }
.history .diff b { font-weight: 600; }
.history .diff s { color: var(--muted); }

/* ---------- Activity ---------- */
.act-row { display: grid; grid-template-columns: 160px 110px 1fr; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.act-row:last-child { border-bottom: none; }
.act-row .who { font-weight: 600; }
.act-row .when { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.act-row details { margin-top: 4px; }
.act-row summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.act-row pre { font-size: 12px; background: #f8fafc; padding: 8px 10px; border-radius: 6px; overflow: auto; margin: 6px 0 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: pop .15s ease-out; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* ---------- Import results ---------- */
.import-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.import-summary div { background: #f8fafc; border-radius: 8px; padding: 10px; text-align: center; }
.import-summary b { display: block; font-size: 20px; }
.import-summary .ok b { color: var(--ok); }
.import-summary .warn b { color: var(--warn); }
.import-summary .err b { color: var(--danger); }
.dropzone { border: 2px dashed #cfd7e2; border-radius: 10px; padding: 24px; text-align: center; color: var(--muted); background: #fafbfc; }
.dropzone.has-file { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.dropzone input { display: none; }

.skeleton { color: var(--muted); padding: 40px; text-align: center; }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; }
  .sidebar .brand-sub { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 7px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; border: none; padding: 0; flex-direction: row; align-items: center; }
  .user-meta { display: none; }
  .main { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .bar-row { grid-template-columns: 110px 1fr auto; }
  .act-row { grid-template-columns: 1fr; gap: 2px; }
  .import-summary { grid-template-columns: repeat(2, 1fr); }
  .drawer .modal { max-width: 100%; }
}
@media print {
  .sidebar, .toolbar, .page-actions, .table-foot, td.actions, th.actions { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
