/* ============================================================
   SmartBus — Global Styles & Design Tokens
   Modern SaaS Dashboard for School Transportation
   ============================================================ */

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
  scroll-behavior: smooth;
}
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: hidden;
}
ul, ol { list-style: none; }
a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select {
  font: inherit;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
}
img { max-width: 100%; display: block; }
svg { display: block; }

/* ===== Design Tokens ===== */
:root {
  /* Palette — Deep Navy / Blue primary */
  --color-primary: #0f1e3d;
  --color-primary-900: #0a152a;
  --color-primary-800: #12264a;
  --color-primary-700: #1c3569;
  --color-primary-600: #25448a;
  --color-accent: #2563eb;
  --color-accent-500: #3b82f6;

  /* States */
  --color-safe: #16a34a;
  --color-safe-bg: #dcfce7;
  --color-safe-100: #dcfce7;
  --color-warning: #ea580c;
  --color-warning-bg: #ffedd5;
  --color-warning-100: #ffedd5;
  --color-danger: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-danger-100: #fee2e2;
  --color-info: #0284c7;
  --color-info-bg: #e0f2fe;

  /* Neutrals */
  --color-bg: #f5f7fb;
  --color-bg-card: #ffffff;
  --color-bg-elevated: #ffffff;
  --color-bg-hover: #f1f5f9;
  --color-bg-panel: #ffffff;
  --color-bg-muted: #f8fafc;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-text: #0f172a;
  --color-text-secondary: #64748b;
  --color-text-tertiary: #94a3b8;

  /* Layout */
  --sidebar-width: 250px;
  --sidebar-width-collapsed: 64px;
  --topbar-height: 64px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 24px -4px rgb(0 0 0 / 0.1), 0 8px 16px -8px rgb(0 0 0 / 0.1);

  /* Transitions */
  --transition: 150ms ease;
  --transition-slow: 250ms ease;
  --transition-spring: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dark mode support (system) */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-bg-card: #1e293b;
    --color-bg-elevated: #242d3c;
    --color-bg-hover: #283448;
    --color-bg-panel: #1e293b;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-tertiary: #64748b;
  }
}
/* Manual dark mode toggle */
body.dark {
  --color-bg: #0f172a;
  --color-bg-card: #1e293b;
  --color-bg-elevated: #242d3c;
  --color-bg-hover: #283448;
  --color-bg-panel: #1e293b;
  --color-bg-muted: #0f172a;
  --color-border: #334155;
  --color-border-light: #334155;
  --color-text: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
}

/* ===== Layout Helpers ===== */
.container {
  width: min(90%, 1240px);
  margin-inline: auto;
  padding-inline: 1.5rem;
}
.grid {
  display: grid;
  gap: 1.5rem;
}
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.text-center { text-align: center; }
.text-muted { color: var(--color-text-secondary); }
.font-mono { font-family: 'Fira Code', 'Courier New', monospace; }

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }
p { margin-bottom: 0.5rem; }
.lead {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  max-width: 38rem;
}
.small { font-size: 0.75rem; }
.caption {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
}
.mono { font-family: 'Fira Code', 'Courier New', monospace; font-size: 0.8125rem; }

/* ===== Badge / Status Dot ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-success { background: var(--color-safe-bg); color: #14532d; }
.badge-success .badge-dot { background: var(--color-safe); }
.badge-warning { background: var(--color-warning-bg); color: #7c2d12; }
.badge-warning .badge-dot { background: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: #7f1d1d; }
.badge-danger .badge-dot { background: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: #0c4e69; }
.badge-info .badge-dot { background: var(--color-info); }
.badge-neutral { background: var(--color-bg-muted); color: var(--color-text-secondary); }
.badge-neutral .badge-dot { background: var(--color-text-tertiary); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--color-border);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  padding: 0.55rem 1rem;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-700); }
.btn-primary:outline {
  background: transparent;
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
}
.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-hover); }
.btn-success {
  background: var(--color-safe);
  color: #fff;
}
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-border);
  color: var(--color-text-secondary);
}
.btn-outline:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-border-light);
}
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.75rem; }
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 0.3rem 0.6rem;
}
.btn-ghost:hover { background: var(--color-bg-hover); }
.btn-floating {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  box-shadow: var(--shadow-xl);
  z-index: 40;
  transition: var(--transition-spring);
}

/* ===== Card ===== */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-light); }
.card-elevated {
  background: var(--color-bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border-light);
}

/* ===== Forms ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.field label {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}
.field.control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
input, textarea, select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  transition: var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.input-icon {
  position: relative;
}
.input-icon input { padding-left: 2.5rem; }
.input-icon .icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: var(--color-text-tertiary);
}

/* ===== Modal / Drawer ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-lg);
  max-width: min(90%, 40rem);
  width: 100%;
  box-shadow: var(--shadow-xl);
  transform: scale(0.96);
  opacity: 0;
  transition: all var(--transition-spring);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(80vh, 50rem);
}
.modal-overlay.open .modal {
  transform: scale(1);
  opacity: 1;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-panel);
}
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-panel);
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(420px, 90vw);
  background: var(--color-bg-elevated);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform var(--transition-spring);
  z-index: 80;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}
.drawer-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.drawer-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}
.toast {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  min-width: 240px;
  max-width: 380px;
  animation: slideIn 0.3s ease;
  pointer-events: all;
}
.toast.success { border-left: 4px solid var(--color-safe); }
.toast.warning { border-left: 4px solid var(--color-warning); }
.toast.error { border-left: 4px solid var(--color-danger); }
.toast.info { border-left: 4px solid var(--color-info); }
.toast .toast-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.toast .toast-content { flex: 1; }
.toast .toast-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}
.toast .toast-msg {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}
.toast .toast-close {
  cursor: pointer;
  color: var(--color-text-tertiary);
  opacity: 0.6;
  transition: var(--transition);
  padding: 0.15rem;
}
.toast .toast-close:hover { opacity: 1; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Table ===== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table th, .table td {
  text-align: left;
  padding: 0.75rem 0.7rem;
  border-bottom: 1px solid var(--color-border-light);
}
.table thead th {
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-tertiary);
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--color-bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table-compact td { padding: 0.5rem 0.5rem; }
.table .col-ctr { text-align: center; }
.table .col-actions { text-align: right; }

/* ===== Utility ===== */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skeleton {
  background: linear-gradient(90deg, var(--color-border-light) 25%, var(--color-bg-muted) 50%, var(--color-border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-tertiary);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 1rem; opacity: 0.4; }
.error-state {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-secondary);
}
.transition-fade { transition: opacity var(--transition), transform var(--transition); }
.opacity-0 { opacity: 0; }
