:root {
  --accent: #667eea;
  --accent-dark: #5568d3;
  --bg: #f5f7fa;
  --card: #fff;
  --text: #333;
  --muted: #777;
  --line: #e6e8ef;
  --on: #48bb78;
  --heat: #ed8936;
  --danger: #e53e3e;
  --chart-1: #667eea; --chart-2: #ed8936; --chart-3: #48bb78;
  --chart-4: #e53e3e; --chart-5: #805ad5; --chart-6: #319795;
}
.lc-frame { display: none; }   /* LCARS frame pieces, only shown by lcars.css */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
button, input, select, textarea { font: inherit; }

.header {
  background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15);
  padding: 0 8px 0 16px; height: 56px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 19px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; fill: #fff; flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 2px; font-size: 14px; color: rgba(255,255,255,.85); }
.header-right .who { margin-right: 8px; }
.icon-btn {
  display: flex; align-items: center; gap: 6px; color: #fff; text-decoration: none; font-size: 14px;
  padding: 8px 10px; border-radius: 8px; min-height: 40px;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,.18); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.btn {
  padding: 8px 14px; background: var(--accent); color: #fff; border: none; border-radius: 6px;
  cursor: pointer; text-decoration: none; font-size: 14px; display: inline-block;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.light { background: #edf0fb; color: var(--accent-dark); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

.tabs { display: flex; gap: 6px; padding: 12px 16px 0; overflow-x: auto; max-width: 1200px; margin: 0 auto; }
.tabs { scrollbar-width: none; }
.tabs[hidden] { display: none; }
.tab {
  padding: 7px 16px; border-radius: 20px; background: #e4e8f4; color: #555; border: none; cursor: pointer;
  white-space: nowrap; font-size: 14px; font-weight: 500;
}
.tab.active { background: var(--accent); color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.message { background: var(--card); border-radius: 12px; padding: 32px; text-align: center; color: var(--muted); }

.card { background: var(--card); border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.08); padding: 20px; }
.card h3 { font-size: 17px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.card .error { color: var(--danger); font-size: 13px; margin-top: 10px; }
.card .muted { color: var(--muted); font-size: 13px; }

.row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); gap: 12px; }
.row-end { display: flex; align-items: center; gap: 12px; }
.row:first-child { border-top: none; }
.row .value { font-weight: 600; }

.big-temp { font-size: 40px; font-weight: 300; line-height: 1.1; }
.temp-row { padding-top: 0; }
.row[hidden] { display: none; }
.status-pill { font-size: 12px; padding: 3px 10px; border-radius: 12px; background: #eee; color: #666; font-weight: 500; }
.status-pill.heating { background: #feebc8; color: #c05621; }
.status-pill.on { background: #c6f6d5; color: #276749; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #fff;
  font-size: 20px; cursor: pointer; color: var(--accent-dark);
}
.stepper button:disabled { opacity: .4; cursor: default; }

.switch { position: relative; width: 50px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #cbd5e0; border-radius: 28px; cursor: pointer; transition: .2s;
}
.switch span::before {
  content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--on); }
.switch input:checked + span::before { transform: translateX(22px); }
.switch input:disabled + span { opacity: .4; cursor: default; }

/* power bars */
.power-row { display: block; }
.power-line { display: flex; justify-content: space-between; gap: 12px; }
.bar { height: 6px; background: #edf0f7; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .4s; }
.bar-fill.negative { background: var(--on); }

/* charts */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart-grid { stroke: #e6e8ef; stroke-width: 1; }
.chart-zero { stroke: #a0aec0; stroke-width: 1; }
.chart-cursor { stroke: #a0aec0; stroke-width: 1; stroke-dasharray: 3 3; }
.chart-label { font-size: 11px; fill: #888; }
.chart-readout { margin-top: 6px; min-height: 1.4em; }
.daily-bar { fill: var(--chart-1); cursor: pointer; }
.daily-bar.today { opacity: .55; }
.daily-bar.picked { fill: var(--accent); opacity: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; color: #555; }
.chart-key i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.chart-select { fill: var(--accent); fill-opacity: .15; stroke: var(--accent); stroke-opacity: .5; }
.chart-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); min-height: 28px; }
.chart-stats { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.chart-stats th { text-align: right; font-weight: 500; color: var(--muted); padding: 4px 6px; }
.chart-stats td { text-align: right; padding: 5px 6px; border-top: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-stats td:first-child, .chart-stats th:first-child { text-align: left; padding-left: 0; }
.chart-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-tools[hidden], .chart-tools [hidden], .chart-stats[hidden] { display: none; }
.row.has-history { cursor: pointer; }
.row.has-history .value { text-decoration: none; }
.row.has-history:hover .value, .row.has-history:focus-visible .value { color: var(--accent); }
.chart-dialog { max-width: 760px; }
.chart-stats.no-total .total-col { display: none; }
.range-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.card.wide { grid-column: 1 / -1; }

/* login */
.login-page { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: #fff; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.2); width: 100%; max-width: 380px; padding: 32px; }
.login-box h1 { font-size: 24px; text-align: center; margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 14px; color: #555; margin-bottom: 6px; }
.field input[type=text], .field input[type=password], .field input[type=email], .field input[type=number], .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #d5d9e3; border-radius: 6px; background: #fff;
}
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #555; margin-bottom: 18px; }
.login-box .btn { width: 100%; padding: 12px; font-size: 16px; }
.login-link { color: var(--accent); font-size: 14px; }
.login-error { background: #fed7d7; color: #c53030; padding: 10px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; }

/* admin */
.admin h2 { font-size: 20px; margin: 24px 0 12px; }
.admin .card { margin-bottom: 16px; }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: middle; }
.admin th { color: var(--muted); font-weight: 500; border-top: none; }
.admin .inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin .inline input[type=text], .admin .inline select { padding: 6px 8px; border: 1px solid #d5d9e3; border-radius: 6px; }
.admin .card-list .row { font-size: 14px; }
.admin .entity-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.admin .entity-row input { padding: 6px 8px; border: 1px solid #d5d9e3; border-radius: 6px; min-width: 0; }
.dialog-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; z-index: 20; }
.dialog { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; }
.dialog h3 { margin-bottom: 14px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 30; max-width: 90vw; }
.scroll { overflow-x: auto; }

@media (max-width: 600px) {
  .header-right .who, .icon-btn span { display: none; }
  .icon-btn { padding: 8px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .container { padding: 12px; }
  .tabs { padding: 12px 12px 0; }
  .card { padding: 16px; }
  .card h3 { font-size: 16px; margin-bottom: 8px; }
  .big-temp { font-size: 34px; }
}
