:root {
  font-family: system-ui, sans-serif;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #18212b;
  --muted: #687583;
  --label: #56616d;
  --border: #c7ced6;
  --chart-border: #e5e8ec;
  --chart-grid: #e4e8ec;
  --chart-text: #667380;
  --primary: #17212b;
  --primary-text: #ffffff;
  --link: #174a8b;
  --danger: #b42318;
  --danger-bg: #fff5f4;
  --shadow: 0 1px 4px #0001;
  --modal-overlay: rgba(0, 0, 0, 0.45);
}

body[data-theme="dark"] {
  --bg: #101418;
  --surface: #1a2026;
  --surface-2: #222a31;
  --text: #edf2f7;
  --muted: #a9b4bf;
  --label: #b8c2cc;
  --border: #46515c;
  --chart-border: #39434d;
  --chart-grid: #303943;
  --chart-text: #b6c0ca;
  --primary: #e9eef3;
  --primary-text: #11161b;
  --link: #8fc4ff;
  --danger: #ff8a80;
  --danger-bg: #35211f;
  --shadow: 0 1px 5px #0006;
  --modal-overlay: rgba(0, 0, 0, 0.68);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); transition: background .18s ease, color .18s ease; }
main { max-width: 1180px; margin: auto; padding: 20px; }
header { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
h1 { margin: 0 0 4px; font-size: 28px; }
.muted { color: var(--muted); font-size: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls { display: flex; gap: 10px; }
button, select, a { font: inherit; }
button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 16px;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.theme-button { min-width: 128px; }
.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface); border-radius: 10px; padding: 15px; box-shadow: var(--shadow); }
.card span { display: block; color: var(--chart-text); font-size: 13px; }
.card strong { font-size: 30px; line-height: 1.25; }
.card small { margin-left: 3px; color: var(--chart-text); }
.panel { background: var(--surface); border-radius: 10px; padding: 15px; box-shadow: var(--shadow); margin-bottom: 14px; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 10px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--label); }
select { min-width: 260px; padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); }
canvas { width: 100%; height: auto; max-height: 56vh; border: 1px solid var(--chart-border); border-radius: 7px; background: var(--surface); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; }
.legend span::before { content: ""; display: inline-block; width: 18px; height: 3px; margin-right: 6px; vertical-align: middle; background: #555; }
.l1::before{background:#1976d2!important}.l2::before{background:#d32f2f!important}.l3::before{background:#388e3c!important}.l4::before{background:#f57c00!important}.lh::before{background:#999!important}
.exports { display: flex; gap: 12px; align-items: center; }
.exports a { color: var(--link); }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: var(--modal-overlay); }
.modal-dialog {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 18px 60px #0006;
}
.modal-dialog h2 { margin: 0 0 8px; font-size: 22px; }
.modal-dialog p { margin: 0 0 20px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media(max-width:850px){
  .cards{grid-template-columns:repeat(2,1fr)}
  header{align-items:flex-start;flex-direction:column}
  .header-actions{width:100%;justify-content:space-between}
  .toolbar{align-items:stretch;flex-direction:column}
}

.history-controls { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.history-controls button { margin-bottom: 0; }
@media(max-width:850px){
  .history-controls{align-items:stretch;flex-direction:column}
  .history-controls select{width:100%;min-width:0}
}

input[type="text"] {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.name-field { margin: 0 0 18px; }


.title-block { min-width: 0; }
.title-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.weather { display: inline-flex; align-items: center; gap: 7px; font-size: 25px; line-height: 1; white-space: nowrap; }
.weather #weatherIcon { font-size: 29px; }
.weather #outsideTemp { font-size: 25px; font-weight: 700; }
.public-link-panel { padding: 10px 14px; }
.public-link { display: flex; align-items: center; gap: 13px; color: var(--link); text-decoration: none; min-width: 0; }
.public-link:hover span { text-decoration: underline; }
.public-link span { overflow-wrap: anywhere; }
.qr-image { width: 82px; height: 82px; object-fit: contain; background: white; border-radius: 8px; padding: 4px; flex: 0 0 auto; }
@media(max-width:600px){
  .weather { font-size: 21px; }
  .weather #weatherIcon { font-size: 25px; }
  .weather #outsideTemp { font-size: 22px; }
  .qr-image { width: 68px; height: 68px; }
}
