:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a1d26;
  --muted: #5c6370;
  --border: #e2e6ee;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 0;
  margin-bottom: 2rem;
}

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

.logo { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }

.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.nav-links a.active, .nav-links a:hover { color: var(--primary); }
.nav-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }

main { flex: 1; padding-bottom: 3rem; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

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

.login-card { max-width: 400px; margin: 3rem auto; }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.75rem; }
.subtitle { color: var(--muted); margin-top: 0.25rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 1rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; }
.form-group input, .form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
}

.inline-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.inline-form .form-group { flex: 1; min-width: 180px; margin-bottom: 0; }

.tripsheet-create-form { display: flex; flex-direction: column; gap: 1rem; }
.upload-step-title { font-size: 1.1rem; margin-bottom: 0.25rem; }
.upload-rows { display: flex; flex-direction: column; gap: 0.75rem; margin: 1rem 0; }
.upload-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.upload-row label { font-size: 0.875rem; font-weight: 500; }
.upload-row input[type="file"] { font-size: 0.9rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

.btn {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #475569; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.hidden { display: none !important; }
.loading { color: var(--muted); }
.error-text { color: var(--danger); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-new { background: #fef9c3; color: #854d0e; }
.badge-suspended { background: #fee2e2; color: #991b1b; }
.badge-expired { background: #f3f4f6; color: #4b5563; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-none { background: #f3f4f6; color: #4b5563; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }

.meta-list div { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.meta-list dt { color: var(--muted); font-size: 0.875rem; }
.meta-list dd { font-weight: 500; }

.usage-item { margin-bottom: 1rem; }
.usage-label { display: flex; justify-content: space-between; font-size: 0.875rem; margin-bottom: 0.35rem; }
.progress { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.3s; }
.progress-fill.topup { background: #8b5cf6; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.plan-card h3 { margin-bottom: 0.5rem; }
.plan-card .price { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-bottom: 0.75rem; }
.plan-features { list-style: none; margin-bottom: 1rem; font-size: 0.875rem; color: var(--muted); }
.plan-features li { padding: 0.2rem 0; }
.plan-features li::before { content: "✓ "; color: var(--success); }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td { padding: 0.65rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.mono { font-family: ui-monospace, monospace; font-size: 0.75rem; word-break: break-all; }

.auth-footer { text-align: center; margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
.auth-footer a { color: var(--primary); }

/* Tripsheet list: card layout (mobile) + table (desktop) */
.tripsheet-cards { display: none; }

.tripsheet-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
}

.tripsheet-card-date {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.tripsheet-card-route {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.tripsheet-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile-first driver UX */
@media (max-width: 640px) {
  .site-header {
    margin-bottom: 1.25rem;
    padding: 0.75rem 0;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .nav-links {
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }

  .nav-links a {
    padding: 0.35rem 0;
    font-size: 0.95rem;
  }

  .nav-links .btn-ghost {
    margin-left: auto;
    min-height: 2.75rem;
    padding: 0.5rem 1rem;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }

  .card {
    padding: 1rem;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form .form-group {
    min-width: 0;
    width: 100%;
    margin-bottom: 0;
  }

  .inline-form .btn-primary {
    width: 100%;
    min-height: 2.75rem;
    margin-top: 0.25rem;
  }

  .form-group input,
  .form-group select {
    min-height: 2.75rem;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .tripsheet-table-desktop {
    display: none;
  }

  .tripsheet-cards {
    display: block;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .plan-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 641px) {
  .tripsheet-cards {
    display: none;
  }

  .tripsheet-table-desktop {
    display: block;
  }
}
