:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #dde3ea;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --danger: #b91c1c;
  --status-delivered: #15803d;
  --status-transit: #b45309;
  --status-pending: #6b7280;
  --status-unknown: #9333ea;
  --status-imminent: #d97706;
  --status-late: #b91c1c;
  --status-estimate: #0e7490;
  --status-grv: #0f766e;
  --status-partial-grv: #ca8a04;
  --status-awaiting-docs: #a16207;
  /* Hover/soft/shadow tints — kept as variables (rather than literal colors
     sprinkled through the rules below) purely so the dark theme override
     further down can flip all of them in one place. */
  --hover: #f1f5f9;
  --hover-danger: #fef2f2;
  --thead-bg: #f9fafb;
  --soft-blue: #eff6ff;
  --soft-red: #fee2e2;
  --soft-green: #dcfce7;
  --vessel-hover-border: #c7d0dc;
  --modal-overlay: rgba(15, 23, 42, 0.5);
  --shadow-sm: rgba(0, 0, 0, 0.06);
  --shadow-md: rgba(0, 0, 0, 0.1);
  --row-selected-bg: rgba(29, 78, 216, 0.1);
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* Toggled from js/api.js's setTheme() and remembered in localStorage — see
   themeToggleHtml()/bindThemeToggle() there, wired into every topbar. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --danger: #f87171;
  --status-awaiting-docs: #ca8a04;
  --hover: rgba(255, 255, 255, 0.08);
  --hover-danger: rgba(248, 113, 113, 0.15);
  --thead-bg: #16213a;
  --soft-blue: rgba(59, 130, 246, 0.18);
  --soft-red: rgba(248, 113, 113, 0.18);
  --soft-green: rgba(74, 222, 128, 0.18);
  --vessel-hover-border: #475569;
  --modal-overlay: rgba(0, 0, 0, 0.65);
  --shadow-sm: rgba(0, 0, 0, 0.3);
  --shadow-md: rgba(0, 0, 0, 0.4);
  --row-selected-bg: rgba(59, 130, 246, 0.22);
}

* { box-sizing: border-box; }

/* Site watermark — to swap the image, just replace img/watermark.svg with
   a same-named file; nothing here needs to change. */
body {
  margin: 0;
  background-color: var(--bg);
  background-image: url('/img/watermark.svg');
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: 900px auto;
  background-attachment: fixed;
  color: var(--text);
  /* On the web this is always 0 and does nothing. In the native app,
     env(safe-area-inset-*) is how iOS reports how much space the notch/
     Dynamic Island (top) and home-indicator bar (bottom) actually take up —
     without this, content renders full-bleed underneath them (confirmed on
     a real iPhone: the topbar sat behind the status bar/clock). Requires
     viewport-fit=cover on the <meta name="viewport"> tag to take effect at
     all — see index.html. */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#app { min-height: 100vh; }

/* --- Login --- */
.login-screen {
  min-height: 100vh;
  padding-bottom: 90px; /* room to scroll the form clear of the pinned footer */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Small action buttons side by side on a shipment's detail page (Order
   items / Auto-tracking), wrapping to their own lines on a narrow phone. */
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
}
.detail-actions button.secondary {
  width: auto;
  flex: 1 1 140px;
  margin-top: 0;
}

/* Privacy-policy link: only visible while a sign-in screen is on show. */
.privacy-footer {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  /* Solid, so a short screen's form scrolling under it can't show through. */
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.privacy-footer a {
  color: var(--muted);
  padding: 0 6px;
}
.privacy-footer .footer-note { display: block; color: var(--muted); }
.privacy-footer .footer-links { display: block; margin-top: 2px; color: var(--muted); }
body:has(.login-screen) .privacy-footer { display: block; }
/* Out of the way while someone is typing (the keyboard already shrinks the screen). */
body:has(.login-screen input:focus) .privacy-footer { display: none; }

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 1px 3px var(--shadow-sm);
}

/* Content panels reuse .login-card's look (background/border/padding) but
   are wide dashboard sections, not a centered sign-in form — they should
   fill the page instead of sitting at a fixed width with empty space
   beside them. Real auth forms stay narrow: this only applies once nested
   inside .dashboard (a login-screen's own form never is). Any panel that's
   deliberately small (e.g. an empty-state message) keeps an inline
   max-width, which — being inline — still wins over this rule. */
.dashboard .login-card {
  width: 100%;
  max-width: none;
}

/* The shipment detail page's cards (info/comments/update log) went full
   width along with everything else above, but as a single column of
   mostly-text content that read as oversized on a wide screen — capped
   back down below, reverting to full width under 900px so it doesn't get
   cramped on a tablet or phone. */
.dashboard .login-card.detail-card {
  max-width: 50%;
}

@media (max-width: 900px) {
  .dashboard .login-card.detail-card {
    max-width: 100%;
  }
}

.portal-picker {
  text-align: center;
  width: 90%;
  max-width: 900px;
}

.landing-title { font-size: 42px; margin: 0 0 6px; color: var(--primary); }
.landing-slogan { font-style: italic; color: var(--muted); font-size: 15px; margin: 0 0 18px; }
.portal-picker p.subtitle { color: var(--muted); font-size: 14px; margin: 0 0 28px; }

.portal-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.portal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 22px;
  width: 220px;
  box-shadow: 0 1px 3px var(--shadow-sm);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.portal-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px var(--shadow-md); }

.portal-card h2 { font-size: 16px; margin: 0 0 8px; color: var(--primary); }
.portal-card p { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.4; }

.admin-login-corner {
  position: fixed;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 4px;
}

.admin-login-corner:hover { color: var(--text); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] { display: none; }

.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.field input, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  /* iOS auto-zooms the whole page on focus for any text input under 16px —
     and doesn't zoom back out again afterward, which is exactly the "stuck
     zoomed in" bug reported from the native app. 16px is the documented
     threshold that avoids it entirely, so this isn't a Capacitor-only
     concern — it'd affect anyone opening the actual website in mobile
     Safari too. */
  font-size: 16px;
  font-family: inherit;
  background: var(--panel);
  color: var(--text);
}

.field textarea { resize: vertical; }

.incoterm-group {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.field .incoterm-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  font-size: 14px;
  cursor: pointer;
}

.field .incoterm-option input {
  width: auto;
  padding: 0;
  border: none;
  background: none;
}

.password-field { position: relative; }

.password-field input { padding-right: 56px; }

.password-toggle-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}

/* Every real "button" element (as opposed to a plain text link — see
   button.link below) shares one height across the whole app, whether it's
   a full-width form button or a small inline one like .icon-btn — see also
   .icon-btn and .topbar-btn further down, which opt into this same rule. */
button.primary, button.secondary, button.danger {
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
}

button.primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
}

button.primary:hover { background: var(--primary-dark); }
button.primary:disabled { opacity: 0.6; cursor: default; }

button.secondary {
  width: 100%;
  margin-top: 10px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover { background: var(--hover); }

button.danger {
  width: 100%;
  margin-top: 10px;
  background: var(--panel);
  color: var(--danger);
  border: 1px solid var(--danger);
}

button.danger:hover { background: var(--hover-danger); }

.error-message {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

.notice-message {
  color: var(--status-delivered);
  font-size: 13px;
  margin-bottom: 12px;
}

.login-card button.link {
  display: block;
  margin: 14px auto 0;
}

/* --- Dashboard --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 16px; margin: 0; }

.topbar .user-email { color: var(--muted); font-size: 13px; margin-right: 16px; }

button.link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

/* "Delete account" (deleteAccountButtonHtml in js/api.js) sits last in the top bar,
   deliberately small and muted and set apart from Sign out, so it is findable
   (the app stores require that) but not easy to hit by mistake. */
#delete-account-btn {
  color: var(--muted);
  font-size: 11px;
  margin-left: 28px;
  text-decoration: underline;
}
#delete-account-btn:hover { color: var(--danger); }
@media (max-width: 600px) {
  #delete-account-btn { display: block; margin: 12px 0 0; }
}

.dashboard { padding: 20px 24px; }

/* Clickable "key issues" summary tiles at the top of the Agent dashboard —
   each one both a count and a toggle for a filter/sort applied in draw().
   See renderAgentDashboard in js/agent.js. */
.issue-tiles {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.issue-tile {
  flex: 1;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.issue-tile:hover { border-color: var(--primary); }
.issue-tile.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

.issue-tile-count { font-size: 24px; font-weight: 700; color: var(--text); }
.issue-tile.has-issues .issue-tile-count { color: var(--danger); }
.issue-tile-label { font-size: 12px; color: var(--muted); font-weight: 600; }

.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters select, .filters input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  /* See the identical comment on .field input's font-size — same iOS
     zoom-on-focus threshold. */
  font-size: 16px;
  background: var(--panel);
  color: var(--text);
}

.filters input[type="search"] { min-width: 220px; }

/* The search box's own clear control — type="search" inputs have a native
   one in most browsers, but it's inconsistent (and easy to miss) across
   the phone app's WebView, so this adds an explicit always-the-same-place
   one instead. The native one is suppressed below so there's never two. */
.search-wrap { position: relative; display: inline-flex; flex: 1 1 220px; }
.search-wrap input[type="search"] { width: 100%; min-width: 0; box-sizing: border-box; padding-right: 28px; }
.search-clear-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
}
.search-clear-btn:hover { color: var(--text); }
input[type="search"]::-webkit-search-cancel-button { display: none; }

.icon-btn {
  height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  box-sizing: border-box;
  white-space: nowrap;
}

.icon-btn:hover { background: var(--hover); }

/* Banner across the top of a shipment's detail page: the way back to the
   dashboard plus which container you're in. It stays pinned while the page
   scrolls, so you can leave from half way down. The body pads for the phone's
   notch (safe-area-inset-top); the banner pulls itself up into that padding and
   re-adds it inside, so it reaches the very top edge with nothing scrolling
   past above it. */
.detail-banner {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: calc(-1 * env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.detail-banner .icon-btn { flex: none; }
/* Still used by the Suppliers & agents screen: a floating pinned back button. */
.sticky-back {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 30;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.detail-banner-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drag-and-drop target for the Supporting Documents upload (see agent.js/
   customer.js) — also just a click target for the normal file picker, so
   it works the same as a button for anyone not dragging a file. */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  margin-top: 10px;
}

.dropzone:hover, .dropzone:focus-visible { border-color: var(--primary); outline: none; }
.dropzone.dropzone-active { border-color: var(--primary); background: var(--soft-blue); }
.dropzone.dropzone-busy { cursor: default; opacity: 0.7; }

.dropzone-text {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.topbar-btn {
  height: 38px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 12px;
  box-sizing: border-box;
}

.topbar-btn:hover { background: var(--primary-dark); }

.copy-code-btn {
  font-family: inherit;
  letter-spacing: 0.03em;
}

.copy-code-btn[hidden] { display: none; }

.vessel-link {
  display: inline-block;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
}

/* :visited pinned to the same color as a fresh link — a vessel is clicked
   repeatedly by design (checking its position again later), so it should
   never look "already read" the way a normal link does. */
.vessel-link, .vessel-link:visited { color: var(--text); }
.vessel-link:hover { background: var(--hover); border-color: var(--vessel-hover-border); }

.date-filter-chip[hidden] { display: none; }

.date-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
}

.date-filter-chip button {
  border: none;
  background: none;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.calendar-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  max-width: 420px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.calendar-header strong { flex: 1; text-align: center; font-size: 14px; }

.calendar-panel.wide { max-width: 640px; }

.comment {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.comment:last-child { border-bottom: none; }

.comment-meta {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.comment-body { font-size: 13px; white-space: pre-wrap; }

.comment-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.comment-dot-new { background: var(--danger); }
.comment-dot-seen { background: var(--status-delivered); }

.auto-tracking-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary-dark);
  cursor: pointer;
  white-space: nowrap;
}

.auto-tracking-toggle input { width: auto; margin: 0; }

.notes-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  max-width: 260px;
  white-space: normal;
}

.note-line { font-size: 12px; line-height: 1.4; }
.note-line strong { font-weight: 600; }
.note-empty { color: var(--muted); font-style: italic; }

.note-live {
  font-weight: 600;
  color: var(--primary-dark);
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}
.note-live .note-empty { font-weight: 400; }

.note-declined {
  font-weight: 600;
  color: var(--danger);
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}
.note-declined .note-empty { font-weight: 400; }

.note-add-form {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.note-add-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.note-add-form button {
  padding: 4px 8px;
  font-size: 12px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-cell {
  border: none;
  background: none;
  font-size: 12px;
  border-radius: 6px;
  padding: 6px 2px;
}

.cal-weekday { color: var(--muted); font-weight: 600; text-align: center; }

.cal-day {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text);
}

.cal-day:hover { background: var(--hover); }
.cal-day.is-today .cal-daynum { color: var(--primary); font-weight: 700; }
.cal-day.has-shipments { background: var(--soft-blue); }

.cal-count {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border-radius: 999px;
  padding: 1px 6px;
}

/* A day in the past with a shipment that never got marked Delivered —
   flagged red so a delay with no update stands out on the calendar. */
.cal-day.is-overdue { background: var(--soft-red); }
.cal-day.is-overdue .cal-daynum { color: var(--danger); font-weight: 700; }
.cal-count-overdue { background: var(--danger); }
.cal-day.is-delivered { background: var(--soft-green); }
.cal-day.is-delivered .cal-daynum { color: var(--status-delivered); font-weight: 700; }
.cal-count-delivered { background: var(--status-delivered); }
:root[data-theme="dark"] .cal-day.is-delivered .cal-daynum { color: #4ade80; }

.summary { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 220px);
}

/* A PO modal's line-item list specifically — deliberately its own class
   rather than reusing .table-wrap, since the @media (max-width: 1024px)
   rule below turns .table-wrap's scrolling off in favor of stacked cards
   for the main shipment table. The PO modal is a small fixed-size popup at
   every width, so it always needs to scroll its own content rather than
   grow past the modal's Close button. */
.po-items-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 300px;
}

table { border-collapse: collapse; width: 100%; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--thead-bg);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  z-index: 1;
}

/* --hover is a see-through tint in dark mode, so using it as the whole
   background let rows scrolling under the sticky header show through. Keep
   the solid header colour underneath and lay the tint over it. */
thead th:hover {
  background-color: var(--thead-bg);
  background-image: linear-gradient(var(--hover), var(--hover));
}

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover { background: var(--hover); }

/* Native-app-only collapsed row affordance — see IS_NATIVE_APP/KEY_COLUMN_KEYS
   in js/api.js and js/main.js. Plain text, not a button: the whole row is
   the tap target. */
.app-row { cursor: pointer; }
.tap-more-hint { color: var(--muted); font-size: 12px; text-align: center !important; }
/* Edit / Full details inside a row that has been tapped open (phone app). */
.row-actions { display: flex; gap: 8px; }
.row-actions::before { display: none !important; }
.row-actions button.secondary { flex: 1; width: auto; margin-top: 0; }

/* Caps a long Items description (especially a merged multi-product order)
   so it can't push the columns after it — PO/Container/Vessel/ETA/Status —
   off screen. Full text is a hover away, and always shown in full on the
   shipment's own detail page. */
.items-cell {
  display: inline-block;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* First click on an agent/customer dashboard row arms it (highlighted here);
   a second click on that same row is what opens it — see the row click
   handlers in js/agent.js and js/customer.js. */
tbody tr.row-selected, tbody tr.row-selected:hover { background: var(--row-selected-bg); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.badge[title] { cursor: help; }
.badge.delivered, .badge.arrived { background: var(--status-delivered); }
.badge.in-transit, .badge.en-route-to-factory { background: var(--status-transit); }
.badge.pending { background: var(--status-pending); }
.badge.awaiting-docs, .badge.awaiting-invoice { background: var(--status-awaiting-docs); }
.badge.unknown { background: var(--status-unknown); }
.badge.imminent { background: var(--status-imminent); }
.badge.late { background: var(--status-late); }
.badge.estimated { background: var(--status-estimate); }
.badge.awaiting-confirmation { background: var(--status-unknown); }
.badge.grvd { background: var(--status-grv); }
.badge.partially-grvd { background: var(--status-partial-grv); }

.needs-review { color: var(--danger); font-weight: 600; }

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

/* --- Phone / tablet --- */
/* 1024px (not just phone-width) so the 11-column table never forces
   horizontal scrolling on a tablet either — this is exactly what showed up
   in the native app on a Samsung tablet in portrait (~800px), a width that
   used to fall between this breakpoint (previously 680px) and desktop,
   getting neither the stacked-card treatment nor enough room for the full
   table, just an unreadable-then-scrollable one. */
@media (max-width: 1024px) {
  body { background-size: 480px auto; }

  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .topbar h1 { font-size: 15px; width: 100%; }
  .topbar .user-email { margin-right: 10px; font-size: 12px; }

  .dashboard { padding: 12px; }

  .issue-tile { min-width: 100%; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters select, .filters input, .filters .icon-btn, .filters .topbar-btn, .filters .primary { width: 100%; font-size: 16px; padding: 10px; }
  .filters input[type="search"] { min-width: 0; }
  /* .search-wrap's desktop flex-basis (220px) is a horizontal sizing hint
     that means something different once .filters switches to a column
     direction here — reset to a plain full-width block so it stacks like
     every other filter control instead of just taking a 220px-tall slice. */
  .filters .search-wrap { width: 100%; flex: none; }
  /* .topbar-btn's margin-right is meant for sitting inline next to other
     desktop buttons — on the stacked, full-width mobile layout it just
     shifts the button in from the right edge instead of flush like every
     other filter-bar element, so it's zeroed out here. */
  .filters .topbar-btn { margin-right: 0; }
  .date-filter-chip { align-self: flex-start; }

  .calendar-panel { max-width: none; }
  .cal-cell { font-size: 12px; padding: 8px 2px; }
  .cal-count { font-size: 11px; }

  /* Below the breakpoint, each shipment renders as a stacked card instead
     of a table row — a wide nowrap table is unreadable on a phone screen,
     so the header row is dropped and every cell becomes its own labeled
     line (label from the td's data-label, set in main.js). Scoped to
     .table-wrap specifically (the main dashboard table) rather than bare
     table/tr/td — a small table elsewhere on the page (e.g. the PO modal's
     .po-items-wrap, whose cells have no data-label) stays a normal compact
     table instead of also being flattened into unlabeled stacked rows. */
  .table-wrap { border: none; background: none; overflow: visible; max-height: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }

  .table-wrap tbody tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 12px;
    margin-bottom: 10px;
  }

  .table-wrap tbody tr.needs-review-row { border-left: 3px solid var(--danger); }

  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    text-align: right;
    font-size: 14px;
  }

  .table-wrap tbody td:last-child { border-bottom: none; }

  .table-wrap tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-align: left;
    flex-shrink: 0;
  }

  /* The stacked-card layout has no columns to push off screen, so the full
     item description can just wrap instead of being truncated. */
  .items-cell { display: inline; max-width: none; overflow: visible; white-space: normal; text-overflow: clip; }
}

/* Login activity (admin graph + per-user stats) */
.login-graph-controls { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.login-graph-controls .field { margin: 0; min-width: 200px; flex: 1; }
.login-range-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 6px; padding: 8px 12px; font-size: 13px; cursor: pointer;
}
.login-range-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.login-graph-total { font-size: 28px; font-weight: 700; line-height: 1; margin: 4px 0 2px; }
.login-graph-total-label { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.login-graph {
  display: flex; align-items: flex-end; gap: 2px; height: 160px;
  padding: 8px 0 0; border-bottom: 1px solid var(--border);
}
.login-graph-col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; cursor: pointer; }
.login-graph-col.selected .login-graph-bar { background: var(--primary-dark); opacity: 1; outline: 2px solid var(--primary-dark); }
.activity-day-chip { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 12px; font-size: 12px; }
.activity-day-chip button { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 12px; padding: 0; }
.login-graph-bar { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; }
.login-graph-col:hover .login-graph-bar { opacity: 1; }
.login-graph-bar.zero { background: var(--border); }
.login-graph-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.user-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.user-stats-tile { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.user-stats-tile .label { color: var(--muted); font-size: 12px; }
.user-stats-tile .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.user-stats-big { font-size: 34px; font-weight: 700; line-height: 1; margin: 10px 0 2px; }
button.link.user-stats-btn { text-align: left; }

/* Rows ticked for declining turn red across the whole bar. */
tr.decline-picked,
tr.decline-picked:hover {
  background: var(--soft-red);
  box-shadow: inset 4px 0 0 var(--danger);
}
.login-card textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

/* Direction arrow on a sorted table heading. */
thead th.sort-asc::after { content: ' \25B2'; font-size: 10px; }
thead th.sort-desc::after { content: ' \25BC'; font-size: 10px; }

/* Phone app: the "Tap for more" line carries the status badge on its left. */
.tap-hint-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; }
.tap-more-hint::before { display: none !important; }

/* ---- Cash flow management / cash forecast (js/orders.js) ---- */
.dashboard .login-card.detail-card.fc-card { max-width: none !important; width: 100%; box-sizing: border-box; }
.fc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; margin-top: 4px; }
.fc-box {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; color: var(--text); cursor: pointer;
}
.fc-box:hover { background: var(--hover); }
.fc-box.now { border-color: var(--primary); }
.fc-box.overdue { border-color: var(--danger); background: var(--soft-red); }
.fc-box.selected { background: var(--soft-blue); border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.fc-month { font-weight: 600; font-size: 13px; color: var(--muted); }
.fc-total { font-size: 15px; font-weight: 700; }
.fc-total.fc-none { color: var(--muted); font-weight: 400; }
.fc-line { font-size: 12px; color: var(--muted); }
.fc-conv-total { font-size: 15px; font-weight: 700; margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--border); width: 100%; box-sizing: border-box; }
.fc-total-label { display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.fc-norate { margin-bottom: 6px; }
.fc-conv-total.nil, .fc-line.nil { color: var(--muted); font-weight: 400; }
.fc-grid .fc-box:not(.fc-cur) .fc-month { margin-bottom: 4px; }
#orders-grid .fc-month { text-transform: uppercase; letter-spacing: 0.03em; }
.fc-norate { font-size: 11px; color: var(--danger); }
.fc-year { margin: 4px 0 14px; font-size: 14px; }
.fc-cur { cursor: default; }
.fc-cur:hover { background: var(--panel); }
.fc-cur:focus-within { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.fc-cur-primary { position: relative; background: var(--soft-blue); border-color: var(--primary); cursor: pointer; }
.fc-cur-pill { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 15px; font-weight: 700; background: var(--panel); text-align: center; }
.fc-cur .fc-cur-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.fc-cur-primary:hover { background: var(--soft-blue); }
.fc-cur.norate { border-style: dashed; }
.fc-cur.norate .fc-sub { color: var(--danger); }
.fc-cur input, .fc-cur select { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 15px; font-weight: 700; background: var(--panel); color: var(--text); }
.fc-cur input { text-align: right; }
.fc-po { font-weight: 600; white-space: nowrap; }
.fc-unalloc { font-weight: 400; font-style: italic; color: var(--muted); }
.fc-conv { white-space: nowrap; text-align: right; color: var(--muted); }
.fc-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.fc-add { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.fc-add .field { flex: 1 1 140px; min-width: 120px; margin: 0; }
/* The PO list holds the longest text, so it gets the widest column. */
.fc-add .field:first-child { flex: 2 1 260px; }
/* Dropdowns in this form look like the text boxes beside them; without this the browser draws them small and plain, and a long PO name pushes the next field over. */
.fc-add .field select {
  width: 100%; min-width: 0; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 16px; font-family: inherit; background: var(--panel); color: var(--text); text-overflow: ellipsis;
}
.fc-add .field input { box-sizing: border-box; }
.fc-table-wrap { max-height: none; }
.fc-table input.fc-input, .fc-table select.fc-input {
  width: 100%; min-width: 90px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: var(--panel); color: var(--text);
}
.fc-table input.fc-num { min-width: 110px; text-align: right; }
/* Room for the invoice number and the supplier's name; the table scrolls sideways if the screen is narrower than that. */
.fc-table input[data-field="invoice_no"] { min-width: 150px; }
.fc-table input[data-field="supplier_name"] { min-width: 220px; }
.fc-table select[data-field="kind"], .fc-table select[data-field="currency"] { min-width: 0; width: auto; }
/* The Linx tag goes under the invoice number, not beside it. */
.fc-table td .fc-pill { display: block; width: fit-content; }
/* Deposit box on a "Not invoiced yet" row: an amount and its currency, with Add invoice under them. */
.fc-deposit { display: flex; gap: 4px; margin-bottom: 4px; }
.fc-table .fc-deposit input, .fc-table .fc-deposit select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-style: normal;
  background: var(--panel); color: var(--text); min-width: 0; box-sizing: border-box;
}
.fc-table .fc-deposit input { width: 110px; text-align: right; }
.fc-table input.fc-check { width: 18px; height: 18px; min-width: 0; }
.fc-table tr.fc-paid td { background: var(--soft-green); }
.fc-table tr.fc-overdue td { background: var(--soft-red); }
.fc-delete { font-size: 20px; color: var(--muted); }
.fc-table tr.fc-expected td { font-style: italic; color: var(--muted); }
.fc-table tr.fc-expected td.fc-po { font-style: normal; color: var(--text); }
.fc-table td.fc-num { text-align: right; white-space: nowrap; }
.fc-pill { display: inline-block; margin-top: 3px; padding: 1px 7px; border: 1px solid var(--border); border-radius: 999px; font-size: 11px; font-style: normal; color: var(--muted); white-space: nowrap; }
.fc-estnote { font-size: 11px; font-style: italic; color: var(--muted); margin-bottom: 6px; }
.fc-table input.fc-needs-amount { border-color: var(--danger); }
.fc-waiting { display: flex; flex-wrap: wrap; gap: 8px; }
.fc-po-chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 13px; cursor: pointer;
}
.fc-po-chip:hover { border-color: var(--primary); }

/* ---- Phone apps only: bottom tab bar and quieter top (see js/appshell.js) ----
   Everything is under body.app-shell (Shipment Manager and Agent/Supplier pages
   once signed in) or .native-app, which only the native apps ever get, so the
   website is untouched. The old top-bar buttons stay in the page (hidden), the
   tab bar and its More sheet do their jobs. */

/* A solid strip behind the phone's status bar (time, battery), so the page
   scrolling up never shows underneath them. The detail page's own banner sits
   above it and fills the same space. */
.native-app body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top);
  background: var(--bg);
  z-index: 25;
}

body.app-shell .topbar > div:last-child { display: none; }
body.app-shell .topbar { padding: 12px 16px; }
body.app-shell #customer-delivered-archive-btn,
body.app-shell #customer-suppliers-btn,
body.app-shell #customer-filter-status,
body.app-shell #customer-load-container-btn,
body.app-shell #customer-orders-btn,
body.app-shell #customer-decline-btn,
body.app-shell #agent-delivered-archive-btn,
body.app-shell #agent-add-customer-btn,
body.app-shell #agent-load-container-btn { display: none !important; }
body.app-shell .filters { gap: 0; margin-bottom: 0; }
body.app-shell .filters > div { width: 100%; }
body.app-shell .filters > div:last-child:not(:first-child) { display: none !important; }
/* Shipment Manager home: the calendar sits as a small button beside the search. */
body.app-shell .filters > div:first-child { flex-wrap: wrap; gap: 8px !important; }
body.app-shell .filters .search-wrap { flex: 1 1 0; width: auto; min-width: 0; }
body.app-shell #customer-calendar-btn { width: 46px !important; flex: none; padding: 0; font-size: 20px; }
body.app-shell .date-filter-chip { flex-basis: 100%; }
/* Agent home: the customer and status lists side by side. */
body.app-shell #agent-filter-customer,
body.app-shell #agent-filter-status { width: auto; flex: 1 1 0; min-width: 0; }
body.app-shell .filters:has(#agent-filter-customer) { flex-direction: row; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
body.app-shell #agent-issue-filter-chip { flex-basis: 100%; }
/* Room under every page for the tab bar. */
body.app-shell #app { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
/* Out of the way while the keyboard is up. */
body.app-typing .app-tabbar { display: none; }

/* Agent dashboard: the three count tiles in one row. */
.native-app .issue-tiles { flex-wrap: nowrap; gap: 8px; margin-bottom: 12px; }
.native-app .issue-tile { flex: 1 1 0; min-width: 0; align-items: center; text-align: center; padding: 10px 6px; }
.native-app .issue-tile-count { font-size: 22px; }
.native-app .issue-tile-label { font-size: 11px; line-height: 1.25; }

/* Title of the app's own pages (Notifications, Preferences). */
.app-page-title { padding: 14px 16px 2px; }
.app-page-title h1 { font-size: 20px; margin: 0; }


.app-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.app-chips::-webkit-scrollbar { display: none; }
.app-chip {
  flex: 0 0 auto;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.app-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
}
.app-tab {
  flex: 1 1 0;
  min-width: 0;
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  padding: 4px 0;
  cursor: pointer;
}
.app-tab svg { width: 24px; height: 24px; }
.app-tab-label { white-space: nowrap; }
.app-tab.active { color: var(--primary); }
.app-tab-load { flex: 1.5 1 0; margin-top: -26px; color: var(--text); font-weight: 600; }
.app-tab-circle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--panel);
}
.app-tab-circle svg { width: 28px; height: 28px; }

.app-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
}
.app-sheet {
  width: 100%;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
}
.app-sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 6px; }
.app-sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 0 20px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.app-sheet-item svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.app-sheet-item.with-divider { border-top: 1px solid var(--border); }
.app-sheet-item.small { min-height: 44px; font-size: 13px; color: var(--muted); }
.app-sheet-item.small svg { width: 18px; height: 18px; }
.app-tab-icon { position: relative; display: inline-flex; }
.app-tab-badge {
  position: absolute;
  top: -5px;
  left: 15px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.app-tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

/* Notifications list. */
.app-notice-list { display: flex; flex-direction: column; gap: 10px; }
.app-notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.app-notice.is-message { border-left: 4px solid var(--primary); }
.app-notice-icon { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--hover); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.app-notice-icon svg { width: 20px; height: 20px; }
.app-notice-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.app-notice-title { font-weight: 700; font-size: 14px; }
.app-notice-what { font-size: 14px; }
.app-notice-meta { font-size: 12px; color: var(--muted); }
.app-notice-text { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.app-notice-text:empty { display: none; }
.app-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
/* The comment a message notification jumped to. */
.comment-highlight { background: var(--row-selected-bg); border-radius: 6px; }

/* Preferences: label on the left, tick box on the right. */
.app-pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-weight: 400;
  font-size: 15px;
}
.app-pref-row input[type="checkbox"] { width: 22px; height: 22px; flex: none; margin: 0; }
.app-pref-main { font-weight: 600; }
.app-pref-off { opacity: 0.45; }

/* Pull to refresh: a pill that slides down from under the status bar. */
.app-pull {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px var(--shadow-md);
  color: var(--muted);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(var(--pull, 0px) * 0.5 - 50px));
  transition: opacity 0.15s;
}
.app-pull.visible { opacity: 1; }
.app-pull.ready, .app-pull.refreshing { color: var(--primary); }
.app-pull-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}
.app-pull.refreshing .app-pull-spinner { animation: app-spin 0.8s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }

/* A cell hidden on purpose (e.g. the Decline tick-box column when not picking)
   must stay hidden on the phone's stacked cards too — otherwise it showed as an
   empty, unlabelled line at the top of every container card. */
.table-wrap tbody td[hidden] { display: none !important; }

/* PO popup line items: long descriptions wrap onto more lines so the Ordered
   column always stays in view; codes and quantities never wrap. */
.po-items-table td.po-desc { white-space: normal; word-break: break-word; min-width: 110px; }
.po-items-table .po-qty { text-align: right; white-space: nowrap; }
.po-items-table td.po-code { white-space: nowrap; }
.native-app .po-items-table { font-size: 12px; }
.native-app .po-items-table th, .native-app .po-items-table td { padding: 6px 8px; }
