/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #ca8a04;
  --warning-bg: #fef9c3;
  --error: #dc2626;
  --error-bg: #fee2e2;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --bg: #f8fafc;
  --white: #ffffff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --nav-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===========================
   Navigation
   =========================== */
.navbar {
  height: var(--nav-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.nav-brand svg { width: 26px; height: 26px; }

.nav-links {
  display: flex;
  align-items: center;
  list-style: none;
  gap: 0.125rem;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-link:hover { color: var(--primary); background: var(--primary-light); }
.nav-link.active { color: var(--primary); background: var(--primary-light); }

.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

.status-dot {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
}

.status-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
}

.status-dot.online::before { background: var(--success); }
.status-dot.offline::before { background: var(--error); }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  color: var(--text);
  margin-left: auto;
  font-size: 1.5rem;
  line-height: 1;
}

/* ===========================
   Page Layout
   =========================== */
.page { min-height: calc(100vh - var(--nav-h)); padding: 2rem 1.5rem 4rem; }
.container { max-width: 1100px; margin: 0 auto; }
.container-sm { max-width: 740px; margin: 0 auto; }

.page-header { margin-bottom: 2rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 0.375rem; }
.page-subtitle { font-size: 0.9375rem; color: var(--text-muted); }

.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
.col-stack { display: flex; flex-direction: column; gap: 1.5rem; }

/* ===========================
   Cards
   =========================== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}

.card-title { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.card-body { padding: 1.5rem; }
.card-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: #f9fafb; }

/* ===========================
   Stat Cards
   =========================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.stat-icon { font-size: 1.625rem; margin-bottom: 0.625rem; display: block; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1; margin-bottom: 0.375rem; }
.stat-label { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.stat-change { font-size: 0.8125rem; font-weight: 500; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--error); }
.stat-change.neutral { color: var(--text-muted); }

/* ===========================
   Forms
   =========================== */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.form-label .req { color: var(--error); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--text-light); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-hint { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.375rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ===========================
   Buttons
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: var(--white); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--white); color: var(--primary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--primary-light); border-color: var(--primary); }
.btn-outline-danger { background: var(--white); color: var(--error); border-color: var(--error); }
.btn-outline-danger:hover:not(:disabled) { background: var(--error-bg); }
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }
.btn-sm { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===========================
   Badges
   =========================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6875rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-neutral { background: #f3f4f6; color: var(--text-muted); }

/* ===========================
   Table
   =========================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #f9fafb;
}

tbody td { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-size: 0.9375rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

/* ===========================
   Upload Zone
   =========================== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafafa;
  position: relative;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon { font-size: 3rem; margin-bottom: 0.75rem; display: block; }
.upload-title { font-size: 1.0625rem; font-weight: 600; color: var(--text); margin-bottom: 0.375rem; }
.upload-hint { font-size: 0.875rem; color: var(--text-muted); }

/* ===========================
   File Items
   =========================== */
.file-list { display: flex; flex-direction: column; gap: 0.625rem; }

.file-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-icon { font-size: 1.5rem; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.9375rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 0.8125rem; color: var(--text-muted); }
.file-remove { cursor: pointer; color: var(--text-muted); font-size: 1.25rem; padding: 0.25rem; border-radius: 4px; background: none; border: none; }
.file-remove:hover { color: var(--error); background: var(--error-bg); }

/* ===========================
   Result Panels
   =========================== */
.result-panel { display: none; }
.result-panel.show { display: block; }

.result-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.result-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.375rem;
  flex-shrink: 0;
}

.result-icon.success-bg { background: var(--success-bg); }
.result-title { font-size: 1rem; font-weight: 600; }
.result-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 1px; }

.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }

.result-item {
  padding: 1rem;
  background: #f9fafb;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.result-item-label {
  font-size: 0.71875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
}

.result-item-value { font-size: 1.0625rem; font-weight: 700; color: var(--text); }
.result-item-value.mono { font-family: 'Courier New', Courier, monospace; letter-spacing: 0.04em; color: var(--primary-dark); }

/* ===========================
   Confidence Bar
   =========================== */
.confidence-wrap { margin-top: 0.75rem; }
.confidence-label { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 0.375rem; display: flex; justify-content: space-between; }
.confidence-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.confidence-fill { height: 100%; border-radius: 3px; background: var(--primary); transition: width 0.6s ease; }
.confidence-fill.high { background: var(--success); }
.confidence-fill.medium { background: var(--warning); }
.confidence-fill.low { background: var(--error); }

/* ===========================
   Duty Breakdown
   =========================== */
.duty-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  background: var(--primary);
  color: var(--white);
  border-radius: var(--radius);
  margin-top: 1rem;
}

.duty-total-label { font-size: 0.9375rem; font-weight: 500; opacity: 0.9; }
.duty-total-value { font-size: 1.5rem; font-weight: 700; }

/* ===========================
   Timeline
   =========================== */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; left: 0.625rem; top: 0.5rem; bottom: 0.5rem; width: 2px; background: var(--border); }

.timeline-item { position: relative; padding-bottom: 1.75rem; }
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -1.625rem;
  top: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 50%;
  background: var(--border);
  border: 2.5px solid var(--white);
  box-shadow: 0 0 0 1.5px var(--border);
}

.timeline-item.done .timeline-dot { background: var(--success); box-shadow: 0 0 0 1.5px var(--success); }
.timeline-item.active .timeline-dot { background: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,0.2), 0 0 0 1.5px var(--primary); }
.timeline-item.flagged .timeline-dot { background: var(--error); box-shadow: 0 0 0 1.5px var(--error); }

.timeline-title { font-size: 0.9375rem; font-weight: 600; color: var(--text); margin-bottom: 0.125rem; }
.timeline-desc { font-size: 0.875rem; color: var(--text-muted); }
.timeline-date { font-size: 0.8125rem; color: var(--text-light); margin-top: 0.25rem; }

/* ===========================
   Toast
   =========================== */
.toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  pointer-events: all;
  animation: toastIn 0.25s ease;
}

.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-warning { border-left-color: var(--warning); }
.toast-icon { font-size: 1.125rem; flex-shrink: 0; padding-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.toast-message { font-size: 0.8125rem; color: var(--text-muted); margin-top: 1px; }
.toast-close { cursor: pointer; color: var(--text-light); font-size: 1.375rem; line-height: 1; flex-shrink: 0; background: none; border: none; }
.toast-close:hover { color: var(--text); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(1rem); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===========================
   Spinner
   =========================== */
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

.spinner-blue {
  border-color: rgba(29,78,216,0.2);
  border-top-color: var(--primary);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===========================
   Alert / Info Box
   =========================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  border: 1px solid transparent;
  margin-bottom: 1.25rem;
}

.alert-icon { font-size: 1.125rem; flex-shrink: 0; }
.alert-info { background: var(--primary-light); border-color: #93c5fd; color: var(--primary-dark); }
.alert-warning { background: var(--warning-bg); border-color: #fde047; color: #713f12; }
.alert-error { background: var(--error-bg); border-color: #fca5a5; color: #7f1d1d; }

/* ===========================
   Quick Actions
   =========================== */
.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.75rem 1.5rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.action-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.action-icon { font-size: 2.25rem; margin-bottom: 0.875rem; }
.action-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.375rem; color: var(--text); }
.action-desc { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.5; }

/* ===========================
   Search bar
   =========================== */
.search-bar { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.search-bar .form-input { flex: 1; }

/* ===========================
   Shipment cards (status page)
   =========================== */
.shipment-list { display: flex; flex-direction: column; gap: 0.75rem; }

.shipment-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  border-left: 4px solid transparent;
}

.shipment-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.shipment-card.active { border-left-color: var(--primary); background: var(--primary-light); }

.shipment-id { font-family: 'Courier New', monospace; font-size: 0.875rem; font-weight: 600; color: var(--primary-dark); }
.shipment-desc { font-size: 0.9375rem; font-weight: 500; }
.shipment-route { font-size: 0.8125rem; color: var(--text-muted); }
.shipment-meta { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
.shipment-date { font-size: 0.8125rem; color: var(--text-light); }

/* ===========================
   Doc types / extracted fields
   =========================== */
.doc-types-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.625rem; }

.doc-type-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.doc-type-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }

.fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.875rem; }

.field-item {
  padding: 0.875rem 1rem;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field-key { font-size: 0.71875rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.3rem; }
.field-value { font-size: 0.9375rem; color: var(--text); font-weight: 500; }

/* ===========================
   Section divider
   =========================== */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.section-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===========================
   Step indicator
   =========================== */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 2rem;
}

.step {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.step-num {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step.active .step-num { background: var(--primary); color: white; }
.step.active { color: var(--primary); }
.step.done .step-num { background: var(--success); color: white; }
.step.done { color: var(--success); }

.step-connector { flex: 1; height: 2px; background: var(--border); min-width: 2rem; }
.step-connector.done { background: var(--success); }

/* ===========================
   Progress bar (clearance)
   =========================== */
.progress-bar { height: 10px; border-radius: 5px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 5px; transition: width 0.6s ease; }
.progress-fill.blue { background: var(--primary); }
.progress-fill.green { background: var(--success); }

/* ===========================
   Misc utilities
   =========================== */
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.font-mono { font-family: 'Courier New', Courier, monospace; }
.font-bold { font-weight: 700; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 1rem; }
.hidden { display: none; }

/* ===========================
   Responsive
   =========================== */
@media (max-width: 900px) {
  .grid-2-1 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--white);
    flex-direction: column;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    gap: 0.25rem;
    z-index: 99;
  }

  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
  .nav-actions { display: none; }

  .page { padding: 1.25rem 1rem 3rem; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .actions-grid { grid-template-columns: 1fr; }
}
