/* ═══════════════════════════════════════════
   TALARIA PORTAL — DESIGN TOKENS
   Same Nexus/Hydra Teal system as Atlas V2
   ═══════════════════════════════════════════ */
:root, [data-theme="light"] {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.9rem  + 0.5vw,  1.125rem);
  --text-lg:   clamp(1.125rem, 0.95rem + 0.85vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1rem    + 1.5vw,  2.25rem);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
  --color-bg: #f7f6f2;
  --color-surface: #f9f8f5;
  --color-surface-2: #fbfbf9;
  --color-surface-offset: #f3f0ec;
  --color-surface-offset-2: #edeae5;
  --color-surface-dynamic: #e6e4df;
  --color-divider: #dcd9d5;
  --color-border: #d4d1ca;
  --color-tx: #28251d;
  --color-tx-muted: #7a7974;
  --color-tx-faint: #bab9b4;
  --color-tx-inverse: #f9f8f4;
  --color-primary: #01696f;
  --color-primary-hover: #0c4e54;
  --color-primary-active: #0f3638;
  --color-primary-hl: #cedcd8;
  --color-error: #a12c7b;
  --color-error-hl: #e0ced7;
  --color-success: #437a22;
  --color-success-hl: #d4dfcc;
  --color-warning: #964219;
  --color-warning-hl: #ddcfc6;
  --color-blue: #006494;
  --color-blue-hl: #c6d8e4;
  --color-orange: #da7101;
  --color-orange-hl: #e7d7c4;
  --sidebar-width: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body { font-family: 'Inter', system-ui, sans-serif; color: var(--color-tx); background: var(--color-bg); line-height: 1.5; }

/* ═══════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════ */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: var(--color-bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-xl);
  padding: 2.5rem 2rem; box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-title { font-size: var(--text-lg); font-weight: 700; margin-top: 0.75rem; }
.login-subtitle { font-size: var(--text-sm); color: var(--color-tx-muted); margin-top: 0.25rem; }
.login-tabs { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 1px solid var(--color-divider); }
.login-tab {
  flex: 1; padding: 0.5rem; font-size: var(--text-sm); font-weight: 500;
  background: none; border: none; cursor: pointer; color: var(--color-tx-muted);
  border-bottom: 2px solid transparent; transition: var(--transition-interactive);
}
.login-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-error { font-size: var(--text-sm); color: var(--color-error); background: var(--color-error-hl); padding: 0.5rem 0.75rem; border-radius: var(--radius-md); }
.login-success { font-size: var(--text-sm); color: var(--color-success); background: var(--color-success-hl); padding: 0.5rem 0.75rem; border-radius: var(--radius-md); }

/* ═══════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--color-tx); }
.form-help { font-size: var(--text-sm); color: var(--color-tx-muted); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.5rem 0.75rem; font-size: var(--text-sm);
  font-family: inherit; border: 1px solid var(--color-border);
  border-radius: var(--radius-md); background: var(--color-surface-2);
  color: var(--color-tx); transition: var(--transition-interactive);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-hl); }
.form-input-sm, .form-select-sm { padding: 0.375rem 0.625rem; font-size: var(--text-xs); }
.form-textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.75rem; }

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.5rem 1rem; font-size: var(--text-sm); font-weight: 600;
  font-family: inherit; border: 1px solid transparent; border-radius: var(--radius-md);
  cursor: pointer; transition: var(--transition-interactive); white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: var(--color-tx-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-ghost { background: transparent; color: var(--color-tx-muted); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-tx); }
.btn-sm { padding: 0.25rem 0.625rem; font-size: var(--text-xs); }
.btn-full { width: 100%; }
.btn.loading { opacity: 0.7; pointer-events: none; }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

/* ═══════════════════════════════════════════
   APP SHELL — SIDEBAR
   ═══════════════════════════════════════════ */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width); background: var(--color-surface);
  border-right: 1px solid var(--color-divider);
  display: flex; flex-direction: column; position: fixed;
  top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.25s ease;
}
.sidebar-header { display: flex; align-items: center; gap: 0.75rem; padding: 1.25rem 1rem; border-bottom: 1px solid var(--color-divider); }
.sidebar-brand { font-size: var(--text-sm); font-weight: 700; color: var(--color-primary); }
.sidebar-nav { flex: 1; padding: 0.75rem 0.5rem; display: flex; flex-direction: column; gap: 0.125rem; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 0.75rem;
  font-size: var(--text-sm); font-weight: 500; color: var(--color-tx-muted);
  border-radius: var(--radius-md); cursor: pointer; text-decoration: none;
  transition: var(--transition-interactive);
}
.nav-item:hover { background: var(--color-surface-offset); color: var(--color-tx); }
.nav-item.active { background: var(--color-primary-hl); color: var(--color-primary); font-weight: 600; }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--color-divider); display: flex; align-items: center; justify-content: space-between; }
.sidebar-user { display: flex; align-items: center; gap: 0.625rem; overflow: hidden; }
.user-avatar {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: var(--color-primary); color: var(--color-tx-inverse);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 700; flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { font-size: var(--text-xs); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.65rem; color: var(--color-tx-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Mobile header */
.mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  background: var(--color-surface); border-bottom: 1px solid var(--color-divider);
  padding: 0.75rem 1rem; align-items: center; justify-content: space-between;
}
.mobile-brand { font-size: var(--text-sm); font-weight: 700; color: var(--color-primary); }
.menu-toggle { background: none; border: none; cursor: pointer; color: var(--color-tx); padding: 0.25rem; }

/* Main content */
.main-content { flex: 1; margin-left: var(--sidebar-width); padding: 1.5rem 2rem; min-height: 100vh; }

/* ═══════════════════════════════════════════
   PAGE STRUCTURE
   ═══════════════════════════════════════════ */
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem; }
.page-title { font-size: var(--text-lg); font-weight: 700; }
.page-date { font-size: var(--text-sm); color: var(--color-tx-muted); }
.page-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.page-body { display: flex; flex-direction: column; gap: 1.5rem; }

/* ═══════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.kpi-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.kpi-label { font-size: var(--text-xs); font-weight: 500; color: var(--color-tx-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: var(--text-xs); color: var(--color-tx-muted); }

/* ═══════════════════════════════════════════
   DATA TABLE
   ═══════════════════════════════════════════ */
.table-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.table-card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-divider); font-weight: 600; font-size: var(--text-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left; padding: 0.625rem 1rem; font-weight: 600;
  font-size: var(--text-xs); color: var(--color-tx-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--color-surface-offset); border-bottom: 1px solid var(--color-divider);
}
.data-table td { padding: 0.625rem 1rem; border-bottom: 1px solid var(--color-divider); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-surface-offset); }
.data-table .clickable { cursor: pointer; }
.data-table .clickable:hover { color: var(--color-primary); }

/* ═══════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; padding: 0.125rem 0.5rem;
  font-size: 0.7rem; font-weight: 600; border-radius: var(--radius-full);
  white-space: nowrap; text-transform: uppercase; letter-spacing: 0.02em;
}
.badge-ordered { background: #f0e6ff; color: #7c3aed; }
.badge-pending { background: var(--color-warning-hl); color: var(--color-warning); }
.badge-scheduled { background: var(--color-blue-hl); color: var(--color-blue); }
.badge-in-route { background: #dbeafe; color: #2563eb; }
.badge-in-transit, .badge-dispatched { background: var(--color-blue-hl); color: var(--color-blue); }
.badge-delivered, .badge-completed, .badge-paid { background: var(--color-success-hl); color: var(--color-success); }
.badge-cancelled, .badge-failed { background: var(--color-error-hl); color: var(--color-error); }
.badge-draft { background: var(--color-surface-offset); color: var(--color-tx-muted); }
.badge-sent, .badge-active { background: var(--color-primary-hl); color: var(--color-primary); }
.badge-overdue { background: var(--color-orange-hl); color: var(--color-orange); }

/* ═══════════════════════════════════════════
   CARDS / SECTIONS
   ═══════════════════════════════════════════ */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 1.25rem;
}
.card-header { font-weight: 600; font-size: var(--text-sm); margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--color-divider); }
.info-box { background: var(--color-surface-offset); border-radius: var(--radius-md); padding: 0.75rem; font-size: var(--text-sm); }
.info-row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.375rem 0; }
.info-row + .info-row { border-top: 1px solid var(--color-divider); }
.info-label { color: var(--color-tx-muted); flex-shrink: 0; }
.info-value { font-weight: 500; text-align: right; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-tx-muted); font-size: var(--text-sm); }
.empty-state svg { margin-bottom: 0.75rem; opacity: 0.4; }

/* ═══════════════════════════════════════════
   ROUTE CARD
   ═══════════════════════════════════════════ */
.route-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem;
}
.route-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.route-name { font-weight: 700; font-size: var(--text-sm); }
.route-id { font-size: var(--text-xs); color: var(--color-primary); font-weight: 600; }
.route-meta { font-size: var(--text-xs); color: var(--color-tx-muted); display: flex; gap: 1rem; flex-wrap: wrap; }
.route-stops { display: flex; flex-direction: column; gap: 0.375rem; }
.route-stop { display: flex; align-items: flex-start; gap: 0.5rem; font-size: var(--text-sm); padding: 0.375rem 0; }
.route-stop-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 0.3rem; flex-shrink: 0; }
.route-stop-dot.pending { background: var(--color-warning); }
.route-stop-dot.delivered { background: var(--color-success); }
.route-stop-dot.in-transit { background: var(--color-blue); }
.route-stop-line { width: 2px; height: 16px; background: var(--color-divider); margin-left: 4px; }

/* Map container */
.route-map { width: 100%; height: 300px; border-radius: var(--radius-md); background: var(--color-surface-offset); border: 1px solid var(--color-border); }

/* ═══════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal-panel {
  background: var(--color-surface); border-radius: var(--radius-xl);
  border: 1px solid var(--color-border); box-shadow: var(--shadow-lg);
  width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal-md { max-width: 520px; }
.modal-lg { max-width: 700px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-divider); }
.modal-title { font-weight: 700; font-size: var(--text-base); }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-tx-muted); line-height: 1; padding: 0.25rem; }
.modal-close:hover { color: var(--color-tx); }
.modal-body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--color-divider); }

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  padding: 0.75rem 1rem; border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500;
  box-shadow: var(--shadow-md); animation: toastIn 0.3s ease;
  max-width: 360px;
}
.toast-success { background: var(--color-success-hl); color: var(--color-success); border: 1px solid var(--color-success); }
.toast-error { background: var(--color-error-hl); color: var(--color-error); border: 1px solid var(--color-error); }
.toast-info { background: var(--color-blue-hl); color: var(--color-blue); border: 1px solid var(--color-blue); }
@keyframes toastIn { from { opacity: 0; transform: translateY(1rem); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════
   SKELETONS
   ═══════════════════════════════════════════ */
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.skeleton-card {
  height: 120px; border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-surface-dynamic) 50%, var(--color-surface-offset) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ═══════════════════════════════════════════
   CHANGE REQUEST LIST
   ═══════════════════════════════════════════ */
.cr-list { display: flex; flex-direction: column; gap: 0.5rem; }
.cr-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem; background: var(--color-surface-offset); border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.cr-item-info { display: flex; flex-direction: column; gap: 0.125rem; }
.cr-item-type { font-weight: 600; text-transform: capitalize; }
.cr-item-details { color: var(--color-tx-muted); }
.cr-item-date { font-size: var(--text-xs); color: var(--color-tx-faint); }
.badge-cr-pending { background: var(--color-warning-hl); color: var(--color-warning); }
.badge-cr-approved { background: var(--color-success-hl); color: var(--color-success); }
.badge-cr-denied { background: var(--color-error-hl); color: var(--color-error); }

/* ═══════════════════════════════════════════
   PROFILE FORM
   ═══════════════════════════════════════════ */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.profile-section { display: flex; flex-direction: column; gap: 1rem; }

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; padding: 4.5rem 1rem 1.5rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .profile-grid { grid-template-columns: 1fr; }
  .modal-panel { margin: 0.5rem; }
  .form-row { grid-template-columns: 1fr; }
  .data-table { font-size: var(--text-xs); }
  .data-table th, .data-table td { padding: 0.5rem 0.625rem; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════
   PLACE ORDER — Location-based
   ═══════════════════════════════════════════ */
.order-location-info {
  margin-top: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: var(--color-bg-subtle);
  border-radius: 8px;
  font-size: var(--text-sm);
  color: var(--color-tx-muted);
  line-height: 1.4;
}

/* ═══════════════════════════════════════════
   CSV IMPORT
   ═══════════════════════════════════════════ */
.csv-upload-area {
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.csv-upload-area:hover {
  border-color: var(--color-primary);
  background: rgba(0, 128, 128, 0.03);
}
.csv-upload-area.dragover {
  border-color: var(--color-primary);
  background: rgba(0, 128, 128, 0.06);
}
.csv-preview-scroll {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.csv-preview-scroll table { font-size: var(--text-xs); }
.csv-preview-scroll th {
  position: sticky;
  top: 0;
  background: var(--color-bg-subtle);
  z-index: 1;
}
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-bg-subtle);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 4px;
  transition: width 0.3s;
}
.csv-validation-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  padding: 0.25rem 0;
}



/* ═══════════════════════════════════════════
   ORDER GROUPING
   ═══════════════════════════════════════════ */
.order-group-header td {
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}
.order-group-header:hover td {
  background: var(--color-surface-offset, #f0f0f2);
}
.order-group-child td {
  font-size: var(--text-sm);
  border-bottom: 1px dashed var(--color-border, #e5e7eb);
}

/* ═══════════════════════════════════════════
   FILTER ROW (Feature #4)
   ═══════════════════════════════════════════ */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  align-items: flex-end;
}
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 130px;
}
.filter-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-tx-muted, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ═══════════════════════════════════════════
   CHECKBOX LABEL (Feature #7)
   ═══════════════════════════════════════════ */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm, 0.875rem);
  cursor: pointer;
  padding: 0.375rem 0;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary, #6366f1);
  cursor: pointer;
}

/* Pulse animation for In Route indicator */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ═══════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════ */
@media print {
  .sidebar, .mobile-header, .toast-container { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
  .modal-overlay { position: static; background: none; }
}
