:root {
  --bg: #f8f9fa;
  --rail: #f1f4f8;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #b85012;
  --accent-hover: #9a410d;
  --accent-soft: #fdf2eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --r: 10px;
  --r-sm: 7px;
  --font: "Red Hat Text", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
::selection { background: rgba(184, 80, 18, 0.16); color: var(--ink); }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; caret-color: var(--accent);
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); font-size: 0.8125rem; }
.sub-line { color: var(--ink-2); font-size: 0.875rem; }

/* ==================== PUBLIC PORTAL (SIGN IN / REGISTER / TRACK / CONTACT) ==================== */
.portal-shell {
  min-height: 100svh; display: flex; flex-direction: column;
  background: var(--bg);
}
.portal-header {
  height: 60px; padding: 0 24px; border-bottom: 1px solid var(--line);
  background: var(--surface); display: flex; align-items: center; justify-content: space-between;
}
.brand-link { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 0.9375rem; color: var(--ink); }
.brand-link img { width: 28px; height: 28px; object-fit: contain; }
.portal-header-links { display: flex; align-items: center; gap: 16px; font-size: 0.875rem; color: var(--ink-2); }
.portal-header-links a:hover, .portal-header-links button:hover { color: var(--ink); }

.portal-main {
  flex: 1; display: grid; place-items: center; padding: 36px 20px 56px;
}
.portal-box {
  width: min(100%, 460px); background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; box-shadow: 0 8px 28px rgba(15, 23, 42, 0.04);
}
.portal-box--wide { width: min(100%, 580px); }

.seg-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--rail); padding: 4px; border-radius: 9px; margin-bottom: 24px;
}
.seg-tab {
  border: 0; background: transparent; color: var(--ink-2); font-size: 0.8125rem; font-weight: 500;
  padding: 8px 6px; border-radius: 6px; cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.seg-tab:hover { color: var(--ink); }
.seg-tab.is-active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08); }

.portal-title { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 6px; }
.portal-sub { font-size: 0.875rem; color: var(--muted); margin-bottom: 22px; }
.portal-foot {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 0.8125rem; color: var(--muted);
}
.text-link {
  background: none; border: 0; padding: 0; color: var(--ink); font-weight: 500; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong);
}
.text-link:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ==================== AUTHENTICATED APP SHELL ==================== */
.app-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100svh; }
.sidebar {
  background: var(--rail); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px;
  position: sticky; top: 0; height: 100svh; overflow-y: auto;
}
.sb-head { padding: 4px 8px 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.sb-nav { display: grid; gap: 2px; }
.sb-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; border: 0; background: transparent; color: var(--ink-2);
  padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; text-align: left;
  font-size: 0.875rem; font-weight: 500; transition: background 150ms ease, color 150ms ease;
}
.sb-btn:hover { background: rgba(15, 23, 42, 0.05); color: var(--ink); }
.sb-btn.is-active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06); }
.sb-count { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sb-btn.is-active .sb-count { color: var(--accent); }

.sb-foot {
  margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line);
  display: grid; gap: 8px;
}
.sb-user { padding: 4px 8px; }
.sb-user strong { display: block; font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.sb-user span { display: block; font-size: 0.75rem; color: var(--muted); }
.sb-actions { display: flex; gap: 6px; padding: 0 4px; }

.main-area { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar h1 { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle {
  display: none; width: 34px; height: 34px; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; color: var(--ink);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.content { padding: 24px; display: grid; gap: 24px; max-width: 1180px; width: 100%; }

/* ==================== FLAT METRIC STRIP (NO RAINBOW CARDS) ==================== */
.metric-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden;
}
.metric-strip--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-cell {
  padding: 18px 20px; display: grid; gap: 4px;
  border-right: 1px solid var(--line);
}
.metric-cell:last-child { border-right: 0; }
.metric-label { font-size: 0.75rem; font-weight: 500; color: var(--muted); }
.metric-val { font-size: 1.5rem; font-weight: 600; color: var(--ink); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric-sub { font-size: 0.75rem; color: var(--muted); }

/* ==================== SECTIONS & TABLES ==================== */
.section-block {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
}
.section-bar {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.section-bar h2 { font-size: 0.9375rem; font-weight: 600; color: var(--ink); }
.section-pad { padding: 18px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.75rem; font-weight: 500; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); font-size: 0.875rem; }

/* Subtle Status Indicators (Tiny Dot + Calm Text, No Rainbow Pills) */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8125rem; font-weight: 500; color: var(--ink); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status--ok::before { background: var(--ok); }
.status--active::before { background: var(--accent); }
.status--warn::before { background: var(--warn); }
.status--danger::before { background: var(--danger); }

/* ==================== SHIPMENT TRACKING RESULT & TIMELINE ==================== */
.track-bar { display: flex; gap: 8px; }
.track-bar input {
  flex: 1; min-width: 0; height: 36px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); font-size: 0.875rem; color: var(--ink);
}
.track-bar input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(184, 80, 18, 0.12); }
.track-card {
  margin-top: 20px; border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; background: var(--surface); display: grid; gap: 18px;
}
.track-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.track-code { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.track-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; padding: 14px 0; border-block: 1px solid var(--line); }
.track-meta dt { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.track-meta dd { margin: 0; font-size: 0.875rem; font-weight: 500; color: var(--ink); }

.track-steps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.track-step { display: grid; gap: 6px; }
.track-step-bar { height: 4px; border-radius: 99px; background: var(--line); }
.track-step.is-done .track-step-bar { background: var(--ink); }
.track-step.is-current .track-step-bar { background: var(--accent); }
.track-step span { font-size: 0.72rem; color: var(--muted); line-height: 1.25; }
.track-step.is-current span { color: var(--ink); font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.timeline li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 10px; align-items: start; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); margin-top: 6px; }
.timeline li:first-child .tl-dot { background: var(--accent); }
.tl-title { font-size: 0.875rem; font-weight: 500; color: var(--ink); }
.tl-meta { font-size: 0.75rem; color: var(--muted); }

/* ==================== BUTTONS & FORMS ==================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid transparent;
  font-size: 0.8125rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn--ghost:hover { background: var(--rail); }
.btn--subtle { background: transparent; color: var(--ink-2); padding: 0 10px; }
.btn--subtle:hover { background: var(--rail); color: var(--ink); }
.btn--danger { background: var(--surface); border-color: var(--line-strong); color: var(--danger); }
.btn--danger:hover { background: #fef2f2; border-color: #fecaca; }
.btn--sm { height: 30px; padding: 0 10px; font-size: 0.75rem; }
.btn--full { width: 100%; height: 40px; font-size: 0.875rem; }

.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 0.8125rem; font-weight: 500; color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); background: var(--surface); font-size: 0.875rem; color: var(--ink);
  transition: border-color 150ms ease;
}
.field input::placeholder, .field textarea::placeholder { color: #94a3b8; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(184, 80, 18, 0.12); }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.search-input {
  height: 34px; padding: 0 11px; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); font-size: 0.8125rem; width: min(100%, 240px); background: var(--surface);
}

.item-row { display: grid; grid-template-columns: minmax(0, 1fr) 74px 110px 30px; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-total-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-radius: var(--r-sm); background: var(--rail);
  font-size: 0.875rem; font-weight: 600; margin: 10px 0 14px;
}

/* ==================== LIST CARDS (SHIPMENTS / DELIVERIES / MESSAGES) ==================== */
.stack-list { display: grid; gap: 12px; }
.row-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; display: grid; gap: 12px;
}
.row-card__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.row-card__body { font-size: 0.875rem; color: var(--ink-2); display: grid; gap: 4px; }
.row-card__foot {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.inline-items { background: #fafbfc; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; display: grid; gap: 6px; font-size: 0.8125rem; }
.inline-item { display: flex; justify-content: space-between; gap: 12px; }

/* ==================== MODAL & FEEDBACK ==================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 60;
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
}
.modal {
  width: min(100%, 520px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22); overflow: hidden;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: 0; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 6px; }
.modal-body { padding: 18px 20px; max-height: 78svh; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfc; }

.alert { padding: 10px 12px; border-radius: var(--r-sm); font-size: 0.8125rem; margin-bottom: 14px; border: 1px solid transparent; }
.alert--error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.alert--ok { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 80;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r-sm);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.25); font-size: 0.8125rem; font-weight: 500;
}

/* ==================== RESPONSIVE MOBILE POLISH (ZERO CLIPPING) ==================== */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 256px; z-index: 50;
    transform: translateX(-100%); transition: transform 180ms ease;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(15, 23, 42, 0.4); }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px 16px 40px; gap: 18px; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip--3 { grid-template-columns: 1fr; }
  .metric-cell { border-bottom: 1px solid var(--line); padding: 14px 16px; }
  .metric-cell:nth-child(even) { border-right: 0; }
  .metric-val { font-size: 1.25rem; }
  .form-row { grid-template-columns: 1fr; }
  .track-steps { grid-template-columns: repeat(5, 1fr); }
  .track-step span { font-size: 0.65rem; }
}

@media (max-width: 640px) {
  .portal-header { padding: 0 16px; }
  .portal-box { padding: 22px 18px; }
  /* Stack wide tables cleanly on narrow phones so no column ever clips off-screen */
  table.resp-table thead { display: none; }
  table.resp-table, table.resp-table tbody, table.resp-table tr, table.resp-table td { display: block; width: 100%; }
  table.resp-table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
  table.resp-table tr:last-child { border-bottom: 0; }
  table.resp-table td {
    padding: 0; border: 0; display: flex; justify-content: space-between; align-items: baseline;
    gap: 12px; text-align: right;
  }
  table.resp-table td::before {
    content: attr(data-label); font-size: 0.75rem; color: var(--muted); font-weight: 500;
    text-align: left; flex-shrink: 0;
  }
  table.resp-table td[data-primary] { display: block; text-align: left; margin-bottom: 2px; }
  table.resp-table td[data-primary]::before { display: none; }
  table.resp-table td.empty { display: block; text-align: center; padding: 28px 16px; }
  table.resp-table td.empty::before { display: none; }
  .item-row { grid-template-columns: minmax(0, 1fr) 64px 92px 28px; }
}
