/* ── Reset + Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 220px;
  --header-h: 56px;

  --color-bg:       #f8f9fb;
  --color-surface:  #ffffff;
  --color-border:   #e5e7eb;
  --color-text:     #111827;
  --color-muted:    #6b7280;
  --color-primary:  #2563eb;
  --color-primary-hover: #1d4ed8;

  /* status */
  --s-pending:     #6b7280;
  --s-in-progress: #2563eb;
  --s-completed:   #059669;
  --s-overdue:     #dc2626;

  /* priority */
  --p-low:    #9ca3af;
  --p-medium: #d97706;
  --p-high:   #dc2626;

  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }

/* ── Layout ──────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border);
  letter-spacing: -.3px;
}
.sidebar-logo span { color: var(--color-muted); font-weight: 400; font-size: 12px; display: block; }

.sidebar-nav { padding: 12px 8px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--color-muted);
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--color-bg); color: var(--color-text); }
.nav-item.active { background: #eff6ff; color: var(--color-primary); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Main ────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#page-header {
  height: var(--header-h);
  padding: 0 24px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.page-title { font-size: 18px; font-weight: 600; }

#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

/* ── Dashboard stat grid ─────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--color-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card.overdue  .stat-value { color: var(--s-overdue); }
.stat-card.today    .stat-value { color: var(--s-in-progress); }
.stat-card.pending  .stat-value { color: var(--s-pending); }
.stat-card.done     .stat-value { color: var(--s-completed); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--color-border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }
tbody td { padding: 12px 14px; vertical-align: middle; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-pending     { background: #f3f4f6; color: var(--s-pending); }
.badge-in_progress { background: #eff6ff; color: var(--s-in-progress); }
.badge-completed   { background: #ecfdf5; color: var(--s-completed); }
.badge-overdue     { background: #fef2f2; color: var(--s-overdue); }

.badge-low    { background: #f3f4f6; color: var(--p-low); }
.badge-medium { background: #fffbeb; color: var(--p-medium); }
.badge-high   { background: #fef2f2; color: var(--p-high); }

/* ── Filters bar ─────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-select {
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  min-width: 130px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-bg); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Inline status buttons */
.status-btn {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .15s;
}
.status-btn:hover:not(:disabled) { opacity: .8; }
.status-btn:disabled { opacity: .5; cursor: not-allowed; }

.status-btn-pending     { background: #f3f4f6; color: var(--s-pending); }
.status-btn-in_progress { background: #eff6ff; color: var(--s-in-progress); }
.status-btn-completed   { background: #ecfdf5; color: var(--s-completed); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
}
.modal-close {
  background: none; border: none;
  color: var(--color-muted);
  font-size: 18px; line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--color-text); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Form ────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--color-text);
}
.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Calendar ────────────────────────────────────────────── */
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.cal-month-label { font-weight: 600; font-size: 16px; min-width: 140px; text-align: center; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day-name {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-muted);
  padding: 6px 0;
}

.cal-day {
  min-height: 80px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px;
  background: var(--color-surface);
  cursor: default;
  transition: background .1s;
}
.cal-day.other-month { background: var(--color-bg); }
.cal-day.today { border-color: var(--color-primary); }
.cal-day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-muted);
  margin-bottom: 4px;
}
.cal-day.today .cal-day-num { color: var(--color-primary); font-weight: 700; }
.cal-day.has-tasks { cursor: pointer; }
.cal-day.has-tasks:hover { background: #f9fafb; }

.cal-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin: 1px 2px;
}

/* ── Day task popup ──────────────────────────────────────── */
.day-tasks-popup {
  margin-top: 12px;
  padding: 14px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.day-tasks-popup h4 { font-size: 13px; font-weight: 600; margin-bottom: 10px; }

/* ── Misc ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-muted);
}
.empty-state p { font-size: 14px; margin-top: 6px; }

.page-actions { display: flex; gap: 8px; align-items: center; }

.link-btn {
  color: var(--color-primary);
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-muted);
  font-size: 13px;
  margin-bottom: 16px;
  background: none;
  border: none;
  cursor: pointer;
}
.back-btn:hover { color: var(--color-text); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  align-items: start;
}

.vehicle-info-card dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.vehicle-info-card dt { font-size: 12px; color: var(--color-muted); font-weight: 500; }
.vehicle-info-card dd { font-size: 13px; font-weight: 500; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading { text-align: center; padding: 48px; color: var(--color-muted); }
.error-msg { color: var(--s-overdue); font-size: 13px; padding: 8px 0; }

/* ── Dashboard ───────────────────────────────────────────── */

/* Summary bar */
.dash-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.sum-sep { color: #d1d5db; font-size: 15px; line-height: 1; margin: 0 2px; }
.sum-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.sum-critical  { background: #fef2f2; color: var(--s-overdue); }
.sum-attention { background: #fffbeb; color: #b45309; }
.sum-upcoming  { background: #eff6ff; color: var(--color-primary); }
.sum-done      { background: #ecfdf5; color: var(--s-completed); }

/* Section wrapper */
.dash-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.dash-section-critical    { border-left: 4px solid var(--s-overdue); }
.dash-section-attention   { border-left: 4px solid #f59e0b; }
.dash-section-inprogress  { border-left: 4px solid var(--color-primary); }
.dash-section-upcoming    { border-left: 4px solid #d1d5db; }

/* Section header */
.dash-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--color-border);
}
.dash-section-critical   .dash-section-header { background: #fff8f8; }
.dash-section-attention  .dash-section-header { background: #fffdf5; }
.dash-section-inprogress .dash-section-header { background: #f0f7ff; }

.dash-section-titles { display: flex; align-items: baseline; gap: 10px; }
.dash-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.dash-section-critical   .dash-section-title { color: var(--s-overdue); }
.dash-section-attention  .dash-section-title { color: #92400e; }
.dash-section-inprogress .dash-section-title { color: var(--color-primary); }
.dash-section-upcoming   .dash-section-title { color: var(--color-muted); }
.dash-section-subtitle { font-size: 12px; color: var(--color-muted); }

.dash-count-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}
.dash-count-critical    { background: #fef2f2; color: var(--s-overdue); }
.dash-count-attention   { background: #fffbeb; color: #b45309; }
.dash-count-inprogress  { background: #eff6ff; color: var(--color-primary); }
.dash-count-upcoming    { background: #f3f4f6; color: var(--color-muted); }

/* Empty state */
.dash-empty { padding: 14px 16px; font-size: 13px; color: var(--color-muted); }

/* Task rows */
.dash-task-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--color-border);
  transition: background .12s;
}
.dash-task-row:last-child { border-bottom: none; }
.dash-task-row:hover { background: #fafafa; }

/* First row — slightly more breathing room, signals "do this next" */
.dash-task-first {
  padding-top: 15px;
  padding-bottom: 15px;
  background: #fdfeff;
}
.dash-task-first:hover { background: #f5f9ff; }
.dash-task-first .dash-task-title { font-size: 14px; }

.dash-task-main { flex: 1; min-width: 0; }
.dash-task-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-task-desc {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-task-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.dash-due { font-size: 12px; font-weight: 500; white-space: nowrap; }
.dash-due-overdue { color: var(--s-overdue); }
.dash-due-today   { color: #d97706; font-weight: 600; }
.dash-due-future  { color: var(--color-muted); }

.dash-task-actions { flex-shrink: 0; min-width: 88px; text-align: right; }

/* Action buttons — solid and prominent */
.dash-action {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.dash-action:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

.dash-start {
  background: var(--color-primary);
  color: #fff;
}
.dash-start:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: scale(1.04);
  box-shadow: 0 2px 6px rgba(37,99,235,.35);
}
.dash-start:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }

.dash-complete {
  background: #059669;
  color: #fff;
}
.dash-complete:hover:not(:disabled) {
  background: #047857;
  transform: scale(1.04);
  box-shadow: 0 2px 6px rgba(5,150,105,.35);
}
.dash-complete:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }

/* First row — slightly larger action button */
.dash-task-first .dash-action { padding: 7px 18px; font-size: 13px; }

/* In-progress summary chip */
.sum-inprogress { background: #eff6ff; color: var(--color-primary); }

/* Vehicle identifier chip inside task rows */
.dash-vehicle-link {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  background: #f3f4f6;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.dash-vehicle-link:hover { background: #e5e7eb; }

/* Critical section with a single task — extra emphasis */
.dash-section-solo .dash-task-first {
  padding-top: 17px;
  padding-bottom: 17px;
  background: #fff5f5;
}
.dash-section-solo .dash-task-first .dash-task-title { font-size: 14.5px; }
.dash-section-solo .dash-task-first .dash-action { padding: 8px 20px; font-size: 13px; }

/* Upcoming — lower visual weight than active sections */
.dash-section-upcoming { box-shadow: none; }
.dash-section-upcoming .dash-section-header { padding: 9px 16px; }
.dash-section-upcoming .dash-task-row { padding: 9px 16px; }
.dash-section-upcoming .dash-task-title { font-weight: 500; }

/* All-clear empty state */
.dash-all-clear {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 14px;
}
.dash-all-clear-icon {
  font-size: 20px;
  color: var(--s-completed);
  margin-bottom: 6px;
}
.dash-all-clear p {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-muted);
}

/* Time-ago label on in-progress rows */
.dash-time-ago {
  font-size: 11px;
  color: var(--color-muted);
  font-style: italic;
  white-space: nowrap;
}

/* Done-today chip pulse when count increases */
@keyframes sumDonePulse {
  0%, 100% { background: #ecfdf5; transform: scale(1); }
  40%      { background: #bbf7d0; transform: scale(1.1); }
}
.sum-done-pulse { animation: sumDonePulse .65s ease; }

/* ── Row animations ──────────────────────────────────────── */

/* Slide left + fade on removal */
@keyframes dashRowExit {
  to { opacity: 0; transform: translateX(-14px); }
}
.dash-row-exit {
  animation: dashRowExit .22s ease forwards;
  pointer-events: none;
}

/* Green flash on complete */
@keyframes dashRowSuccess {
  0%   { background: #ecfdf5; }
  40%  { background: #bbf7d0; }
  100% { background: #ecfdf5; }
}
.dash-row-success { animation: dashRowSuccess .4s ease; }

/* Blue flash when a task is started */
@keyframes dashRowStart {
  0%   { background: transparent; }
  40%  { background: #dbeafe; }
  100% { background: transparent; }
}
.dash-row-start { animation: dashRowStart .3s ease; }

/* Blue pulse to guide attention to next task */
@keyframes dashRowFocus {
  0%, 100% { background: transparent; }
  30%, 70% { background: #eff6ff; }
}
.dash-row-focus { animation: dashRowFocus 1.4s ease; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #page-content { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
