:root {
  --bg: #0f1720;
  --panel: #18222e;
  --panel-2: #212e3c;
  --line: #2c3a4a;
  --text: #e8eef4;
  --muted: #8ea0b3;
  --green: #2ecc71;
  --green-dim: #1d3b2b;
  --red: #ff5a5f;
  --gold: #f5c04a;
  --blue: #4aa3f5;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: rgba(15,23,32,.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.bulbs { display: inline-flex; gap: 3px; }
.bulbs i { width: 8px; height: 11px; border-radius: 50% 50% 45% 45%; background: var(--red); box-shadow: 0 0 8px var(--red); }
.bulbs i:nth-child(2) { background: var(--green); box-shadow: 0 0 8px var(--green); }
.bulbs i:nth-child(3) { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-size: 14px; }
.top nav a.active { background: var(--panel-2); color: var(--text); }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px calc(100px + var(--safe-b)); }
h1 { font-size: 22px; margin: 4px 0 2px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 10px; }
.sub { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; }
.card:active { background: var(--panel-2); }
.card .title { font-weight: 650; font-size: 17px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.roof { background: #3a2f14; color: var(--gold); }
.meter { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; background: var(--green); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel-2); border-radius: 12px; padding: 11px 16px; cursor: pointer; min-height: 46px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #062312; font-weight: 700; }
.btn.danger { background: transparent; border-color: #5a2a2e; color: var(--red); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.fab { position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 4; border-radius: 999px;
  padding: 14px 20px; box-shadow: 0 6px 20px rgba(0,0,0,.45); }

.ports { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 560px) { .ports { grid-template-columns: repeat(8, 1fr); } }
.port { position: relative; aspect-ratio: 1 / 1.05; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  padding: 6px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; cursor: pointer; overflow: hidden; }
.port .n { font-weight: 800; font-size: 18px; color: var(--muted); }
.port .p { font-size: 11px; line-height: 1.15; max-height: 2.4em; overflow: hidden; word-break: break-word; }
.port .px { font-size: 10px; color: var(--muted); }
.port.on { background: var(--green-dim); border-color: var(--green); }
.port.on .n { color: var(--green); }
.port.assigned:not(.on) { border-style: dashed; }

.list .item { display: flex; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.ev-icon { flex: 0 0 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-size: 15px; }
.ev-icon.connected { background: var(--green-dim); color: var(--green); }
.ev-icon.disconnected { background: #3b1d20; color: var(--red); }
.ev-icon.note { background: #1b2c3f; color: var(--blue); }
.ev-icon.moved { background: #3a2f14; color: var(--gold); }
.ev-main { flex: 1; min-width: 0; }
.ev-main .t { color: var(--muted); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  outline: none; font-size: 16px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { padding: 6px 11px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.chip.sel { border-color: var(--gold); color: var(--gold); }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }
.search { margin-bottom: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; }

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--panel);
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(22px + var(--safe-b)); border-top: 1px solid var(--line);
  animation: up .18s ease-out; max-width: 760px; margin: 0 auto; }
.sheet-panel::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 30; font-size: 14px; }
.toast.hidden { display: none; }
.login { max-width: 360px; margin: 60px auto; }

/* smart receivers */
.rid { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 7px;
  background: #1b2c3f; color: var(--blue); font-weight: 800; font-size: 14px; vertical-align: 2px; }
.rid.big { min-width: 32px; height: 32px; font-size: 18px; border-radius: 9px; }
.card.child { margin-left: 18px; border-left: 3px solid #2a4560; }
.card.rx { background: var(--panel); }
.rxbox { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 2px 12px 8px; margin-top: 12px; }

/* nav badge */
.top nav a { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.brand { white-space: nowrap; }
@media (max-width: 400px) { .brand-txt { display: none; } .top nav a { padding: 6px 10px; } }
.nbadge { background: var(--red); color: #fff; font-size: 11px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 9px;
  display: inline-grid; place-items: center; padding: 0 5px; }
.nbadge.hidden, .hidden { display: none !important; }

/* problems */
.badge.warn { background: #3b1d20; color: var(--red); }
.stat.warn { border-color: #5a2a2e; }
.stat.warn b { color: var(--red); }
a.stat { display: block; }
.warnbtn { color: #ffb4b6; }
.warnbox { border-color: #5a2a2e; background: #241619; }
.ev-icon.issue { background: #3b1d20; color: var(--red); }
.ev-icon.fixed { background: var(--green-dim); color: var(--green); }
.ev-icon.imported { background: #1b2c3f; color: var(--blue); }
.port.hasissue { box-shadow: inset 0 0 0 2px var(--red); }
.warn-dot { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--red); color: #fff;
  font-size: 10px; font-style: normal; font-weight: 900; margin-left: 4px; vertical-align: 3px; }
button.item { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; color: inherit; }
.list button.item:last-child { border-bottom: 0; }
.issue.fixed b { text-decoration: line-through; color: var(--muted); }

/* GPIO / video rows */
.outrow { align-items: center; }
.outrow .dot { flex: 0 0 9px; }
.block { display: block; }

/* actions with 4 buttons */
.actions.wrap4 { flex-wrap: wrap; }
.actions.wrap4 .btn { flex: 1 1 calc(50% - 10px); }
@media (min-width: 520px) { .actions.wrap4 .btn { flex: 1; } }

/* photos */
.photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.thumb { padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--panel-2); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
img.full { width: 100%; border-radius: 12px; display: block; max-height: 65vh; object-fit: contain; background: #000; }

/* import */
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--blue); font-size: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.tbl th, .tbl td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; }
.tbl .num { text-align: right; white-space: nowrap; }
input[type=file] { padding: 10px; font-size: 14px; }

/* ================= North Pole Command ================= */
:root { --tab-h: 62px; --santa: #e0353b; }

/* nav: top on desktop, bottom tab bar on phones */
.tabbar { display: none; }
.top nav a[data-nav="settings"] { font-size: 17px; padding: 4px 10px; }
@media (max-width: 719px) {
  .topnav { display: none !important; }
  .brand-txt { display: inline !important; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    padding: 4px 4px var(--safe-b); background: rgba(15,23,32,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0 7px; font-size: 11px; color: var(--muted); }
  .tabbar a span { position: relative; font-size: 21px; line-height: 1.15; filter: grayscale(.7); opacity: .75; }
  .tabbar a.active { color: var(--text); }
  .tabbar a.active span { filter: none; opacity: 1; }
  .tabbar .nbadge { position: absolute; top: -3px; right: -12px; font-style: normal; font-size: 10px; min-width: 16px; height: 16px; }
  main { padding-bottom: calc(var(--tab-h) + 90px + var(--safe-b)); }
  .fab { bottom: calc(var(--tab-h) + 14px + var(--safe-b)); }
  .toast { bottom: calc(var(--tab-h) + 80px + var(--safe-b)); }
}

/* wider home screen on computers */
main.wide { max-width: 1180px; }
.dash { display: grid; gap: 0 22px; }
@media (min-width: 900px) { .dash { grid-template-columns: 1.25fr 1fr; } }
.dash .col { min-width: 0; }
.dash h2 { margin-top: 22px; }
.dash .row.spread h2 { margin-bottom: 10px; }

/* hero */
.hero { position: relative; overflow: hidden; padding: 18px; margin-top: 4px;
  background: radial-gradient(120% 140% at 100% 0%, #3a1518 0%, #1b1f2a 55%, var(--panel) 100%); border-color: #4a2427; }
.hero:active { background: radial-gradient(120% 140% at 100% 0%, #3a1518 0%, #1b1f2a 55%, var(--panel) 100%); }
.kicker { font-size: 13px; color: #ffb4b6; font-weight: 600; letter-spacing: .02em; }
.xmas { font-size: 22px; margin-top: 4px; }
.xmas b { font-size: 40px; color: var(--gold); text-shadow: 0 0 18px rgba(245,192,74,.35); vertical-align: -4px; }
.sleigh { font-size: 42px; transform: scaleX(-1); opacity: .9; }
.showline { margin-top: 12px; padding: 12px; border-radius: 12px; background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.06); }
.showline b { font-size: 17px; }
.showline.is-live { border-color: var(--green); background: rgba(46,204,113,.08); }
.live { color: var(--green); }

/* attention */
.alerts { display: grid; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); font-size: 14px; cursor: default; }
a.alert, .alert[data-fpp] { cursor: pointer; }
.alert.warn { border-color: #5a2a2e; background: #241619; }
.alert.info { border-color: #2a4560; background: #142130; }

/* FPP */
.fpp-grid { display: grid; gap: 10px; }
@media (min-width: 560px) { .fpp-grid { grid-template-columns: 1fr 1fr; } }
.card.fpp { width: 100%; text-align: left; cursor: pointer; margin: 0; color: inherit; font: inherit; }
.card.fpp.playing { border-color: var(--green); background: linear-gradient(180deg, rgba(46,204,113,.09), var(--panel) 70%); }
.card.fpp.off { border-color: #5a2a2e; }
.card.fpp .np { margin: 6px 0 2px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.state.on { color: var(--green); }
.state.off { color: var(--red); }
.state.gold { color: var(--gold); }
.state.idle { color: var(--blue); }
.agent-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.ctl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.np-card { margin-top: 12px; border-color: var(--green); }
.kv div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.kv b { color: var(--text); font-weight: 600; text-align: right; }
.warnline { color: var(--gold); padding: 4px 0; }
input[type=range] { accent-color: var(--green); flex: 1; border: 0; background: none; }
.row select { flex: 1; }

/* links */
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  min-height: 92px; padding: 10px 6px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.tile:active, .tile:hover { background: var(--panel-2); }
.tile .ic { font-size: 28px; line-height: 1; }
.tile .tt { font-size: 13px; font-weight: 600; line-height: 1.2; word-break: break-word; }
.tile .home { position: absolute; top: 5px; right: 7px; font-size: 11px; opacity: .8; }
.tile.editing { border-style: dashed; border-color: var(--gold); }
.tile .ed { position: absolute; top: 4px; left: 7px; color: var(--gold); font-size: 13px; }
.grp { font-size: 12px; color: var(--muted); margin: 12px 2px 6px; font-weight: 600; }
.small-note { font-size: 12px; margin-top: 8px; }
.chips.icons .chip { font-size: 20px; padding: 4px 9px; }

/* weather */
.weather .wx-icon { font-size: 40px; }
.weather .temp { font-size: 32px; font-weight: 700; line-height: 1; }
.hours { display: flex; gap: 6px; overflow-x: auto; margin-top: 12px; padding-bottom: 4px; scrollbar-width: thin; }
.hour { flex: 0 0 auto; min-width: 54px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px;
  border-radius: 10px; background: var(--panel-2); font-size: 14px; }
.hour .sub { font-size: 11px; }
.hour.windy { box-shadow: inset 0 0 0 1px var(--gold); }
.hour.windy .gust { color: var(--gold); font-weight: 700; }

/* light tracker card */
.lt-card .stats.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 8px; }
.lt-card .stats.mini > div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.lt-card .stats.mini b { display: block; font-size: 19px; }
.lt-card .stats.mini span { font-size: 11px; color: var(--muted); }
.lt-card .stats.mini .warn b { color: var(--red); }

/* settings */
.steps { padding-left: 20px; }
.steps li { margin: 6px 0; }
.cmd { background: #070b10; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.cmd code { font-size: 13px; white-space: pre-wrap; word-break: break-all; color: #b6f5cf; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.tile .tabs { position: absolute; top: 5px; left: 7px; font-size: 10px; font-weight: 700; color: var(--gold); }
.tile.editing .tabs { display: none; }
.list a.item { align-items: center; }
.list a.item .ev-main { word-break: break-all; }
.list a.item > .sub { flex: 0 0 auto; white-space: nowrap; }
