:root {
  --bg: #e9e2d0;
  --panel: rgba(247, 242, 229, 0.92);
  --ink: #213027;
  --muted: #5d6c63;
  --accent: #c2185b;
  --accent-strong: #880e4f;
  --earth: #8f6842;
  --line: rgba(33, 48, 39, 0.12);
  --shadow: 0 18px 45px rgba(41, 54, 43, 0.16);
  --radius: 26px;
  --font: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 28%),
    linear-gradient(160deg, #f1ebdb 0%, #d8cfba 42%, #c7bca4 100%);
  min-height: 100vh;
}

img {
  max-width: 100%;
  display: block;
}

.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow,
.panel-label {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  color: var(--accent-strong);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  line-height: 0.95;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.hero-buttons {
  display: flex;
  gap: 10px;
}

.button-outline {
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
  font-size: 1.2rem;
  padding: 10px 16px;
  line-height: 1;
}

.button-outline:active {
  background: rgba(194, 24, 91, 0.08);
}

.button {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #c2185b 0%, #880e4f 100%);
  color: white;
  padding: 14px 22px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.button-secondary {
  background: linear-gradient(135deg, #80513f 0%, #5b3328 100%);
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

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

.top-grid {
  grid-template-columns: 1fr 1fr 0.85fr;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.level-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.level-value {
  font-size: clamp(3rem, 8vw, 5.6rem);
  line-height: 0.9;
  font-weight: 800;
}

.level-subvalue {
  margin: 10px 0 0;
  color: var(--accent-strong);
  font-size: 1.05rem;
  font-weight: 700;
}

.tank-wrap {
  width: 140px;
  padding: 4px 0;
}

.tank-svg {
  width: 100%;
  height: auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 6px 0 0;
}

.stats dt {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats dd {
  margin: 6px 0 0;
  font-size: 2rem;
  font-weight: 750;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
  margin: 0;
}

/* Range selector */
.range-selector {
  display: flex;
  gap: 4px;
  background: rgba(33, 48, 39, 0.06);
  border-radius: 999px;
  padding: 3px;
}

.range-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.range-btn:hover {
  color: var(--ink);
}

.range-btn.active {
  background: var(--accent);
  color: white;
}

/* Chart */
.chart-panel {
  margin-bottom: 20px;
}

#history-chart {
  width: 100%;
  aspect-ratio: 900 / 340;
  display: block;
  margin-top: 12px;
  background:
    linear-gradient(180deg, rgba(194, 24, 91, 0.04), rgba(194, 24, 91, 0)),
    rgba(255, 255, 255, 0.35);
  border-radius: 18px;
}

.chart-tap-hint {
  display: none;
  text-align: center;
  margin: 8px 0 0;
  font-size: 0.78rem;
}

.chart-dot {
  cursor: pointer;
}

.chart-dot:hover {
  filter: brightness(1.2);
}

.modal-chart-content {
  max-width: 95vw;
  width: 100%;
}

.modal-chart-content svg {
  width: 100%;
  aspect-ratio: 900 / 500;
  display: block;
  margin-top: 12px;
  background:
    linear-gradient(180deg, rgba(194, 24, 91, 0.04), rgba(194, 24, 91, 0)),
    rgba(255, 255, 255, 0.35);
  border-radius: 18px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 16px 0 4px;
}

.page-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-btn:hover {
  color: var(--ink);
  background: rgba(33, 48, 39, 0.06);
}

.page-btn.active {
  background: var(--accent);
  color: white;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.chart-tooltip {
  font-size: 10px;
  fill: var(--ink);
  font-family: var(--font);
  pointer-events: none;
}

.chart-axis-label {
  font-size: 10px;
  fill: #5d6c63;
  font-family: var(--font);
}

.image-panel img {
  width: 100%;
  min-height: 200px;
  object-fit: contain;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid var(--line);
}

.table-panel {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  position: sticky;
  top: 0;
  background: var(--panel);
}

.empty {
  text-align: center;
  color: var(--muted);
}

#readings-body tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

#readings-body tr:hover {
  background: rgba(194, 24, 91, 0.06);
}

.bottom-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(33, 48, 39, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.modal-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
}

.modal-image-label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-images img {
  width: 100%;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid var(--line);
  object-fit: contain;
}

.modal-meta {
  margin: 12px 0 0;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
}

@media (max-width: 980px) {
  .hero,
  .grid,
  .top-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero-actions {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 18px 14px 28px;
  }

  .panel {
    padding: 18px;
  }

  .level-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tank-wrap {
    width: 100%;
  }

  .tank {
    height: 120px;
  }

  .modal-images {
    grid-template-columns: 1fr;
  }

  .range-btn {
    padding: 5px 10px;
    font-size: 0.72rem;
  }

  .chart-tap-hint {
    display: block;
  }
}
