:root {
  --bg: #f1f5f9;
  --fg: #0f172a;
  --sidebar-bg: #1e293b;
  --sidebar-fg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --danger: #ef4444;
  --success: #22c55e;
  --muted: #64748b;
  --input-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --fg: #f1f5f9;
    --sidebar-bg: #020617;
    --sidebar-fg: #f8fafc;
    --card-bg: #1e293b;
    --border: #334155;
    --primary: #3b82f6;
    --input-bg: #0f172a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  overflow: hidden;
}

body.rider-app {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

/* Layout */
.layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand h2 {
  margin: 0;
  font-size: 1.25rem;
}

.badge {
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.sidebar nav {
  flex: 1;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: transparent;
  color: var(--sidebar-fg);
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.95rem;
  border-radius: 0;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
}

.nav-link.active {
  background: var(--primary);
  color: var(--primary-fg);
}

.icon {
  width: 20px;
  text-align: center;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  height: 64px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 1.25rem;
}

.user-profile {
  font-weight: 500;
  color: var(--muted);
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.view.hidden {
  display: none;
}

/* Components */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat h3 {
  margin: 0 0 10px 0;
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
}

.stat .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--fg);
}

.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 0.875rem;
  transition: all 0.2s;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}

.btn.secondary:hover {
  background: var(--bg);
}

.btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 0.875rem;
}

/* Table */
.table-container {
  padding: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.875rem;
  background: rgba(0,0,0,0.02);
}

td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.875rem;
}

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

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.05);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Riders Grid */
.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

.rider-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rider-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
}

.rider-name {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
}

.rider-info {
  font-size: 0.875rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
  overflow: hidden;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
}

.close-modal {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
}

/* Modal Tabs */
.tabs {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--primary);
}

.tab-content.hidden {
  display: none;
}

.modal-body {
  padding: 24px;
}

.rider-selection-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 16px;
}

.rider-select-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rider-select-item:hover {
  background: rgba(0,0,0,0.02);
}

.rider-select-item:last-child {
  border-bottom: none;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 0.875rem;
}

.form-group input, .form-group select {
  width: 100%;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.rider-shell {
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 92px;
}

.rider-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.rider-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.rider-brand {
  display: flex;
  flex-direction: column;
}

.rider-brand-title {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.rider-brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.rider-screen {
  padding: 16px;
}

.rider-hero {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(37,99,235,0.10), rgba(37,99,235,0.02));
}

.rider-hero-title {
  font-weight: 800;
  font-size: 18px;
  margin: 0;
}

.rider-hero-meta {
  margin-top: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.rider-section-title {
  margin: 16px 0 10px 0;
  font-size: 14px;
  font-weight: 700;
}

.rider-job-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--card-bg);
}

.rider-job-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.rider-job-id {
  font-weight: 800;
  font-size: 14px;
}

.rider-job-ref {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.rider-job-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.rider-kv {
  font-size: 13px;
}

.rider-kv strong {
  font-weight: 700;
}

.rider-job-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.rider-job-actions .btn {
  width: 100%;
  justify-content: center;
}

.rider-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}

.rider-bottom-nav-inner {
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.rider-tab {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}

.rider-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}

.rider-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 70;
  max-width: 720px;
  margin: 0 auto;
  display: none;
}

.rider-toast .card {
  padding: 12px 14px;
  border-radius: 12px;
}
