:root {
  --bg: #0f172a;
  --bg-elev: #1a2438;
  --bg-card: #17213a;
  --border: #2a3651;
  --text: #eef2ff;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) 16px calc(env(safe-area-inset-bottom, 0) + 24px);
  min-height: 100%;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 12px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 80%, transparent);
  z-index: 5;
}

header.top h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.02em;
}

header.top .subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.fab {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #04202e;
  font-size: 26px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.35);
}

.fab:active { transform: scale(0.94); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state .emoji { font-size: 44px; display: block; margin-bottom: 12px; }

.empty-state button {
  margin-top: 18px;
}

.car-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.car-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.car-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.car-card.status-ok::before { background: var(--green); }
.car-card.status-soon::before { background: var(--yellow); }
.car-card.status-overdue::before { background: var(--red); }

.car-card .row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.car-card h3 {
  margin: 0;
  font-size: 17px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 100px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.status-ok { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.badge.status-soon { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge.status-overdue { background: rgba(248, 113, 113, 0.15); color: var(--red); }

.car-card .meta {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 6px;
}

.car-card .due-line {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 500;
}

.car-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.car-card .actions button {
  flex: 1;
  font-size: 13px;
  padding: 9px 10px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary { background: var(--accent); color: #04202e; }
.btn-ghost { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: rgba(248, 113, 113, 0.12); color: var(--red); }
.btn-secondary { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn:active { transform: scale(0.97); }

/* Sheets */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
  transition: opacity 0.2s;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  z-index: 21;
  padding: 10px 20px calc(env(safe-area-inset-bottom, 0) + 20px);
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(0);
  transition: transform 0.25s ease;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
}

.sheet.hidden, .backdrop.hidden { display: none; }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 100px;
  margin: 8px auto 14px;
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 19px;
}

.sheet label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.sheet .row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sheet input, .sheet select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.sheet input:focus, .sheet select:focus {
  outline: none;
  border-color: var(--accent);
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: -6px 0 14px;
  line-height: 1.4;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.sheet-actions .btn { flex: 1; }
.sheet-actions .btn-danger { flex: 0 0 auto; }

/* Detail sheet */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.detail-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.detail-item .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-item .value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  max-height: 50vh;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.history-date {
  font-size: 13px;
  color: var(--text-dim);
}

.history-miles {
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

.history-delta {
  font-size: 13px;
  color: var(--green);
  font-weight: 600;
}

.car-card .actions {
  flex-wrap: wrap;
}

.car-card .actions button {
  flex: 1 1 calc(50% - 4px);
}

footer.install-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 30px 10px 10px;
}
