* {
  box-sizing: border-box;
}

:root {
  --tg-blue: #229ed9;
  --tg-blue-dark: #1b86ba;
  --tg-bg: #f4f6f8;
  --tg-surface: #ffffff;
  --tg-text: #1c1c1e;
  --tg-muted: #6b7280;
  --tg-card-dark: #0f172a;
  --tg-card-dark-text: #f8fafc;
  --tg-border: #e5e7eb;
  --tg-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
}

body[data-theme="dark"] {
  --tg-bg: #0f172a;
  --tg-surface: #111827;
  --tg-text: #f8fafc;
  --tg-muted: #9ca3af;
  --tg-border: #1f2937;
  --tg-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  min-height: 100vh;
}

.app {
  max-width: 480px;
  min-height: 100vh;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 32px;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--tg-blue);
  color: #fff;
  box-shadow: var(--tg-shadow);
}

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

.icon-btn,
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.burger,
.burger::before,
.burger::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 999px;
  position: relative;
}

.burger::before {
  position: absolute;
  top: -6px;
  left: 0;
}

.burger::after {
  position: absolute;
  top: 6px;
  left: 0;
}

.theme-toggle {
  position: relative;
  background: #fff;
}

.toggle-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tg-blue);
  transform: translateX(-8px);
  transition: transform 0.2s ease;
}

body[data-theme="dark"] .toggle-dot {
  transform: translateX(8px);
  background: var(--tg-blue-dark);
}

.content {
  padding: 16px;
  flex: 1;
}

.metrics-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.metric-title {
  font-size: 12px;
  color: var(--tg-muted);
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 6px;
}

.metric-unit {
  font-size: 12px;
  color: var(--tg-muted);
}

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

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

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

.tile {
  border: 1px solid var(--tg-border);
  background: var(--tg-surface);
  border-radius: 16px;
  padding: 12px;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--tg-shadow);
  cursor: pointer;
}

.tile-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-blue);
}

.tile-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.car-card {
  border: 2px dashed var(--tg-border);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--tg-surface);
}

.car-figure {
  position: relative;
  width: 120px;
  height: 60px;
}

.car-body {
  position: absolute;
  inset: 18px 10px 12px 10px;
  background: var(--tg-blue);
  border-radius: 18px 18px 12px 12px;
}

.car-body::after {
  content: "";
  position: absolute;
  top: -10px;
  left: 20px;
  width: 60px;
  height: 22px;
  background: var(--tg-blue-dark);
  border-radius: 16px 16px 6px 6px;
}

.car-wheel {
  position: absolute;
  bottom: 6px;
  width: 18px;
  height: 18px;
  background: #111827;
  border-radius: 50%;
}

.car-wheel.left {
  left: 20px;
}

.car-wheel.right {
  right: 20px;
}

.car-caption {
  font-weight: 600;
}

.car-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #0f172a;
  color: var(--tg-card-dark-text);
  border-radius: 12px;
  padding: 8px 10px;
  width: 100%;
  text-align: center;
}

body[data-theme="dark"] .car-metric {
  background: #1f2937;
}

.car-metric-label {
  font-size: 12px;
  opacity: 0.8;
}

.car-metric-value {
  font-size: 14px;
  font-weight: 700;
}

.stat-card {
  background: var(--tg-surface);
  border-radius: 16px;
  padding: 12px;
  border: 1px solid var(--tg-border);
  box-shadow: var(--tg-shadow);
  text-align: center;
}

.stat-card.dark {
  background: #0f172a;
  color: var(--tg-card-dark-text);
  border-color: #0f172a;
}

body[data-theme="dark"] .stat-card.dark {
  background: #0b1220;
}

.stat-card.outline {
  border: 2px dashed var(--tg-border);
  background: var(--tg-surface);
}

.stat-title {
  font-size: 12px;
  color: var(--tg-muted);
}

.stat-card.dark .stat-title {
  color: rgba(248, 250, 252, 0.7);
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  margin-top: 6px;
}

.stat-icon {
  width: 28px;
  height: 28px;
  margin: 10px auto 0;
  border: 2px solid var(--tg-blue);
  border-radius: 6px;
  position: relative;
}

.stat-icon.plus::before,
.stat-icon.plus::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  background: var(--tg-blue);
  transform: translate(-50%, -50%);
}

.stat-icon.plus::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

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

.section-card + .section-card {
  margin-top: 16px;
}

.section-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.range-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.range-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--tg-muted);
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--tg-muted);
}

input,
select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-border);
  background: transparent;
  color: var(--tg-text);
  font-size: 14px;
}

select {
  background: var(--tg-surface);
}

.primary-btn {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--tg-blue);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.ghost-btn {
  margin-top: 10px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--tg-border);
  background: transparent;
  color: var(--tg-text);
  font-weight: 600;
  cursor: pointer;
}

.ghost-btn.hidden {
  display: none;
}

.danger-btn {
  margin-top: 10px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: #ef4444;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.danger-btn.hidden {
  display: none;
}

.chart {
  margin-top: 16px;
  position: relative;
  height: 180px;
  border-radius: 16px;
  border: 1px dashed var(--tg-border);
  background: linear-gradient(180deg, rgba(34, 158, 217, 0.1), transparent);
  overflow: hidden;
}

.chart-line {
  position: absolute;
  inset: 30px 16px 60px 16px;
  border-top: 2px solid var(--tg-blue);
  border-radius: 16px;
  opacity: 0.8;
  top: var(--line-top, 30px);
  bottom: auto;
}

.chart-bars {
  position: absolute;
  inset: 20px 16px 20px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chart-bars span {
  flex: 1;
  background: var(--tg-blue);
  border-radius: 6px 6px 0 0;
  opacity: 0.7;
}

.chart-average-line {
  position: absolute;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--tg-blue-dark);
  opacity: 0.7;
  top: 50%;
}

.chart-tooltip {
  position: absolute;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--tg-surface);
  color: var(--tg-text);
  border: 1px solid var(--tg-border);
  box-shadow: var(--tg-shadow);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -110%);
  transition: opacity 0.15s ease;
  white-space: nowrap;
  z-index: 2;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--tg-muted);
}

.chart-empty.visible {
  display: flex;
}

.chart-legend {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--tg-muted);
}

.chart-average {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-text);
}

.chart-value {
  margin-top: 6px;
  font-size: 12px;
  color: var(--tg-muted);
  line-height: 1.4;
}

.chart-value strong {
  color: var(--tg-text);
  font-weight: 600;
}

.legend-line,
.legend-bar {
  display: inline-block;
  width: 18px;
  height: 3px;
  background: var(--tg-blue);
  margin-right: 6px;
  vertical-align: middle;
}

.legend-bar {
  height: 10px;
}

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

.utility-item {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--tg-border);
  background: var(--tg-bg);
}

.utility-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.utility-item ul {
  margin: 0;
  padding-left: 18px;
  color: var(--tg-muted);
}

.charge-edit-status {
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--tg-muted);
}

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

.charge-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--tg-border);
  background: var(--tg-bg);
}

.charge-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.charge-item-info span {
  color: var(--tg-muted);
  font-size: 12px;
}

.charge-item-btn {
  border: none;
  background: var(--tg-blue);
  color: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  height: fit-content;
}

.utility-link {
  color: var(--tg-blue);
  text-decoration: none;
}

.utility-link:hover {
  text-decoration: underline;
}

.partner-category {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(34, 158, 217, 0.12);
  color: var(--tg-blue);
  font-size: 11px;
}

.icon-attribution {
  margin-top: 14px;
  font-size: 12px;
  color: var(--tg-muted);
}

.icon-attribution a {
  color: var(--tg-blue);
  text-decoration: none;
}

.icon-attribution a:hover {
  text-decoration: underline;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

@media (max-width: 400px) {
  .metrics-top {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 768px) {
  body {
    display: flex;
    justify-content: center;
  }

  .app {
    width: 100%;
    max-width: 480px;
  }
}
