/* ============================================================
   ALBERDI TRANSPORTADORA — Design System
   Tokens, Reset, Componentes Base
   ============================================================ */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&family=Source+Sans+3:wght@300;400;500;600;700&display=swap');

/* ============================================================
   1. TOKENS (CSS Variables)
   ============================================================ */
:root {
  /* — Cores Primárias — */
  --primary-900: #1E3A8A;
  --primary-800: #1E40AF;
  --primary-700: #1D4ED8;
  --primary-600: #2563EB;
  --primary-500: #3B82F6;
  --primary-400: #60A5FA;
  --primary-300: #93C5FD;
  --primary-200: #BFDBFE;
  --primary-100: #DBEAFE;
  --primary-50:  #EFF6FF;

  --primary:       var(--primary-800);
  --primary-light:  var(--primary-500);
  --primary-hover:  var(--primary-700);

  /* — Acento — */
  --accent:    #F97316;
  --accent-hover: #EA580C;

  /* — Semânticas — */
  --success:   #16A34A;
  --success-bg:#F0FDF4;
  --warning:   #EAB308;
  --warning-bg:#FEFCE8;
  --danger:    #DC2626;
  --danger-bg: #FEF2F2;
  --info:      #0EA5E9;
  --info-bg:   #F0F9FF;

  /* — Superfícies — */
  --bg:        #F8FAFC;
  --surface:   #FFFFFF;
  --surface-hover: #F1F5F9;
  --border:    #E2E8F0;
  --border-light: #F1F5F9;

  /* — Texto — */
  --text:        #0F172A;
  --text-muted:  #475569;
  --text-light:  #94A3B8;
  --text-inverse:#FFFFFF;

  /* — Tipografia — */
  --font-heading: 'Lexend', sans-serif;
  --font-body:    'Source Sans 3', sans-serif;

  /* — Tamanhos — */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;

  /* — Espaçamento — */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* — Bordas — */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* — Sombras — */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);

  /* — Transições — */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* — Layout — */
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --header-height: 64px;
  --container-max: 1280px;
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--primary-hover); }

img { max-width: 100%; display: block; }

ul, ol { list-style: none; }

/* ============================================================
   3. UTILITÁRIOS
   ============================================================ */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-light { color: var(--text-light); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ============================================================
   4. BOTÕES
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-sm);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.btn-accent {
  background: var(--accent);
  color: var(--text-inverse);
}
.btn-accent:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover {
  background: var(--primary-50);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
}
.btn-danger:hover {
  background: #B91C1C;
}

.btn-success {
  background: var(--success);
  color: var(--text-inverse);
}
.btn-success:hover {
  background: #15803D;
}

.btn-sm {
  padding: 6px 14px;
  font-size: var(--text-xs);
}

.btn-lg {
  padding: 14px 28px;
  font-size: var(--text-base);
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-md);
}

/* ============================================================
   5. CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition-fast);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
}

/* — KPI Card — */
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  transition: all var(--transition-fast);
}
.kpi-card:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-md);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg {
  width: 24px;
  height: 24px;
}

.kpi-icon-blue    { background: var(--primary-100); color: var(--primary); }
.kpi-icon-orange  { background: #FFF7ED; color: var(--accent); }
.kpi-icon-green   { background: var(--success-bg); color: var(--success); }
.kpi-icon-red     { background: var(--danger-bg); color: var(--danger); }

.kpi-content { flex: 1; }
.kpi-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}
.kpi-value {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.kpi-change {
  font-size: var(--text-xs);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }

/* ============================================================
   6. BADGES / STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-blue    { background: #DBEAFE; color: #1D4ED8; }
.badge-green   { background: #DCFCE7; color: #15803D; }
.badge-yellow  { background: #FEF3C7; color: #B45309; }
.badge-red     { background: #FEE2E2; color: #DC2626; }
.badge-gray    { background: #F1F5F9; color: #475569; }
.badge-orange  { background: #FFEDD5; color: #C2410C; }
.badge-purple  { background: #F3E8FF; color: #7C3AED; }

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ============================================================
   7. INPUTS & FORMS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
  color: var(--text-light);
}

.form-input.error {
  border-color: var(--danger);
}
.form-input.error:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-light);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394A3B8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ============================================================
   8. TABELAS
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table thead {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.table tbody tr {
  transition: background var(--transition-fast);
}
.table tbody tr:hover {
  background: var(--primary-50);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================================================
   9. MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateY(20px) scale(0.97);
  transition: transform var(--transition-base);
}
.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

/* ============================================================
   10. PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-4) 0;
}

.pagination-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.pagination-btn:hover {
  background: var(--primary-50);
  border-color: var(--primary-200);
  color: var(--primary);
}
.pagination-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}
.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   11. STEPPER (Multi-step form)
   ============================================================ */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: var(--space-8);
}

.step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: var(--text-sm);
  border: 2px solid var(--border);
  color: var(--text-light);
  background: var(--surface);
  transition: all var(--transition-base);
  flex-shrink: 0;
}

.step.active .step-circle {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--text-inverse);
}

.step.completed .step-circle {
  border-color: var(--success);
  background: var(--success);
  color: var(--text-inverse);
}

.step-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-light);
  transition: color var(--transition-base);
}
.step.active .step-label { color: var(--primary); font-weight: 600; }
.step.completed .step-label { color: var(--success); }

.step-line {
  width: 60px;
  height: 2px;
  background: var(--border);
  margin: 0 var(--space-3);
  transition: background var(--transition-base);
}
.step-line.completed {
  background: var(--success);
}

/* ============================================================
   12. TIMELINE (Rastreio)
   ============================================================ */
.timeline {
  position: relative;
  padding-left: 32px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--space-6);
}
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -28px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  border: 3px solid var(--bg);
  z-index: 1;
}

.timeline-item.active .timeline-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-100);
}
.timeline-item.completed .timeline-dot {
  background: var(--success);
}
.timeline-item.problem .timeline-dot {
  background: var(--danger);
}

.timeline-date {
  font-size: var(--text-xs);
  color: var(--text-light);
  margin-bottom: var(--space-1);
}

.timeline-title {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
}

.timeline-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ============================================================
   13. EMPTY STATES & LOADING
   ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--text-light);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
  opacity: 0.4;
}
.empty-state h3 {
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ============================================================
   14. TOAST / NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  min-width: 300px;
  max-width: 420px;
  animation: toast-in 0.3s ease;
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error   { border-left: 4px solid var(--danger); }
.toast.toast-warning { border-left: 4px solid var(--warning); }
.toast.toast-info    { border-left: 4px solid var(--info); }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   15. SEARCH BAR
   ============================================================ */
.search-bar {
  position: relative;
}
.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}
.search-bar .search-icon svg {
  width: 18px;
  height: 18px;
}
.search-bar .form-input {
  padding-left: 42px;
}

/* ============================================================
   16. ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: fadeInUp 0.4s ease forwards;
  opacity: 0;
}

.delay-1 { animation-delay: 0.06s; }
.delay-2 { animation-delay: 0.12s; }
.delay-3 { animation-delay: 0.18s; }
.delay-4 { animation-delay: 0.24s; }

/* ============================================================
   17. RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-4 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  .stepper {
    flex-direction: column;
    align-items: flex-start;
  }
  .step-line {
    width: 2px;
    height: 24px;
    margin: var(--space-2) 0 var(--space-2) 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
