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

:root {
  --navy: #1a2744;
  --navy-light: #243360;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --bg: #fff7ed;
  --white: #ffffff;
  --border: #fed7aa;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --info: #f97316;
  --sidebar-width: 230px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

#sidebar .logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
#sidebar .logo h1 { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
#sidebar .logo p { font-size: 11px; color: rgba(255,255,255,.65); margin-top: 8px; }
.portal-logo-img {
  display: block;
  width: 100%;
  max-width: 170px;
  height: auto;
  border-radius: 8px;
  background: rgba(255,255,255,.96);
  padding: 8px 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

body.public-lastmile-domain #sidebar .portal-logo-img {
  display: none;
}

body.public-lastmile-domain #sidebar .logo p {
  margin-top: 0;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .08em;
}

#sidebar nav { padding: 12px 0; flex: 1; }
#sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
#sidebar nav a.active { color: #fff; background: rgba(249,115,22,.22); border-left-color: #fb923c; }
#sidebar nav a .icon { font-size: 16px; width: 20px; text-align: center; }

#sidebar .sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 11px;
  color: rgba(255,255,255,.35);
}

/* ── MAIN ── */
body.lastmile-customer-only #sidebar {
  display: none;
}

body.lastmile-customer-only #main {
  margin-left: 0;
  width: 100%;
}

body.lastmile-customer-only #topbar {
  padding-left: 28px;
}

#main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
#topbar h2 { font-size: 18px; font-weight: 700; }
#topbar .topbar-right { display: flex; align-items: center; gap: 12px; }

#workspace-tabs {
  position: sticky;
  top: 57px;
  z-index: 45;
  min-height: 42px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 28px 0;
  background: #fff7ed;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.workspace-tab {
  min-width: 126px;
  max-width: 220px;
  height: 34px;
  padding: 0 8px 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  background: #ffedd5;
  color: #9a3412;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.03);
}
.workspace-tab:hover { background: #fed7aa; }
.workspace-tab.active {
  background: var(--white);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 -2px 8px rgba(249,115,22,.10);
}
.workspace-tab .tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-tab .tab-close {
  margin-left: auto;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 16px;
  opacity: .65;
}
.workspace-tab .tab-close:hover { background: rgba(15,23,42,.10); opacity: 1; }
#refresh-btn {
  background: var(--accent); color: #fff; border: none; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
#refresh-btn:hover { background: var(--accent-hover); }
#logout-btn {
  background: var(--accent); color: #fff; border: none; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
#logout-btn:hover { background: var(--accent-hover); }
#export-btn {
  background: #16a34a; color: #fff; border: none; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
#export-btn:hover { background: #15803d; }

#content { padding: 24px 28px; flex: 1; }

/* ── PAGES ── */
.page { display: none; }
.page.active { display: block; }

/* ── CARDS ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-card .icon-box {
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-card.orange .icon-box { background: #fff7ed; }
.stat-card.blue .icon-box { background: #fff7ed; }
.stat-card.green .icon-box { background: #f0fdf4; }
.stat-card.purple .icon-box { background: #fff7ed; }
.stat-card.red .icon-box { background: #fff1f2; }
.stat-card.red .info h3 { color: #dc2626; }
.stat-card[onclick] { transition: transform .12s, box-shadow .12s; }
.stat-card[onclick]:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.10); }
.stat-card[onclick]:active { transform: translateY(0); }
.stat-card .info h3 { font-size: 22px; font-weight: 700; }
.stat-card .info p { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* ── SECTION ── */
.section {
  background: var(--white);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.section-header h3 { font-size: 15px; font-weight: 700; }

.ae-filter-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: calc(100vw - var(--sidebar-width) - 360px);
  padding-bottom: 2px;
}
.ae-filter-row input,
.ae-filter-row select {
  flex: 0 0 auto;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  height: 32px;
}
.ae-filter-row input { width: 260px; }
.ae-filter-row select { min-width: 112px; max-width: 165px; }
#ae-customer-filter { min-width: 170px; max-width: 210px; }
#ae-airline-filter { min-width: 135px; max-width: 180px; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody tr.expandable { cursor: pointer; }
tbody tr.expanded { background: #eff6ff; }

/* ── BADGES ── */
.badge {
  display: inline-block; padding: 3px 9px;
  border-radius: 20px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
}
.badge-pending  { background: #fff7ed; color: #c2410c; }
.badge-progress { background: #fff7ed; color: #c2410c; }
.badge-cleared { background: #f0fdf4; color: #15803d; }
.badge-complete { background: #f0fdf4; color: #15803d; }
.badge-partial  { background: #fef3c7; color: #92400e; }
.badge-warning  { background: #fff7ed; color: #c2410c; }
.badge-blue     { background: #fff7ed; color: #c2410c; }
.badge-voided { background: #fef2f2; color: #b91c1c; }
.badge-inventory { background: #f0fdf4; color: #15803d; }

/* ── EXPAND PANEL ── */
.expand-row td { padding: 0; }
.expand-panel {
  padding: 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
}
.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.info-item label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.info-item p { font-size: 13px; margin-top: 2px; }

/* ── TABS ── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn {
  padding: 9px 18px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted);
  transition: all .15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; border: none;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: #d97706; color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-sync { background: #7c3aed; color: #fff; }
.btn-sync:hover { background: #6d28d9; }
.btn-sync:disabled { background: #a78bfa; cursor: not-allowed; }

/* ── FORM ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border .15s;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent);
}
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  display: none;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal .modal-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 20px; }

/* ── TOAST ── */
#toast-container {
  position: fixed; top: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── LOADING ── */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 32px; color: var(--text-muted); }

/* ── SUBTABS ── */
.subtabs { display: flex; gap: 8px; margin-bottom: 20px; }
.subtab-btn {
  padding: 8px 20px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--white); cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text-muted); transition: all .15s;
}
.subtab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── SEARCH ── */
.search-bar {
  display: flex; gap: 10px; margin-bottom: 16px; align-items: center;
}
.search-bar input {
  flex: 1; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

/* ── SORT ── */
thead th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
thead th[data-sort]:hover { background: #eef2f7; }
thead th.sort-asc .sort-icon::after { content: ' ▲'; font-size:10px; }
thead th.sort-desc .sort-icon::after { content: ' ▼'; font-size:10px; }
thead th[data-sort] span { opacity: .4; font-size: 10px; }
thead th.sort-asc span, thead th.sort-desc span { opacity: 1; }
thead th.sort-asc span::before { content: '▲'; }
thead th.sort-desc span::before { content: '▼'; }

/* ── EMPTY ── */
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.empty-state .icon { font-size: 36px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ── CONFIRM ── */
.confirm-box { background: #fef9c3; border: 1px solid #fbbf24; border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  #sidebar { width: 160px; }
  #sidebar .logo h1 { font-size: 13px; }
  #sidebar .logo p, #sidebar .sidebar-footer { display: none; }
  .portal-logo-img { max-width: 120px; padding: 6px 8px; }
  #sidebar nav a .icon { font-size: 14px; width: 16px; }
  #sidebar nav a { padding: 10px 12px; font-size: 12px; gap: 8px; }
  #main { margin-left: 160px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid .stat-card:last-child { grid-column: 1 / -1; }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  #content { padding: 16px; }
}

/* ── LAST MILE ── */
.lastmile-card { overflow: hidden; }
.lastmile-form { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.lastmile-form h4 { margin-top: 4px; font-size: 13px; color: var(--navy); border-top: 1px solid var(--border); padding-top: 12px; }
.lastmile-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--text-muted); }
.lastmile-form input, .lastmile-form textarea, .lastmile-form select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; color: var(--text); background: #fff;
}
.lastmile-form input:focus, .lastmile-form textarea:focus, .lastmile-form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(249,115,22,.12); }
.lastmile-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.lastmile-two label { min-width: 0; }
.lastmile-three { display: grid; grid-template-columns: 1.4fr .7fr 1fr; gap: 10px; }
.lastmile-four { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.lastmile-package-main-row { display: grid; grid-template-columns: 1.2fr .8fr 1fr; gap: 10px; align-items: end; }
.lastmile-dim-row { display: grid; grid-template-columns: repeat(3, minmax(110px, 1fr)); gap: 10px; align-items: end; }
.lastmile-international-box { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: #f8fafc; margin-top: 8px; }
.lastmile-international-box h4 { border-top: 0; padding-top: 0; margin: 0 0 10px; font-size: 13px; color: var(--navy); }
.lastmile-intl-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(110px, .62fr) minmax(0, 1.05fr); gap: 12px; align-items: end; margin-bottom: 10px; }
.lastmile-intl-grid-two { grid-template-columns: 1fr 1fr; }
.lastmile-intl-grid label { min-width: 0; }
.lastmile-intl-grid input, .lastmile-intl-grid select { min-height: 42px; }
.lastmile-package-row { display: grid; grid-template-columns: minmax(150px,1.2fr) minmax(86px,.65fr) minmax(130px,.95fr) repeat(3, minmax(86px,.62fr)); gap: 12px; align-items: end; }
.lastmile-package-row label { min-width: 0; }
.lastmile-package-row input, .lastmile-package-row select { padding: 7px 8px; min-width: 0; width: 100%; font-size: 13px; }
.lastmile-check { flex-direction: row !important; align-items: center; font-weight: 600 !important; }
.lastmile-check input { width: auto; }
.lastmile-status { min-height: 18px; font-size: 12px; color: var(--text-muted); }
.lastmile-status.error { color: var(--error); font-weight: 700; }
.lastmile-status.success { color: var(--success); font-weight: 700; }
.lastmile-json { margin:0; padding:16px; min-height:520px; max-height:720px; overflow:auto; background:#0f172a; color:#e2e8f0; font-size:12px; line-height:1.45; white-space:pre-wrap; border-radius:0 0 8px 8px; }
.lastmile-help { color: var(--text-muted); font-size: 12px; line-height: 1.45; background:#f8fafc; border:1px solid var(--border); border-radius:6px; padding:10px; }
.lastmile-rate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc; }
.lastmile-rate-grid label { display: grid; grid-template-columns: 1fr 92px 92px; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px; }
.lastmile-rate-grid span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 700; display:flex; flex-direction:column; gap:2px; }
.lastmile-dropbox { border:2px dashed var(--border); border-radius:10px; padding:16px; text-align:center; cursor:pointer; background:#f8fafc; color:var(--text-muted); transition:.15s; }
.lastmile-dropbox:hover, .lastmile-dropbox.drag { border-color:var(--accent); background:#fff7ed; color:var(--text); }
@media (max-width: 1100px) {
  #page-lastmile > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 820px) {
  .lastmile-package-row { grid-template-columns: repeat(3, minmax(110px, 1fr)); }
}
@media (max-width: 720px) {
  .lastmile-two, .lastmile-three, .lastmile-four, .lastmile-package-main-row, .lastmile-dim-row, .lastmile-intl-grid, .lastmile-intl-grid-two, .lastmile-package-row { grid-template-columns: 1fr; }
  .lastmile-rate-grid { grid-template-columns: 1fr; }
}

.lastmile-lookup-results {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg, #fff);
  max-height: 260px;
  overflow: auto;
  margin-top: -8px;
  margin-bottom: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}
.lastmile-lookup-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.lastmile-lookup-item:last-child { border-bottom: none; }
.lastmile-lookup-item:hover { background: var(--hover-bg, #f3f4f6); }
.lastmile-lookup-item strong { display:block; }
.lastmile-lookup-item span { color: var(--text-muted); font-size: 12px; }

.portal-action-status {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, .28);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}
.portal-action-status-box {
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: 420px;
  padding: 18px 22px;
  border-radius: 14px;
  background: var(--card-bg, #fff);
  box-shadow: 0 18px 55px rgba(15, 23, 42, .28);
  border: 1px solid var(--border);
}
.portal-action-status-box strong { display:block; font-size:15px; margin-bottom:4px; }
.portal-action-status-box p { margin:0; color:var(--text-muted); font-size:12px; }
.portal-action-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(37, 99, 235, .25);
  border-top-color: var(--primary, #2563eb);
  animation: spin .75s linear infinite;
  flex: 0 0 auto;
}
button.portal-action-busy {
  opacity: .68;
  cursor: wait !important;
}

.table-sort-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}
.table-sort-btn:hover { color: var(--primary); text-decoration: underline; }
