:root {
  --bg: #eef3f5;
  --card: #ffffff;
  --ink: #13313a;
  --muted: #6b7c84;
  --accent: #0b7285;
  --accent-dark: #095260;
  --accent-soft: #e6f3f5;
  --line: #e3eaed;
  --ok: #2b8a3e;
  --low: #1971c2;
  --warning: #e8590c;
  --critical: #c92a2a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(19, 49, 58, 0.04), 0 6px 18px rgba(19, 49, 58, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(1200px 380px at 100% -10%, #e0eef0 0%, rgba(224,238,240,0) 60%),
    var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  background: linear-gradient(100deg, var(--accent-dark), var(--accent));
  color: #fff; padding: 0.7rem 1.25rem;
  box-shadow: 0 2px 12px rgba(9, 82, 96, 0.18);
}
.topbar a { color: #fff; }
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-weight: 700; font-size: 1.12rem; letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand-logo { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15)); }
.topbar nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.topbar nav a:hover { text-decoration: underline; }
.topbar .who { color: #cfe9ee; font-size: 0.82rem; }

.container { max-width: 1240px; margin: 1.75rem auto; padding: 0 1.5rem; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.head-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.12rem; margin: 0 0 0.5rem; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 460px; margin: 2rem auto; }
.card.empty { text-align: center; }
.card.empty .primary { margin: 0.75rem 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.pool-card {
  display: block; padding: 0; overflow: hidden;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.pool-card:hover {
  border-color: var(--accent); text-decoration: none;
  transform: translateY(-2px); box-shadow: 0 8px 26px rgba(11, 114, 133, 0.15);
}
.pool-thumb {
  height: 124px; background-size: cover; background-position: center;
  background-color: #dcebee; display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--line);
}
.pool-card.has-thumb .pool-thumb { border-bottom: none; }
.pool-thumb-drop { font-size: 2.2rem; opacity: 0.45; }
.pool-card-body { padding: 0.9rem 1.1rem; }
.pool-card h2 { color: var(--ink); margin: 0 0 0.3rem; }

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

label { display: block; font-weight: 600; margin: 0.9rem 0 0.3rem; font-size: 0.9rem; }
label.checkbox { font-weight: 400; display: flex; align-items: center; gap: 0.5rem; }
input, select, textarea {
  width: 100%; padding: 0.55rem 0.65rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: 1rem; font-family: inherit; background: #fff;
}
textarea { resize: vertical; }
.row { display: flex; gap: 0.5rem; }
.row input { flex: 2; } .row select { flex: 1; }
.inline-form { display: flex; align-items: flex-end; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.inline-form label { margin-top: 0; }
.inline-form select { width: auto; min-width: 160px; }

.autosync-form { align-items: center; }
.autosync-form .checkbox { white-space: nowrap; margin: 0; flex: 0 0 auto; }
.autosync-form button { margin-top: 0; }
.autosync-form select[name="interval_hours"] { min-width: 120px; }
.autosync-into { color: var(--muted); font-size: 0.9rem; }

button { cursor: pointer; font-family: inherit; }
.primary {
  display: inline-block; background: var(--accent); color: #fff; border: none;
  padding: 0.6rem 1rem; border-radius: 8px; font-size: 0.95rem; font-weight: 600;
  margin-top: 1rem;
}
.primary:hover { background: var(--accent-dark); text-decoration: none; }
.secondary {
  display: inline-block; background: #fff; color: var(--accent-dark);
  border: 1px solid var(--accent); padding: 0.6rem 1rem; border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; margin-top: 1rem;
}
.secondary:hover { background: #f4f8fa; }
.secondary.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; margin-top: 0; }
.btn-link { font-size: 0.85rem; }
.linklike {
  background: none; border: none; padding: 0; color: var(--accent);
  cursor: pointer; font: inherit; text-decoration: underline;
}
.danger-link {
  background: none; border: none; color: var(--critical); padding: 0.5rem 0;
  font-size: 0.85rem; text-decoration: underline; margin-top: 0.5rem;
}

.badge {
  display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: #fff;
}
.badge.ok { background: var(--ok); }
.badge.low { background: var(--low); }
.badge.warning { background: var(--warning); }
.badge.critical { background: var(--critical); }

.tag { font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line);
  padding: 0.1rem 0.5rem; border-radius: 999px; }

.assessment-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.advice-refresh { margin: 0 0 0 auto; }
.advice-refresh button { margin: 0; }

.location-edit { margin: 0.5rem 0 1rem; }
.location-edit summary { cursor: pointer; color: var(--accent-dark); font-size: 0.9rem; }
.location-edit .inline-form { margin-top: 0.6rem; }
.location-edit .inline-form > div { display: flex; flex-direction: column; }

.scan-box {
  border: 1px dashed var(--line); border-radius: 10px; padding: 0.9rem 1rem;
  margin: 1rem 0 1.5rem; background: #f8fbfc;
}
.scan-box h2 { margin-top: 0; font-size: 1rem; }
.scan-box input[type="file"] { margin: 0.3rem 0; }
.alert.inline { display: inline-block; margin: 0.5rem 0 0; }
.strip-thumb { display: inline-block; margin: 0.3rem 0 0.6rem; }
.strip-thumb img {
  max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line);
}
.summary { font-size: 1.05rem; }

.next-steps { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.next-steps h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.next-steps ol { margin: 0; padding-left: 1.2rem; }
.next-steps li { margin: 0.3rem 0; }

.recs { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.rec {
  border-left: 4px solid var(--line); padding: 0.6rem 0.9rem; margin-bottom: 0.6rem;
  background: #fafcfd; border-radius: 0 8px 8px 0;
}
.rec.ok { border-left-color: var(--ok); }
.rec.low { border-left-color: var(--low); }
.rec.warning { border-left-color: var(--warning); }
.rec.critical { border-left-color: var(--critical); }
.rec-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.2rem; }
.rec p { margin: 0.2rem 0; }
.rec .action { color: var(--accent-dark); font-weight: 500; }

.readings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 0.6rem; }
.metric {
  background: linear-gradient(180deg, #f7fafb, #eef5f7);
  border: 1px solid var(--line); border-radius: 10px; padding: 0.55rem 0.7rem;
}
.metric-label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 1.22rem; font-weight: 700; color: var(--accent-dark); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

.alert { padding: 0.6rem 0.85rem; border-radius: 8px; margin: 0.5rem 0; font-size: 0.9rem; }
.alert.low { background: #e7f5ff; color: var(--low); }
.alert.critical { background: #fff0f0; color: var(--critical); }
.alert.inline { display: inline-block; padding: 0.1rem 0.5rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.section-head h2 { margin: 0; }
.history-tools { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.import-form { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.import-form input[type="file"] { width: auto; max-width: 180px; font-size: 0.8rem; padding: 0.25rem; }

/* Pin the delete action to the left so it stays visible on wide, scrolling tables. */
.data-table th:first-child,
.data-table td:first-child {
  position: sticky; left: 0; background: var(--card); z-index: 1;
}
.data-table tbody tr:hover td:first-child { background: #fafcfd; }

.row-action { text-align: center; padding: 0.2rem 0.3rem; width: 1%; }
.row-action form { margin: 0; }
.icon-delete {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.9rem; line-height: 1; padding: 0.25rem 0.4rem; border-radius: 6px;
}
.icon-delete:hover { color: var(--critical); background: #fff0f0; }

.weather-line { margin-top: 0.75rem; color: var(--accent-dark); font-size: 0.9rem; }
.weather-cell { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

/* --- Pool hero --- */
.hero {
  position: relative; border-radius: var(--radius); overflow: hidden;
  padding: 1.4rem 1.5rem; margin-bottom: 1.25rem; min-height: 210px;
  display: flex; flex-direction: column; justify-content: flex-end;
  background-size: cover; background-position: center; box-shadow: var(--shadow);
}
.hero.no-photo {
  background:
    radial-gradient(120% 140% at 85% -20%, rgba(255,255,255,0.18), rgba(255,255,255,0) 50%),
    linear-gradient(120deg, var(--accent-dark), var(--accent));
}
.hero h1 {
  color: #fff; font-size: 1.85rem; margin: 0 0 0.55rem;
  text-shadow: 0 1px 10px rgba(0,0,0,0.35);
}
.hero-body { position: relative; z-index: 1; }
.hero-actions {
  position: absolute; top: 1rem; right: 1rem; z-index: 2;
  display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: rgba(255,255,255,0.18); color: #fff;
  border: 1px solid rgba(255,255,255,0.3); -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px); padding: 0.2rem 0.65rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 500;
}
.btn-ghost, .btn-bright {
  padding: 0.45rem 0.85rem; border-radius: 9px; font-size: 0.85rem; font-weight: 600;
}
.btn-ghost {
  background: rgba(255,255,255,0.16); color: #fff;
  border: 1px solid rgba(255,255,255,0.32); -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.btn-ghost:hover { background: rgba(255,255,255,0.3); text-decoration: none; }
.btn-bright { background: #fff; color: var(--accent-dark); font-weight: 700; }
.btn-bright:hover { background: #eef7f9; text-decoration: none; }

.detail-grid {
  display: grid; grid-template-columns: 1fr; gap: 1.5rem; align-items: start;
}
/* Advice gets the lion's share; latest reading sits in a comfortable sidebar. */
@media (min-width: 860px) {
  .detail-grid { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); }
}
.detail-grid .card { margin-bottom: 0; }

.photo-preview {
  display: block; max-width: 100%; max-height: 180px;
  border-radius: 8px; border: 1px solid var(--line); margin: 0.3rem 0 0.2rem;
}

/* --- Analysis charts --- */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.chart-card { margin-bottom: 0; padding: 1rem 1.1rem; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.chart-head h2 { margin: 0; font-size: 1rem; }
.chart-latest { font-weight: 700; font-size: 1.05rem; }
.chart-latest.in { color: var(--ok); }
.chart-latest.out { color: var(--warning); }
.chart-latest.neutral { color: var(--accent-dark); }
.chart-foot { margin: 0.4rem 0 0; }

.chart { width: 100%; height: auto; display: block; margin: 0.5rem 0 0.2rem; overflow: visible; }
.chart-band { fill: var(--accent); opacity: 0.10; }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-area { fill: var(--accent); opacity: 0.08; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); }
.chart-dot.last { fill: var(--accent-dark); stroke: #fff; stroke-width: 1.5; }
.chart-yl { fill: var(--muted); font-size: 8px; }
.chart-xl { fill: var(--muted); font-size: 8px; }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.75rem 1rem; }
