/* Church Farm Weather - Home Assistant inspired dashboard styling */

:root {
  --bg: #f3f4ef;
  --surface: #ffffff;
  --surface-2: #f7f8f4;
  --text: #1d2420;
  --muted: #66706a;
  --border: #e1e4dc;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 2px 8px rgba(20, 30, 20, .06);
  --radius: 14px;
  --grid: rgba(0, 0, 0, .07);
  --danger: #c0392b;
  --success: #2e7d32;

  --c-temperature: #f2711c;
  --c-humidity: #2185d0;
  --c-pressure: #8e44ad;
  --c-rainfall: #00a3bf;
  --c-windSpeed: #16a085;
  --c-windDirection: #4c9a2a;
  --c-groundTemperature: #a0662b;
  --c-battery: #3a9e4f;
  --c-lastReading: #6c7a89;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111412;
    --surface: #1c201d;
    --surface-2: #232824;
    --text: #e6ebe7;
    --muted: #9aa49d;
    --border: #2d332e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --grid: rgba(255, 255, 255, .08);
  }
}
:root[data-theme="dark"] {
  --bg: #111412;
  --surface: #1c201d;
  --surface-2: #232824;
  --text: #e6ebe7;
  --muted: #9aa49d;
  --border: #2d332e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --grid: rgba(255, 255, 255, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.container { flex: 1; padding-top: 24px; padding-bottom: 40px; }
.icon { width: 24px; height: 24px; display: block; }

/* ---------- Header & menu ---------- */
.site-header { background: var(--header-bg); color: var(--header-text); box-shadow: 0 2px 6px rgba(0, 0, 0, .15); z-index: 20; }
.site-header.sticky { position: sticky; top: 0; }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.site-logo { width: auto; max-width: 220px; object-fit: contain; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.site-title { font-size: 1.3rem; font-weight: 650; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-tagline { font-size: .85rem; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-menu { margin-left: auto; }
.site-menu ul { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; }
.site-menu a { display: block; padding: 8px 14px; border-radius: 999px; color: inherit; text-decoration: none; font-weight: 500; opacity: .9; }
.site-menu a:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
.site-menu a.active { background: var(--accent); color: #fff; opacity: 1; }
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; color: inherit; padding: 8px; border-radius: 8px; cursor: pointer; }

@media (max-width: 720px) {
  .menu-toggle { display: block; }
  .site-menu { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--header-bg); padding: 8px 16px 14px; box-shadow: 0 6px 10px rgba(0, 0, 0, .15); }
  .site-menu.open { display: block; }
  .site-menu ul { flex-direction: column; }
  .header-inner { position: relative; }
  .site-tagline { display: none; }
}

/* ---------- Page ---------- */
.page-intro h1 { margin: 0 0 2px; font-size: 1.5rem; font-weight: 600; }
.page-intro p { margin: 0 0 18px; }
.live-status { margin-left: 8px; font-size: .85rem; }
.live-status.stale { color: var(--danger); }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; border: 1px solid var(--border); }
.prose { max-width: 820px; }
.prose h1 { margin-top: 0; }
.site-footer { padding: 18px 0; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }

/* ---------- Cards (tile style) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: stretch; text-align: left;
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 0; cursor: pointer;
  overflow: hidden; min-height: 150px; transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0, 0, 0, .1); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-icon {
  --c: var(--accent); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 50%; color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.card-label { font-weight: 550; color: var(--muted); font-size: .92rem; }
.card-value { font-size: 1.85rem; font-weight: 600; margin-top: 10px; line-height: 1.15; }
.card-value small { font-size: 1rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.card-value.awaiting { font-size: 1.05rem; font-weight: 500; color: var(--muted); font-style: italic; margin-top: 16px; }
.card-sub { color: var(--muted); font-size: .85rem; min-height: 1.3em; margin-top: 2px; }
.sparkline { display: block; width: calc(100% + 32px); height: 42px; margin: auto -16px 0; }
.sparkline path.line { fill: none; stroke: var(--c); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.sparkline path.area { fill: color-mix(in srgb, var(--c) 18%, transparent); stroke: none; }
.sparkline rect { fill: color-mix(in srgb, var(--c) 55%, transparent); }
.wind-arrow { display: inline-block; width: 26px; height: 26px; vertical-align: -4px; margin-right: 6px; color: var(--c-windDirection); transition: transform .6s ease; }
.battery-level { transition: width .4s ease; }

.icon-temperature { --c: var(--c-temperature); }
.icon-humidity { --c: var(--c-humidity); }
.icon-pressure { --c: var(--c-pressure); }
.icon-rainfall { --c: var(--c-rainfall); }
.icon-windSpeed { --c: var(--c-windSpeed); }
.icon-windDirection { --c: var(--c-windDirection); }
.icon-groundTemperature { --c: var(--c-groundTemperature); }
.icon-battery { --c: var(--c-battery); }
.icon-lastReading { --c: var(--c-lastReading); }
.card[data-field="temperature"] { --c: var(--c-temperature); }
.card[data-field="humidity"] { --c: var(--c-humidity); }
.card[data-field="pressure"] { --c: var(--c-pressure); }
.card[data-field="rainfall"] { --c: var(--c-rainfall); }
.card[data-field="windSpeed"] { --c: var(--c-windSpeed); }
.card[data-field="windDirection"] { --c: var(--c-windDirection); }
.card[data-field="groundTemperature"] { --c: var(--c-groundTemperature); }
.card[data-field="battery"] { --c: var(--c-battery); }
.card[data-field="lastReading"] { --c: var(--c-lastReading); }
.card.stale .card-sub { color: var(--danger); }

/* ---------- More-info dialog ---------- */
dialog.more-info {
  width: min(880px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: 20px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.more-info::backdrop { background: rgba(10, 15, 12, .55); backdrop-filter: blur(2px); }
dialog.more-info[open] { animation: pop .16s ease-out; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.mi-header { display: flex; align-items: center; gap: 14px; padding: 18px 20px 8px; }
.mi-titles { flex: 1; min-width: 0; }
.mi-titles h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.mi-current { font-size: 1.6rem; font-weight: 600; }
.mi-current small { font-size: .95rem; color: var(--muted); font-weight: 500; }
.icon-button { background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 50%; cursor: pointer; }
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.range-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 20px 12px; border-bottom: 1px solid var(--border); }
.range-tab {
  font: inherit; font-size: .88rem; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.range-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.range-tab:disabled { opacity: .45; cursor: not-allowed; }
.mi-body { padding: 16px 20px 22px; overflow: auto; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.rose { height: 320px; max-width: 420px; margin: 18px auto 0; }
.mi-message { padding: 40px 10px; text-align: center; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 18px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.2rem; font-weight: 600; }
.stat-when { color: var(--muted); font-size: .78rem; }
.section-title { margin: 22px 0 6px; font-size: .95rem; font-weight: 600; color: var(--muted); }
table.readings { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.readings th, table.readings td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.readings th:first-child, table.readings td:first-child { text-align: left; }
.table-scroll { overflow-x: auto; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; font-weight: 500; }

/* ---------- Contact form ---------- */
.contact-panel { max-width: 640px; }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 550; margin-bottom: 5px; }
.form-row input[type=text], .form-row input[type=email], .form-row textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.form-row input:focus, .form-row textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-row.has-error input, .form-row.has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .85rem; margin: 4px 0 0; }
.captcha-box { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.captcha-image svg { display: block; border-radius: 8px; border: 1px solid var(--border); max-width: 100%; height: auto; }
.captcha-row input[type=text] { max-width: 220px; text-transform: uppercase; letter-spacing: .15em; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.button {
  font: inherit; font-weight: 600; background: var(--accent); color: #fff; border: 0;
  border-radius: 999px; padding: 10px 22px; cursor: pointer;
}
.button:disabled { opacity: .6; cursor: progress; }
.notice { border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
.notice.success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.notice.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---------- Download page ---------- */
.download-panel { max-width: 760px; }
.download-form fieldset { border: 0; padding: 0; margin: 0 0 22px; }
.download-form legend { font-weight: 650; font-size: 1.02rem; margin-bottom: 8px; padding: 0; }
.date-row { display: flex; flex-wrap: wrap; gap: 16px; }
.date-row .form-row { margin-bottom: 8px; }
.download-form input[type=date] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
.download-form .has-error input[type=date] { border-color: var(--danger); }
.quick-ranges { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: .85rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.chip:hover { border-color: var(--accent); }
.select-all { font-size: .88rem; margin-bottom: 8px; color: var(--muted); }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.choice { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); }
.choice input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.choice .card-icon { width: 30px; height: 30px; }
.choice .card-icon .icon { width: 18px; height: 18px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: .85rem; margin: 8px 0 0; }
fieldset.has-error .checkbox-grid { outline: 1px solid var(--danger); outline-offset: 4px; border-radius: 10px; }
.download-panel > p:first-child { margin-top: 0; }

/* ---------- Stations ---------- */
:root { --c-rainRate: #1f7ae0; }
.icon-rainRate, .card[data-field="rainRate"] { --c: var(--c-rainRate); }
.station-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.station-tabs a {
  padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); font-weight: 550;
}
.station-tabs a[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.card[hidden] { display: none; }

/* ---------- Highs & lows ---------- */
.mi-extremes { padding: 0 20px 22px; }
.mi-extremes:empty { display: none; }
table.extremes td, .records-table td { vertical-align: top; }
table.readings .stat-when { display: block; }
.records-panel { max-width: 860px; }
.records-tabs { padding: 0 0 12px; border-bottom: 0; }
.records-range { margin: 0 0 10px; }
.records-table th[scope=row] { text-align: left; font-weight: 550; }
.records-table td { font-size: 1rem; }
.records-table td small { color: var(--muted); }
.cell-label { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Admin ---------- */
.admin-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: -6px 0 18px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.admin-tabs a { padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--text); font-weight: 550; }
.admin-tabs a.active { background: var(--accent); color: #fff; }
.admin-tabs .logout { margin-left: auto; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 14px; }
.admin-grid .panel, .panel + .panel, .todo-panel { margin-bottom: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 1.1rem; }
.panel h3 { font-size: 1rem; margin: 16px 0 6px; }
.narrow-panel { max-width: 520px; }
.button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.button { display: inline-block; text-decoration: none; }
.link-button.danger, .danger { color: var(--danger); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks li { display: flex; gap: 10px; align-items: flex-start; }
.check-icon { flex: 0 0 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; color: #fff; }
.check-ok .check-icon { background: var(--success); }
.check-warning .check-icon { background: #c98500; }
.check-error .check-icon { background: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.todo { padding-left: 20px; }
.todo li { margin-bottom: 6px; }
.todo-panel { border-left: 4px solid #c98500; }
.setup-section { margin-bottom: 12px; padding: 0; }
.setup-section > summary { list-style: none; cursor: pointer; padding: 16px 22px; display: flex; align-items: center; }
.setup-section > summary::-webkit-details-marker { display: none; }
.setup-section > summary::before { content: '▸'; margin-right: 10px; color: var(--muted); transition: transform .15s; }
.setup-section[open] > summary::before { transform: rotate(90deg); }
.setup-section > summary h2 { margin: 0; }
.setup-section > :not(summary) { padding: 0 22px; }
.setup-section > :last-child { padding-bottom: 20px; }
.setup-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0 18px; }
.setup-fields .repeat, .setup-fields .checkbox-row { grid-column: 1 / -1; }
.setup-fields .checkbox-row { margin-bottom: 8px; }
.form-row select, .form-row input[type=number], .form-row input[type=password], .repeat-row input, .station-row input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
.form-row input[type=color] { width: 70px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.form-row .hint { margin-top: 4px; }
.choice.inline { display: inline-flex; background: none; padding: 4px 0; font-size: .85rem; }
.input-with-button { display: flex; gap: 8px; align-items: center; }
.input-with-button input { flex: 1; min-width: 0; }
.file-button { cursor: pointer; white-space: nowrap; }
.logo-preview { max-height: 56px; margin-top: 8px; background: var(--header-bg); padding: 6px; border-radius: 8px; }
.repeat-row { display: grid; grid-template-columns: 1fr 2fr auto auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.station-row { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
.station-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.station-grid .wide { grid-column: 1 / -1; }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); }
textarea.code { width: 100%; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.job-log { background: #111; color: #d6e2d6; padding: 12px; border-radius: 10px; max-height: 320px; overflow: auto; font-size: .82rem; white-space: pre-wrap; }
.file-list { columns: 2; font-size: .85rem; padding-left: 18px; }
.release-note { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.release-note p { margin: 4px 0; }
.message { border-bottom: 1px solid var(--border); padding: 12px 0; }
.message-subject { font-weight: 600; margin: 6px 0 2px; }
.message-body { white-space: pre-wrap; margin: 4px 0 6px; }
.pager { display: flex; gap: 16px; justify-content: center; margin-top: 14px; }
@media (max-width: 600px) {
  .repeat-row { grid-template-columns: 1fr auto auto; }
  .repeat-row input[name=menu_url] { grid-column: 1 / -1; grid-row: 2; }
  .file-list { columns: 1; }
}
@media (max-width: 600px) {
  .records-panel, .panel { padding: 16px 14px; }
  table.records-table th, table.records-table td, table.extremes th, table.extremes td { white-space: normal; padding: 6px 4px; }
  .records-table th[scope=row] { font-size: .88rem; }
}
.site-log { max-height: 70vh; }
.steps { padding-left: 22px; }
.steps li { margin-bottom: 14px; }
.inline-form { margin-top: 10px; max-width: 520px; }
.check-line.ok { color: var(--success); }
.check-line.bad { color: var(--danger); }
.check-line.warn { color: #b07400; }
.input-with-button input[readonly] {
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
