/* styles.css — Fuel Tracker. Mobile-first, dark theme default with light mode.
   All colors are CSS variables; charts read grid/muted via var(). */

:root,
:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --grid: #2b3a52;
  --accent: #38bdf8;
  --accent-contrast: #082032;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --grid: #e2e8f0;
  --accent: #0284c7;
  --accent-contrast: #ffffff;
  --ok: #059669;
  --warn: #b45309;
  --danger: #dc2626;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.2px;
}

.status-bar {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

/* ---------- layout ---------- */

.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px 24px;
}

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

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

.card-title {
  margin: 0 0 10px;
  font-size: 1.02rem;
  font-weight: 650;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- stats rows ---------- */

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }

.stat-label { color: var(--muted); font-size: 0.95rem; }
.stat-value { font-size: 1.15rem; font-weight: 650; text-align: right; }
.stat-sub { font-size: 0.8rem; color: var(--muted); font-weight: 400; }

/* ---------- buttons (touch targets ≥ 44px) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }

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

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

.btn-lg { min-height: 54px; font-size: 1.08rem; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-grid .btn { width: 100%; }

/* ---------- forms ---------- */

.field { display: block; margin-bottom: 12px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
}
.field-hint { display: block; margin-top: 4px; font-size: 0.82rem; color: var(--muted); }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
}
textarea.input { min-height: 72px; resize: vertical; }
select.input { appearance: none; }

input[type="date"].input { min-height: 48px; }

/* segmented range switcher */
.seg {
  display: flex;
  gap: 6px;
  margin: 8px 0 12px;
  flex-wrap: wrap;
}
.seg-btn {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.badge-ok { border-color: var(--ok); color: var(--ok); }
.badge-warn { border-color: var(--warn); color: var(--warn); }
.badge-live { border-color: var(--ok); color: var(--ok); }
.badge-fallback { border-color: var(--warn); color: var(--warn); }

/* ---------- price block ---------- */

.price-block { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.price-line { font-size: 1rem; }
.price-line-big { font-size: 2rem; font-weight: 750; }

/* ---------- history rows ---------- */

.fill-row { display: flex; flex-direction: column; gap: 8px; }
.fill-main { flex: 1; }
.fill-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.fill-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- key/value list ---------- */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; }
.kv dt { color: var(--muted); font-size: 0.92rem; }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- data table (price sensitivity) ---------- */

.sens-table { width: 100%; border-collapse: collapse; margin: 8px 0 0; font-size: 0.92rem; }
.sens-table th, .sens-table td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.sens-table th:first-child, .sens-table td:first-child { text-align: left; }
.sens-table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.sens-table td { font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .tick { fill: var(--muted); }

.chart-slot { margin-bottom: 14px; }

/* ---------- messages ---------- */

.msg-box {
  padding: 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  margin-top: 10px;
  white-space: pre-line;
}
.msg-ok { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); border: 1px solid var(--ok); }
.msg-error { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); border: 1px solid var(--danger); color: var(--danger); }

/* ---------- bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
}

.bottom-nav button {
  flex: 1;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav button .nav-ico { font-size: 1.35rem; line-height: 1; }
.bottom-nav button.active { color: var(--accent); }

/* ---------- larger screens: comfortable, not a desktop layout ---------- */

@media (min-width: 700px) {
  .app-main { padding: 20px 24px 32px; }
  .bottom-nav {
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    width: min(560px, 100%);
    border-radius: 16px 16px 0 0;
  }
}
