/* ╔══════════════════════════════════════════════════════╗
   ║  TRA MÃ VẬN ĐƠN — Design System & Styles           ║
   ╚══════════════════════════════════════════════════════╝ */

/* ─── CSS Custom Properties ─── */
:root {
  /* Palette */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --accent: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.2);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);
  --delivering: #a855f7;
  --delivering-bg: rgba(168, 85, 247, 0.12);
  --returned: #ec4899;
  --returned-bg: rgba(236, 72, 153, 0.12);

  /* Dark theme (default) */
  --bg-body: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #1a2235;
  --bg-card-hover: #1f2a40;
  --bg-input: #0f172a;
  --border-color: #1e293b;
  --border-focus: var(--primary);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
  --glass: rgba(17, 24, 39, 0.7);

  /* Layout */
  --header-height: 64px;
  --container-max: 1280px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(.4,0,.2,1);
  --transition-base: 250ms cubic-bezier(.4,0,.2,1);
  --transition-slow: 400ms cubic-bezier(.4,0,.2,1);
}

/* ─── Light theme ─── */
[data-theme="light"] {
  --bg-body: #f0f4f8;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f1f5f9;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
  --shadow-md: 0 4px 20px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.1);
  --glass: rgba(255, 255, 255, 0.8);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Animated bg gradient */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 600px;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, var(--primary-glow), transparent),
              radial-gradient(ellipse 60% 40% at 80% 0%, var(--accent-glow), transparent);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══════════ HEADER ═══════════ */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--border-color);
  height: var(--header-height);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 1.6rem;
  color: var(--primary-light);
  text-shadow: 0 0 20px var(--primary-glow);
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ═══════════ BUTTONS ═══════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 2px 12px var(--primary-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--primary-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-icon {
  width: 34px; height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.85rem;
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-card); border-color: var(--border-color); }
.btn-icon.btn-icon-danger:hover { color: var(--danger); background: var(--danger-bg); }

/* ═══════════ HERO / SEARCH SECTION ═══════════ */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}

.hero-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.hero-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 520px;
  margin: 0 auto 32px;
}

/* Search Form */
.search-form {
  max-width: 720px;
  margin: 0 auto;
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.select-wrapper {
  position: relative;
  flex: 0 0 190px;
}

.select-wrapper select {
  width: 100%;
  height: 100%;
  appearance: none;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 36px 12px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}
.select-wrapper select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.7rem;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper input {
  width: 100%;
  height: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 44px 12px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  transition: border-color var(--transition-fast);
}
.input-wrapper input::placeholder { color: var(--text-muted); }
.input-wrapper input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn-paste {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color var(--transition-fast);
}
.btn-paste:hover { color: var(--primary-light); }

/* ─── Detect Indicator ─── */
.detect-indicator {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px dashed var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all var(--transition-base);
  min-height: 42px;
}

.detect-indicator.detected {
  border-color: var(--success);
  border-style: solid;
  background: var(--success-bg);
  color: var(--success);
}

.detect-indicator.multi-detected {
  border-color: var(--info);
  border-style: solid;
  background: var(--info-bg);
  color: var(--info);
}

.detect-indicator.unknown {
  border-color: var(--warning);
  border-style: solid;
  background: var(--warning-bg);
  color: var(--warning);
}

.detect-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.detect-text {
  flex: 1;
  line-height: 1.4;
}

.detect-text .carrier-name {
  font-weight: 700;
  color: var(--text-primary);
}

.detect-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.detect-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--primary-glow);
  color: var(--primary-light);
}

.form-hint {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

/* ═══════════ STATS BAR ═══════════ */
.stats-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.stat-item {
  flex: 1;
  min-width: 110px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.stat-item::after {
  content: '';
  position: absolute;
  bottom: 0; left: 20%; right: 20%;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: all var(--transition-fast);
}

.stat-item:hover, .stat-item.active {
  border-color: var(--primary);
  background: var(--bg-card-hover);
}
.stat-item.active::after { background: var(--primary); left: 10%; right: 10%; }

.stat-transit .stat-count { color: var(--info); }
.stat-delivering .stat-count { color: var(--delivering); }
.stat-delivered .stat-count { color: var(--success); }
.stat-returned .stat-count { color: var(--returned); }
.stat-problem .stat-count { color: var(--danger); }
.stat-pending .stat-count { color: var(--warning); }

.stat-count {
  font-size: 1.5rem;
  font-weight: 800;
  display: block;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ═══════════ TRACKING SECTION ═══════════ */
.tracking-section {
  margin-bottom: 32px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.section-title i { color: var(--primary-light); font-size: 1rem; }

.section-actions {
  display: flex;
  gap: 8px;
}

/* ─── Empty state ─── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state.hidden { display: none; }
.empty-icon { font-size: 3.5rem; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state p { font-size: 0.88rem; }

/* ─── Tracking List ─── */
.tracking-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Tracking Card ─── */
.tracking-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  animation: cardSlideIn 0.35s ease-out both;
}
.tracking-card:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-sm);
}

/* Accent stripe left */
.tracking-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--text-muted);
  border-radius: 3px 0 0 3px;
}
.tracking-card[data-status-group="transit"]::before { background: var(--info); }
.tracking-card[data-status-group="delivering"]::before { background: var(--delivering); }
.tracking-card[data-status-group="delivered"]::before { background: var(--success); }
.tracking-card[data-status-group="returned"]::before { background: var(--returned); }
.tracking-card[data-status-group="problem"]::before { background: var(--danger); }
.tracking-card[data-status-group="pending"]::before { background: var(--warning); }

.tracking-card.hidden { display: none; }

@keyframes cardSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-status-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: var(--bg-input);
  color: var(--text-muted);
}
.tracking-card[data-status-group="transit"] .card-status-icon { background: var(--info-bg); color: var(--info); }
.tracking-card[data-status-group="delivering"] .card-status-icon { background: var(--delivering-bg); color: var(--delivering); }
.tracking-card[data-status-group="delivered"] .card-status-icon { background: var(--success-bg); color: var(--success); }
.tracking-card[data-status-group="returned"] .card-status-icon { background: var(--returned-bg); color: var(--returned); }
.tracking-card[data-status-group="problem"] .card-status-icon { background: var(--danger-bg); color: var(--danger); }
.tracking-card[data-status-group="pending"] .card-status-icon { background: var(--warning-bg); color: var(--warning); }

.card-info {
  flex: 1;
  min-width: 0;
}

.card-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.card-tracking-id {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-carrier-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--primary-glow);
  color: var(--primary-light);
  white-space: nowrap;
}

.card-status-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-eta {
  color: var(--warning);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Loading spinner on card */
.card-loading {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  z-index: 2;
}
.card-loading .spinner { 
  width: 24px; height: 24px; 
  border: 2.5px solid var(--border-color); 
  border-top-color: var(--primary-light); 
  border-radius: 50%; 
  animation: spin 0.7s linear infinite; 
}

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

/* ═══════════ AUTO-CHECK BAR ═══════════ */
.auto-check-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  margin-bottom: 40px;
}

.auto-check-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.auto-check-inner i { color: var(--primary-light); }

.auto-check-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

/* ═══════════ MODAL ═══════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); }

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

/* ─── Modal ETA Header ─── */
.modal-eta {
  background: var(--warning-bg);
  color: var(--warning);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--warning);
}
.modal-eta i { font-size: 1.1rem; }

/* ─── Timeline inside modal ─── */
.timeline {
  position: relative;
  padding-left: 28px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border-color);
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  padding-bottom: 24px;
}
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -23px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--bg-surface);
  z-index: 1;
}

.timeline-item:first-child .timeline-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
  width: 14px;
  height: 14px;
  left: -24px;
  top: 4px;
}

.timeline-desc {
  font-size: 0.88rem;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 2px;
}

.timeline-time {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.timeline-location {
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 2px;
}

/* ═══════════ TOAST NOTIFICATIONS ═══════════ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease-out;
  max-width: 360px;
  min-width: 240px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-success i { color: var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-error i { color: var(--danger); }
.toast.toast-info { border-left: 3px solid var(--info); }
.toast.toast-info i { color: var(--info); }

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

@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ═══════════ SCROLLBAR ═══════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 640px) {
  .hero-title { font-size: 1.6rem; }
  .hero { padding: 32px 0 24px; }

  .form-row {
    flex-direction: column;
  }
  .select-wrapper { flex: none; }

  .btn .btn-label { display: none; }
  .btn i { margin: 0; }
  .btn-primary .btn-label { display: inline; }

  .stats-bar { gap: 6px; }
  .stat-item { padding: 10px 8px; min-width: 80px; }
  .stat-count { font-size: 1.2rem; }

  .section-actions { flex-wrap: wrap; }

  .tracking-card { padding: 12px 14px; gap: 10px; }
  .card-status-icon { width: 36px; height: 36px; font-size: 0.95rem; }
}
