/* ===========================
   Fleet Card Platform — admin
   =========================== */

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-50: #eff6ff;
  --brand-100: #dbeafe;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --muted-2: #9ca3af;

  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  --neutral-bg: #e5e7eb;
  --neutral-text: #374151;
  --purple-bg: #ede9fe;
  --purple-text: #5b21b6;

  --sidebar-bg: #0f172a;
  --sidebar-bg-2: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #94a3b8;
  --sidebar-active: #2563eb;
  --sidebar-hover: #1e293b;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* =========== Sidebar =========== */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0b1220;
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--sidebar-bg-2);
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand) 0%, #4338ca 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.brand-name {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.1;
}
.brand-sub {
  color: var(--sidebar-text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar-nav {
  padding: 8px 12px;
  flex: 1;
  overflow-y: auto;
}
.nav-section { margin-top: 16px; }
.nav-section:first-child { margin-top: 4px; }
.nav-section-title {
  color: var(--sidebar-text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 8px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}
.nav-item.active svg { opacity: 1; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--sidebar-bg-2);
  background: rgba(15, 23, 42, 0.6);
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-email {
  color: var(--sidebar-text-muted);
  font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-logout {
  color: var(--sidebar-text-muted);
  padding: 6px;
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}
.user-logout:hover { background: var(--sidebar-hover); color: #fff; }
.user-logout svg { width: 16px; height: 16px; display: block; }

/* =========== Content =========== */

.content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.page-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.page-header-actions { display: flex; gap: 8px; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text-2); }
.breadcrumb .sep { color: var(--muted-2); }

.content-body { padding: 24px 32px 48px; max-width: 1500px; width: 100%; }

/* =========== Widgets / cards =========== */

.widgets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.widget::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
  background: var(--border-strong);
}
.widget.alert::before { background: var(--danger); }
.widget.warning::before { background: var(--warning); }
.widget.success::before { background: var(--success); }
.widget .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.widget .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.widget.alert .value { color: var(--danger); }
.widget.warning .value { color: var(--warning); }
.widget.success .value { color: var(--success); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card > h2:first-child { margin-top: 0; }
h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 12px;
  letter-spacing: -0.005em;
}

/* =========== Tables =========== */

table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}
.card > table { margin: -4px 0 -4px; }

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

td a { color: var(--brand); text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }

/* =========== Badges =========== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: 0.01em;
}
.badge-Pending     { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-Queued      { background: var(--info-bg);    color: var(--info-text); }
.badge-Processing  { background: var(--warning-bg); color: var(--warning-text); }
.badge-Success     { background: var(--success-bg); color: var(--success-text); }
.badge-Failed      { background: var(--danger-bg);  color: var(--danger-text); }
.badge-Retrying    { background: var(--purple-bg);  color: var(--purple-text); }
.badge-Info        { background: var(--info-bg);    color: var(--info-text); }
.badge-Warning     { background: var(--warning-bg); color: var(--warning-text); }
.badge-Critical    { background: var(--danger-bg);  color: var(--danger-text); }

/* =========== Health tiles =========== */

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.health-tile {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}
.health-tile.ok { border-left: 3px solid var(--success); }
.health-tile.bad { border-left: 3px solid var(--danger); }
.health-tile .name { font-weight: 600; font-size: 13px; color: var(--text); }
.health-tile .detail { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* =========== Forms =========== */

form { display: grid; gap: 14px; }
.card form, form > div { gap: 0; }

label {
  font-size: 12px;
  color: var(--text-2);
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
}
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-100);
}
textarea { min-height: 90px; resize: vertical; font-family: ui-monospace, SFMono-Regular, monospace; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  font-family: inherit;
}
button:hover, .btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* =========== Toolbar / filters =========== */

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: end;
}
.toolbar form {
  display: flex;
  gap: 8px;
  align-items: end;
  flex: 1;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 220px; }
.toolbar label { margin-bottom: 0; }

/* =========== Flash messages =========== */

.flashes { list-style: none; padding: 0; margin: 0 0 16px; }
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}
.flash svg { width: 16px; height: 16px; flex-shrink: 0; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--danger-bg); color: var(--danger-text); }
.auth-flashes { max-width: 380px; margin: 16px auto -8px; }

/* =========== Audit trail =========== */

.audit-trail { font-size: 13px; }
.audit-trail .event {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  align-items: baseline;
}
.audit-trail .event:last-child { border-bottom: 0; }
.audit-trail .timestamp {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* =========== Details / dropdown =========== */

details {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
details:last-of-type { border-bottom: 0; }
summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: '▸';
  display: inline-block;
  color: var(--muted);
  transition: transform 0.15s;
  font-size: 10px;
}
details[open] > summary::before { transform: rotate(90deg); }
details > form { margin-top: 14px; padding-left: 18px; }

/* =========== Login =========== */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  padding: 24px;
}
.login-card {
  max-width: 400px;
  width: 100%;
  background: var(--surface);
  padding: 36px 36px 32px;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px -8px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.15);
}
.login-card .brand-mark {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  font-size: 16px;
}
.login-card h1 {
  text-align: center;
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}
.login-card .subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-card button { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }

/* =========== Misc =========== */

pre {
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, "Menlo", monospace;
}

code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--text-2);
}

/* =========== Detail key/value tables =========== */

.card > table tr th {
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  width: 30%;
  border-bottom: 1px solid var(--border);
}
.card > table tr td { font-size: 13px; color: var(--text); }

/* =========== Sidebar toggle for mobile =========== */

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 100;
  padding: 8px;
  background: var(--sidebar-bg);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .content { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .page-header { padding-left: 64px; }
  .content-body { padding: 16px 16px 32px; }
}
