:root {
  color-scheme: light dark;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17201b;
  --muted: #607067;
  --border: #d7ded6;
  --primary: #116b5b;
  --primary-2: #1f8a70;
  --accent: #d97706;
  --petrol: #c2410c;
  --electric: #1177b8;
  --shadow: 0 16px 36px rgba(24, 34, 28, 0.1);
}

[data-theme="dark"] {
  --bg: #101418;
  --surface: #171d22;
  --surface-2: #20282e;
  --text: #eff5f1;
  --muted: #a7b5ad;
  --border: #334149;
  --primary: #40c6a4;
  --primary-2: #2aa98c;
  --accent: #f5a524;
  --petrol: #fb7b45;
  --electric: #59b9ef;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 14px calc(86px + env(safe-area-inset-bottom));
  max-width: 780px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 1.2rem;
  line-height: 1.1;
}

.brand p {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 14px;
}

.section-heading h2 {
  font-size: 1.25rem;
}

select, input, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.hero-total {
  display: grid;
  gap: 6px;
  padding: 18px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #1d4f71);
  color: white;
  box-shadow: var(--shadow);
}

.hero-total span {
  font-size: 0.9rem;
  opacity: 0.86;
}

.hero-total strong {
  font-size: 2.25rem;
  line-height: 1;
}

.hero-total small {
  opacity: 0.8;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.metric, .panel, .calculation-card, .history-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.metric {
  display: grid;
  gap: 6px;
  padding: 13px;
}

.metric span, label, .history-meta, .panel-heading span, .legend {
  color: var(--muted);
  font-size: 0.86rem;
}

.metric strong {
  font-size: 1.2rem;
}

.panel {
  padding: 14px;
  margin: 14px 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h3, .history-section h3 {
  font-size: 1rem;
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 86px 1fr 70px;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.bar-track {
  height: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 160ms ease;
}

.bar-fill.electric { background: var(--electric); }
.bar-fill.petrol { background: var(--petrol); }

.donut-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 12px;
}

.donut-wrap canvas {
  width: 150px;
  height: 150px;
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.form-stack {
  display: grid;
  gap: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
}

.calculation-card {
  padding: 13px;
  display: grid;
  gap: 6px;
  background: var(--surface-2);
}

.calculation-card strong {
  color: var(--primary);
}

.primary-button, .secondary-button, .text-button {
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.secondary-button {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  text-align: center;
}

.text-button {
  background: transparent;
  color: var(--primary);
  border-color: var(--border);
}

.tank-grid {
  display: grid;
  gap: 12px;
}

input[type="range"] {
  padding: 0;
}

.quick-levels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.quick-levels button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.84rem;
}

.history-section {
  margin: 16px 0;
}

.history-section h3 {
  margin-bottom: 10px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.history-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.history-title strong {
  font-size: 1rem;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-actions button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.actions-panel {
  display: grid;
  gap: 10px;
}

.scan-panel {
  display: grid;
  gap: 12px;
}

.scan-panel p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 5px;
}

.helper-text {
  color: var(--muted);
  font-size: 0.88rem;
}

.scan-review {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.hidden {
  display: none !important;
}

.history-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 0.78rem;
}

.file-button input {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(780px, 100%);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
}

.nav-button {
  display: grid;
  gap: 2px;
  justify-items: center;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
}

.nav-button span {
  font-size: 1.1rem;
}

.nav-button.active {
  background: var(--surface-2);
  color: var(--primary);
}

.empty {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

@media (min-width: 680px) {
  .app-shell {
    padding-inline: 22px;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tank-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  .bar-row {
    grid-template-columns: 72px 1fr 62px;
    font-size: 0.82rem;
  }

  .donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }
}
