:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;

  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-active: #334155;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --transition: .2s ease;
  --sidebar-width: 260px;
  --header-height: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-sidebar-active: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #f1f5f9;
  --border: #334155;
  --input-bg: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,.25);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.3);
  --primary-light: #1e3a8a;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.container-fluid { width: 100%; padding: 0 1rem; }

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

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--font);
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-lg { padding: .75rem 2rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: .875rem; font-weight: 500; color: var(--text); margin-bottom: .4rem; }
.form-control {
  display: block;
  width: 100%;
  padding: .625rem .875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: .9rem;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-control::placeholder { color: var(--text-muted); }
.form-text { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.form-error { font-size: .8rem; color: var(--danger); margin-top: .25rem; }

.alert { padding: .875rem 1.25rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef9c3; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
[data-theme="dark"] .alert-success { background: #14532d; color: #86efac; }
[data-theme="dark"] .alert-danger { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .alert-info { background: #0c4a6e; color: #7dd3fc; }

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 100px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-secondary { background: var(--border); color: var(--text-muted); }
[data-theme="dark"] .badge-success { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-danger { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-warning { background: #78350f; color: #fcd34d; }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th { background: var(--bg); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .05em; padding: .75rem 1rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table td { padding: .875rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.table tbody tr:hover { background: var(--bg); }
.table tbody tr:last-child td { border-bottom: none; }

.pagination { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text);
  background: var(--bg-card);
  transition: all var(--transition);
}
.page-link:hover { border-color: var(--primary); color: var(--primary); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link:disabled { opacity: .5; pointer-events: none; }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.stat-icon { width: 48px; height: 48px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; }
.stat-icon-blue { background: var(--primary-light); }
.stat-icon-green { background: #dcfce7; }
.stat-icon-orange { background: #fef3c7; }
.stat-icon-purple { background: #f3e8ff; }
[data-theme="dark"] .stat-icon-green { background: #14532d; }
[data-theme="dark"] .stat-icon-orange { background: #78350f; }
[data-theme="dark"] .stat-icon-purple { background: #581c87; }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.2; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .75rem;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
}
.sidebar-brand img { width: 32px; height: 32px; }
.sidebar-nav { padding: 1rem 0; flex: 1; }
.nav-section { padding: .5rem 1.5rem .25rem; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.35); }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; font-size: .875rem; color: var(--text-sidebar); transition: all var(--transition); border-left: 3px solid transparent; cursor: pointer; text-decoration: none; }
.nav-item:hover { background: var(--bg-sidebar-active); color: var(--text-sidebar-active); }
.nav-item.active { background: var(--bg-sidebar-active); color: var(--text-sidebar-active); border-left-color: var(--primary); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

.main-layout { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 50;
  box-shadow: var(--shadow);
}
.page-content { padding: 1.5rem; flex: 1; }
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 1.5rem; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; animation: modalIn .2s ease; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-weight: 600; font-size: 1.1rem; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.5rem; padding: 0; line-height: 1; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }

@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }

.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 500; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .875rem 1.25rem;
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
  min-width: 280px;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; } }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; } .gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; } .mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: .25rem; } .mb-2 { margin-bottom: .5rem; } .mb-3 { margin-bottom: .75rem; } .mb-4 { margin-bottom: 1rem; }
.text-center { text-align: center; } .text-right { text-align: right; }
.text-sm { font-size: .875rem; } .text-xs { font-size: .75rem; }
.font-bold { font-weight: 700; } .font-semibold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.d-none { display: none !important; }

.tracking-timeline { position: relative; padding-left: 2rem; }
.tracking-timeline::before { content: ''; position: absolute; left: .625rem; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-dot { position: absolute; left: -1.6rem; top: .2rem; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg-card); }
.timeline-item.active .timeline-dot { background: var(--primary); border-color: var(--primary); }
.timeline-item.completed .timeline-dot { background: var(--success); border-color: var(--success); }
.timeline-status { font-weight: 600; font-size: .9rem; }
.timeline-date { font-size: .8rem; color: var(--text-muted); }
.timeline-note { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-layout { margin-left: 0; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 1rem; }
  .card { padding: 1rem; }
  .topbar { padding: 0 1rem; }
  .modal { max-width: 100%; margin: .5rem; }
  .table th, .table td { padding: .6rem .75rem; }
}
