:root {
  /* CEL brand */
  --cel-blue: #0077a8;
  --cel-blue-dark: #005f87;
  --cel-blue-light: #e6f1f7;
  --cel-blue-lighter: #f4f9fc;
  --cel-navy: #0a2540;
  --cel-navy-soft: #1a3658;

  --bg: #ffffff;
  --bg-soft: #f7f9fb;
  --bg-card: #ffffff;
  --ink: #0a2540;
  --ink-soft: #4a5a72;
  --ink-faint: #8a96a8;
  --line: #e4e9ef;
  --line-strong: #ccd4df;

  --accent: var(--cel-blue);
  --accent-soft: var(--cel-blue-light);
  --accent-ink: var(--cel-blue-dark);

  --warn: #b8651a;
  --warn-soft: #fbece0;
  --danger: #c0392b;

  --status-offered: #6b7480;
  --status-approved: #0077a8;
  --status-invoiced: #2a5687;
  --status-paid: #6a4ea8;
  --status-shipped: #b8651a;
  --status-partial: #c9941d;
  --status-received: #2a7d4f;
  --status-tested: #1f6356;
  --status-closed: #4a5a72;

  --shadow-sm: 0 1px 2px rgba(10,37,64,0.04), 0 1px 3px rgba(10,37,64,0.04);
  --shadow-md: 0 4px 16px rgba(10,37,64,0.06), 0 2px 4px rgba(10,37,64,0.04);
  --shadow-lg: 0 12px 40px rgba(10,37,64,0.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.mono { font-family: 'JetBrains Mono', monospace; }

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}
.login-left {
  background: var(--cel-blue);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-left::before,
.login-left::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  pointer-events: none;
}
.login-left::before { width: 480px; height: 480px; right: -160px; bottom: -160px; }
.login-left::after { width: 280px; height: 280px; right: 80px; bottom: 60px; background: rgba(255,255,255,0.04); }
.login-brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; }
.login-brand img {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: #fff;
  padding: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.login-brand .name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; line-height: 1.2; }
.login-brand .sub {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  margin-top: 2px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.login-pitch { position: relative; z-index: 1; margin-top: auto; max-width: 520px; }
.login-pitch h1 { font-weight: 700; font-size: 52px; line-height: 1.05; letter-spacing: -0.025em; margin: 0 0 24px 0; }
.login-pitch p { color: rgba(255,255,255,0.85); line-height: 1.6; font-size: 17px; }
.login-foot {
  position: relative; z-index: 1;
  margin-top: 48px;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.login-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--cel-blue-lighter);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-weight: 700; font-size: 32px; margin: 8px 0 28px 0; letter-spacing: -0.02em; }

.auth-tabs {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 8px;
}
.auth-tab {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
}
.auth-tab.active { background: var(--cel-blue-light); color: var(--cel-blue-dark); }

/* ============ FIELDS / BUTTONS ============ */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px; /* ≥16px prevents iOS zoom-on-focus */
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,119,168,0.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  min-height: 44px; /* touch target */
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-primary:disabled { background: var(--line-strong); cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); background: var(--bg-soft); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; min-height: 36px; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  padding: 0;
  font-weight: 600;
  text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }

/* ============ APP SHELL ============ */
.app { display: none; min-height: 100vh; background: var(--bg-soft); }
.app.active { display: block; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-brand img { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; }
.topbar-brand .name { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; color: var(--ink); line-height: 1.1; }
.topbar-brand .portal {
  white-space: nowrap;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-soft); flex-shrink: 0; }
.topbar-right .who {
  font-weight: 700;
  background: var(--cel-blue-light);
  color: var(--cel-blue-dark);
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 12px;
  border: none;
  font-family: inherit;
  cursor: pointer;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
button.who:hover { background: #d5e8f2; }

.container { max-width: 1320px; margin: 0 auto; padding: 32px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 24px;
  flex-wrap: wrap;
}
.page-head h1 { font-weight: 800; font-size: 34px; margin: 0; letter-spacing: -0.025em; line-height: 1.1; color: var(--ink); }
.page-head .sub { color: var(--ink-soft); margin-top: 6px; font-size: 14px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab {
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
  transition: all 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.tab .count { background: var(--bg-soft); padding: 2px 9px; border-radius: 12px; font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.tab.active .count { background: var(--cel-blue-light); color: var(--cel-blue-dark); }

/* Cards / table */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.shipments { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 720px; }
table.shipments th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  white-space: nowrap;
}
table.shipments td { padding: 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.shipments tr:last-child td { border-bottom: none; }
table.shipments tr.clickable { cursor: pointer; transition: background 0.1s; }
table.shipments tr.clickable:hover { background: var(--bg-soft); }
.cell-strong { font-weight: 700; color: var(--ink); }
.cell-soft { color: var(--ink-soft); font-size: 13px; }
.cell-mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-offered { color: var(--status-offered); background: #eef0f3; }
.pill-approved { color: var(--status-approved); background: var(--cel-blue-light); }
.pill-invoiced { color: var(--status-invoiced); background: #dde6f0; }
.pill-paid { color: var(--status-paid); background: #ebe6f3; }
.pill-shipped { color: var(--status-shipped); background: #fbece0; }
.pill-partial { color: #8b6610; background: #fdf3d6; }
.pill-received { color: var(--status-received); background: #d9ebe0; }
.pill-tested { color: var(--status-tested); background: #d8eae5; }
.pill-closed { color: var(--status-closed); background: #e3e8ef; }

/* Empty state */
.empty { padding: 64px 32px; text-align: center; color: var(--ink-faint); }
.empty .heading { font-weight: 700; font-size: 18px; color: var(--ink-soft); margin-bottom: 8px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,37,64,0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 48px 24px;
  overflow-y: auto;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 660px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.modal-head h3 { font-weight: 700; font-size: 22px; margin: 0; letter-spacing: -0.015em; color: var(--ink); }
.modal-head .sub { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.modal-close {
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--ink); background: var(--bg-soft); }
.modal-body { padding: 24px 28px; }
.modal-foot {
  padding: 16px 28px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-soft);
}

/* Form sections */
.form-section { padding: 16px 0; }
.form-section + .form-section { border-top: 1px dashed var(--line); margin-top: 8px; }
.form-section h4 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 14px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section h4 .step {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--cel-blue-light);
  color: var(--cel-blue-dark);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  display: grid; place-items: center;
  letter-spacing: 0;
  font-weight: 700;
}
.help-text { font-size: 12px; color: var(--ink-faint); margin-top: 4px; line-height: 1.5; }
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
  border-left: 3px solid;
}
.alert-info { background: var(--cel-blue-light); color: var(--cel-blue-dark); border-color: var(--accent); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* Detail panel */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin-bottom: 20px; }
.detail-grid .item .lbl {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 3px;
}
.detail-grid .item .val { font-size: 14px; color: var(--ink); font-weight: 600; }
.detail-grid .item .val.empty { color: var(--ink-faint); font-style: italic; font-weight: 400; }
.detail-grid .item .val.mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 500; }

.timeline { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.timeline-head {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 8px;
}
.timeline-item { display: flex; gap: 12px; padding: 8px 0; font-size: 13px; }
.timeline-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex-shrink: 0; }
.timeline-item .dot.muted { background: var(--line-strong); }
.timeline-item .text { color: var(--ink); }
.timeline-item .when { color: var(--ink-faint); font-size: 12px; }

/* Tracking rows */
.tracking-list { display: flex; flex-direction: column; gap: 8px; }
.tracking-row { display: flex; gap: 8px; align-items: center; }
.tracking-row input { flex: 1; }
.tracking-remove {
  background: none;
  border: 1px solid var(--line-strong);
  color: var(--ink-faint);
  width: 44px; height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.tracking-remove:hover { color: var(--danger); border-color: var(--danger); }
.tracking-add {
  background: none;
  border: 1px dashed var(--line-strong);
  color: var(--ink-soft);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  width: fit-content;
}
.tracking-add:hover { color: var(--accent); border-color: var(--accent); }
.tracking-display { display: flex; flex-direction: column; gap: 4px; }
.tracking-display .t-item { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--ink); word-break: break-all; }

/* Filters */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
}
.filters input[type="search"] { min-width: 240px; flex: 1; }
.filters .filter-label {
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Stats strip */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stat .lbl {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 6px;
}
.stat .val { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
.stat .delta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* Small touches */
.req { color: var(--danger); margin-left: 2px; }
.total-preview {
  background: var(--cel-blue-light);
  color: var(--cel-blue-dark);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.total-preview .v { font-weight: 800; font-family: 'JetBrains Mono', monospace; font-size: 16px; }

/* Toasts */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: var(--cel-navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); }

/* Loading overlay */
#loadingScreen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 300;
  color: var(--ink-faint);
  font-weight: 600;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-left { padding: 32px 24px; min-height: 220px; }
  .login-pitch h1 { font-size: 32px; margin-bottom: 12px; }
  .login-pitch p { font-size: 15px; }
  .login-foot { margin-top: 20px; }
  .login-right { padding: 28px 20px; align-items: flex-start; }
}

@media (max-width: 768px) {
  .topbar { padding: 10px 16px; }
  .topbar-brand .name { display: none; }
  .container { padding: 20px 14px; }
  .page-head h1 { font-size: 25px; }
  .page-head { margin-bottom: 18px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 12px 16px; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; max-width: none; min-height: 100vh; display: flex; flex-direction: column; }
  .modal-body { flex: 1; }
  .modal-foot { position: sticky; bottom: 0; }
  .filters input[type="search"] { min-width: 0; width: 100%; }
}

/* Stacked-card tables on phones (supplier views) */
@media (max-width: 680px) {
  table.stackable { min-width: 0; }
  table.stackable thead { display: none; }
  table.stackable tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
  }
  table.stackable tbody tr:last-child { border-bottom: none; }
  table.stackable td { display: block; padding: 2px 0; border: none; }
  table.stackable td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
  }
  table.stackable td.stack-wide { grid-column: 1 / -1; }
  table.stackable td.stack-hide { display: none; }
}
