/* Cadence — mobile-first styles */
:root {
  --bg: #0a0a0a;
  --bg-elev: #161616;
  --bg-elev-2: #1f1f1f;
  --border: #262626;
  --border-strong: #3a3a3a;
  --text: #e8e8e8;
  --text-dim: #8a8a8a;
  --text-dimmer: #5a5a5a;
  --accent: #d4a64a;
  --accent-soft: #d4a64a1f;
  --green: #5fb96e;
  --green-soft: #5fb96e1f;
  --red: #e85a5a;
  --red-soft: #e85a5a1f;
  --blue: #5aa6e8;
  --blue-soft: #5aa6e81f;
  --yellow: #e8c25a;
  --yellow-soft: #e8c25a1f;
  --purple: #b88ee8;
  --purple-soft: #b88ee81f;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 12px;
  --gap-sm: 8px;
  --gap-lg: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(80px + var(--safe-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* === Topbar === */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 16px; }
.brand-name { font-weight: 600; letter-spacing: 0.02em; }
.brand-meta { color: var(--text-dim); font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* === Tabs === */
.tabs {
  position: sticky;
  top: 49px;
  z-index: 9;
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.tab[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* === Main === */
.tab-panel { display: none; padding: 14px; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.panel-header h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.panel-sub { color: var(--text-dim); font-size: 12px; }

.subhead { font-size: 11px; font-weight: 700; color: var(--text-dim); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.08em; }

/* === Cards (compact list rows) === */
.card-list { display: flex; flex-direction: column; gap: 4px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.card:active { background: var(--bg-elev-2); }
.card.overdue { border-left: 3px solid var(--red); }
.card.soon    { border-left: 3px solid var(--yellow); }
.card.upcoming { border-left: 3px solid var(--green); }

.card-row1 {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.card-row1 .vendor-avatar { flex-shrink: 0; }
.card-row1 .card-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-row1 .urgency-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.urgency-pill.overdue { background: var(--red-soft); color: var(--red); }
.urgency-pill.soon    { background: var(--yellow-soft); color: var(--yellow); }
.urgency-pill.upcoming { background: var(--green-soft); color: var(--green); }
.urgency-pill.future   { background: var(--bg-elev-2); color: var(--text-dim); }

.card-row2 {
  display: flex;
  align-items: center;
  gap: 4px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  flex-wrap: wrap;
  margin-left: 34px; /* aligns with title (avatar width + gap) */
}
.card-row2 .sep { color: var(--text-dimmer); }
.card-row2 .meta-value { color: var(--text); font-weight: 500; }
.card-row2 .meta-cost { color: var(--accent); font-weight: 600; }

.card-row3 {
  margin-left: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.card-notes {
  margin-left: 34px;
  font-size: 12px;
  color: var(--text-dimmer);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.vendor-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg-elev-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.vendor-avatar.fuel { background: var(--accent-soft); color: var(--accent); }
.vendor-avatar.charge { background: var(--green-soft); color: var(--green); }
.vendor-avatar.subscription { background: var(--blue-soft); color: var(--blue); }
.vendor-avatar.reminder { background: var(--purple-soft); color: var(--purple); }
.vendor-avatar.watchlist { background: var(--yellow-soft); color: var(--yellow); }

.kind-chip {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  flex-shrink: 0;
}
.kind-chip.subscription { background: var(--blue-soft); color: var(--blue); }
.kind-chip.reminder     { background: var(--purple-soft); color: var(--purple); }
.kind-chip.watchlist    { background: var(--yellow-soft); color: var(--yellow); }
.kind-chip.charge       { background: var(--green-soft); color: var(--green); }
.kind-chip.fuel         { background: var(--accent-soft); color: var(--accent); }

/* === Buttons === */
.btn {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #0a0a0a; border-color: var(--accent); font-weight: 600; }
.btn-secondary { background: var(--bg-elev); color: var(--text-dim); }
.btn-danger { color: var(--red); border-color: var(--border); background: transparent; }
.btn-icon { padding: 4px 6px; color: var(--text-dim); font-size: 14px; line-height: 1; }
.btn-icon:active { color: var(--text); }
.btn-small { padding: 5px 9px; font-size: 11.5px; }

/* === Modal === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-backdrop.hidden { display: none; }
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { min-height: 60px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; border: 1px solid var(--border); }
}

/* === Summary grid (Vehicle) === */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.summary-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.summary-tile.highlight {
  background: linear-gradient(135deg, var(--accent-soft) 0%, transparent 100%);
  border-color: var(--accent);
}
.summary-tile h4 { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin-bottom: 6px; }
.summary-tile .v { font-size: 22px; font-weight: 700; font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: -0.02em; line-height: 1; }
.summary-tile .v.small { font-size: 18px; }
.summary-tile .s { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.3; }

.easee-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13px;
}
.easee-label { font-weight: 600; }
.easee-status { color: var(--text-dim); flex: 1; }
.easee-status.ok { color: var(--green); }
.easee-status.err { color: var(--text-dimmer); }

/* Live charging banner */
.live-charge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin: 12px 0;
  background: linear-gradient(135deg, var(--green-soft) 0%, var(--accent-soft) 100%);
  border: 1px solid var(--green);
  border-radius: var(--radius);
}
.live-charge-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--green-soft); }
  50% { opacity: 0.7; box-shadow: 0 0 0 8px transparent; }
}
.live-charge-body { flex: 1; }
.live-charge-title { font-weight: 600; font-size: 14px; color: var(--green); }
.live-charge-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.live-charge-stat {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--green);
  flex-shrink: 0;
  text-align: right;
  line-height: 1;
  min-width: 80px;
}

/* Inline chart (sparkline) */
.spark-chart {
  width: 100%;
  height: 70px;
  display: block;
}
.spark-chart .spark-line-fuel {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.spark-chart .spark-line-elec {
  fill: none;
  stroke: var(--green);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.spark-chart .spark-dot-fuel { fill: var(--accent); }
.spark-chart .spark-dot-elec { fill: var(--green); }
.spark-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text-dimmer);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  margin-top: 2px;
}
.spark-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.spark-legend .dot-fuel, .spark-legend .dot-elec {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin: 0 2px 0 4px;
}
.spark-legend .dot-fuel { background: var(--accent); }
.spark-legend .dot-elec { background: var(--green); }

/* === Empty state === */
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 16px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.empty p { margin: 0; }
.empty-sub { font-size: 13px; color: var(--text-dimmer); }

/* === Filter chips === */
.filter-chips {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  cursor: pointer;
}
.filter-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-load-more {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px;
}

.card.ignored {
  opacity: 0.55;
  border-style: dashed;
}
.card.ignored .card-title { text-decoration: line-through; text-decoration-color: var(--text-dimmer); }
.kind-chip.ignored-badge {
  background: var(--red-soft);
  color: var(--red);
}

/* === Entry view (read-only info modal) === */

.entry-view-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.entry-view-head .vendor-avatar.large {
  width: 44px;
  height: 44px;
  font-size: 22px;
  border-radius: 10px;
}
.entry-view-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}
.entry-view-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 3px;
}

.entry-view-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.entry-view-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.entry-view-row:last-child {
  border-bottom: none;
}
.entry-view-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex-shrink: 0;
}
.entry-view-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  text-align: right;
  word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.entry-view-value:first-letter { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* Stats row (vehicle analytics) */
.analytics-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.analytics-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.analytics-tile .label { font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.analytics-tile .v { font-size: 17px; font-weight: 700; font-family: ui-monospace, "SF Mono", Menlo, monospace; margin-top: 4px; line-height: 1; }
.analytics-tile .v.electric { color: var(--green); }
.analytics-tile .v.petrol { color: var(--accent); }

/* Breakdown bar */
.breakdown-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 4px;
  background: var(--bg-elev-2);
}
.breakdown-bar .electric { background: var(--green); }
.breakdown-bar .petrol { background: var(--accent); }
.breakdown-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
}
.breakdown-labels .electric { color: var(--green); }
.breakdown-labels .petrol { color: var(--accent); }