/* binos -- palette from the dusk-over-the-bins photo.
   night navy base, steel greys, one restrained dusk-pink accent.
   Semantics stay semantic: green ON, steel OFF, red FAULT, amber UNKNOWN. */
:root {
  --night: #0b1424;
  --panel: #111d31;
  --panel-2: #16253d;
  --line: #213450;
  --line-2: #2c4366;
  --text: #e9eef6;
  --muted: #8ea0b9;
  --dusk: #f0a2b4;
  --dusk-deep: #d46f8a;
  --on: #3ec25a;
  --on-dim: rgba(62,194,90,.16);
  --off: #7a8ba3;
  --fault: #ff5c5c;
  --fault-dim: rgba(255,92,92,.14);
  --unknown: #e6b84a;
  --unknown-dim: rgba(230,184,74,.14);
  --info: #5aa9ff;
  --info-dim: rgba(90,169,255,.14);
  --danger: #c2333f;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--night); color: var(--text); font: 15px/1.45 var(--font); min-height: 100vh; }
a { color: var(--info); }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
main { max-width: 1140px; margin: 0 auto; padding: 22px 20px 48px; }
:focus-visible { outline: 2px solid var(--dusk); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---- brand mark: a fan seen head-on, three blades ---- */
.mark { width: 26px; height: 26px; border-radius: 50%; display: inline-block; position: relative; flex: none;
  background:
    conic-gradient(from 0deg, var(--dusk) 0 40deg, transparent 40deg 120deg,
                   var(--dusk) 120deg 160deg, transparent 160deg 240deg,
                   var(--dusk) 240deg 280deg, transparent 280deg 360deg);
  -webkit-mask: radial-gradient(circle, transparent 0 4px, #000 5px 11px, transparent 12px);
  mask: radial-gradient(circle, transparent 0 4px, #000 5px 11px, transparent 12px); }

/* ---- header ---- */
header.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px;
  padding: 12px 20px; background: rgba(11,20,36,.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); }
header.top .brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
header.top .brand .name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
header.top .brand .sub { color: var(--muted); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--line-2); }
header.top nav { display: flex; gap: 6px; }
header.top nav a { color: var(--muted); text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 500; }
header.top nav a:hover { color: var(--text); background: var(--panel-2); }
header.top nav a.on { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--dusk); }
header.top form.logout { margin-left: auto; display: flex; align-items: center; gap: 12px; }
header.top .who { color: var(--muted); font-size: 14px; }

/* ---- buttons ---- */
button { font: inherit; font-weight: 600; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; transition: filter .12s, transform .06s, background .12s; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; font-weight: 500; }
button.primary { background: var(--dusk-deep); border-color: var(--dusk-deep); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.wide { width: 100%; }

/* ---- toolbar / banner ---- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .actions { display: flex; gap: 10px; }
button.success { background: #1f8a3c; border-color: #136b2c; color: #fff; }
@media (max-width: 720px) { .toolbar .actions { width: 100%; } .toolbar .actions button { flex: 1; padding: 12px; } }
.live { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--muted); }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); box-shadow: 0 0 0 3px var(--unknown-dim); }
.live.ok .dot { background: var(--on); box-shadow: 0 0 0 3px var(--on-dim); animation: pulse 2s ease-in-out infinite; }
.live.bad .dot { background: var(--fault); box-shadow: 0 0 0 3px var(--fault-dim); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(62,194,90,.06); } }
.banner { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; border: 1px solid; }
.banner.bad { background: var(--fault-dim); border-color: var(--fault); }
.banner.info { background: var(--info-dim); border-color: var(--info); }
.banner.warn { background: var(--unknown-dim); border-color: var(--unknown); }
.filter { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.filter label { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.filter input[type="date"] { font: inherit; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; padding: 7px 10px; color-scheme: dark; }
.filter .clear { font-size: 14px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 18px 0; font-size: 15px; }
.pager a { text-decoration: none; font-weight: 600; padding: 8px 14px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel-2); }
.pager .off { opacity: .35; padding: 8px 14px; }
.pager .pageno { color: var(--muted); font-variant-numeric: tabular-nums; }
select { font: inherit; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 12px; }

/* ---- fan cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
article.fan { background: linear-gradient(180deg, var(--panel) 0%, #0f1a2c 100%); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; transition: border-color .2s; }
/* whole card carries the state colour */
article.fan { transition: background .25s, border-color .25s, color .25s; }
article.fan.ON      { background: #2f9d4b; border-color: #49c468; color: #052a10; }
article.fan.OFF     { background: #dfb23f; border-color: #f0c75a; color: #2a2004; }
article.fan.FAULT   { background: #cf3a3a; border-color: #ff6b6b; color: #fff; animation: cardpulse 1.1s ease-in-out infinite; }
article.fan.UNKNOWN { background: #6a798f; border-color: #8796ad; color: #f2f5fa; }
@keyframes cardpulse { 50% { box-shadow: 0 0 0 6px rgba(255,92,92,.35), var(--shadow); } }
article.fan[data-id] p.since, article.fan[data-id] p.since strong { color: inherit; }
article.fan[data-id] p.since { opacity: .85; }
article.fan[data-id] p.since strong { opacity: 1; }
article.fan .badge.ON, article.fan .badge.OFF, article.fan .badge.FAULT, article.fan .badge.UNKNOWN {
  color: inherit; border-color: rgba(0,0,0,.25); background: rgba(0,0,0,.22); }
article.fan .controls button.start { background: #1f8a3c; border-color: #136b2c; color: #fff; }
article.fan .controls button.stop  { background: #c62828; border-color: #9c1f1f; color: #fff; }
article.fan .controls button.start, article.fan .controls button.stop {
  box-shadow: 0 2px 6px rgba(0,0,0,.35); text-shadow: 0 1px 1px rgba(0,0,0,.35); }
article.fan .controls button:disabled { opacity: .35; box-shadow: none; }
article.fan .note.info, article.fan .note.warn, article.fan .note.bad {
  background: rgba(0,0,0,.28); border-color: rgba(0,0,0,.25); color: inherit; }
article.fan header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
article.fan h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.badge { font-weight: 700; font-size: 12px; letter-spacing: .08em; padding: 5px 11px; border-radius: 999px; border: 1px solid; }
.badge.ON { color: var(--on); border-color: var(--on); background: var(--on-dim); }
.badge.OFF { color: var(--unknown); border-color: var(--unknown); background: var(--unknown-dim); }
.badge.FAULT { color: #fff; border-color: var(--fault); background: var(--fault); }
.badge.UNKNOWN { color: var(--off); border-color: var(--line-2); background: transparent; }

article.fan .body { display: grid; grid-template-columns: 96px 1fr; gap: 18px; align-items: stretch; margin-bottom: 12px; }
.meters { display: flex; gap: 14px; justify-content: center; }
.meter { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.meter .track { position: relative; width: 26px; height: 92px; background: var(--night); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.meter .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: var(--off); transition: height .35s ease, background .2s; }
article.fan.ON .meter .fill { background: var(--on); }
article.fan.FAULT .meter .fill { background: var(--fault); }
article.fan.UNKNOWN .meter .fill { background: var(--unknown); opacity: .35; }
.meter .thresh { position: absolute; left: 0; right: 0; bottom: 25%; border-top: 1px dashed rgba(240,162,180,.7); }
.meter .lbl { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted); }

article.fan p.since { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
article.fan p.since strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

dl.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-content: start; }
dl.facts div { display: flex; flex-direction: column; gap: 2px; }
dl.facts div.wide { grid-column: 1 / -1; }
dl.facts dt { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
dl.facts dd { margin: 0; font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
dl.facts div.wide dd { font-size: 16px; font-weight: 500; color: var(--text); }

.note { font-size: 13px; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; }
.note.info { background: var(--info-dim); border-color: rgba(90,169,255,.5); }
.note.warn { background: var(--unknown-dim); border-color: rgba(230,184,74,.5); }
.note.bad { background: var(--fault-dim); border-color: rgba(255,92,92,.5); }

.controls { display: flex; gap: 10px; }
.controls button { flex: 1; padding: 11px; letter-spacing: .02em; }
.controls button.start { background: var(--on-dim); border-color: rgba(62,194,90,.55); color: #c6f2cf; }
.controls button.stop { background: var(--fault-dim); border-color: rgba(255,92,92,.55); color: #ffd2d2; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---- history ---- */
ol.history { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
ol.history li { display: grid; grid-template-columns: 14px max-content 1fr; gap: 14px; align-items: baseline;
  padding: 11px 16px; border-bottom: 1px solid var(--line); }
ol.history li:last-child { border-bottom: 0; }
ol.history li.empty { display: block; color: var(--muted); text-align: center; padding: 36px 16px; }
ol.history .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); align-self: center; }
ol.history li.ON .dot { background: var(--on); }
ol.history li.OFF .dot { background: var(--unknown); }
ol.history li.FAULT .dot, ol.history li.action_failed .dot { background: var(--fault); box-shadow: 0 0 0 3px var(--fault-dim); }
ol.history li.UNKNOWN .dot { background: var(--off); }
ol.history .ts { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
ol.history li.FAULT .txt, ol.history li.action_failed .txt { color: #ffb3b3; font-weight: 500; }
ol.history li.UNKNOWN .txt { color: var(--muted); }
ol.history li.command .txt { color: var(--text); }
ol.history li.external .txt { color: #cfd8e6; }
p.more { text-align: center; margin: 18px; }

/* ---- login ---- */
body.login-page { background: var(--night) url("bg.jpg") center 60% / cover no-repeat fixed; }
body.login-page::before { content: ""; position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(11,20,36,.15) 0%, rgba(11,20,36,.05) 45%, rgba(11,20,36,.55) 100%); }
body.login-page main { position: relative; display: flex; justify-content: center; align-items: flex-start; padding-top: clamp(40px, 11vh, 140px); }
.login-box { width: min(400px, 100%); padding: 30px 30px 28px; border-radius: 18px;
  background: rgba(11,20,36,.62); border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 24px 60px rgba(0,0,0,.45); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand .mark { width: 32px; height: 32px;
  -webkit-mask: radial-gradient(circle, transparent 0 5px, #000 6px 14px, transparent 15px);
  mask: radial-gradient(circle, transparent 0 5px, #000 6px 14px, transparent 15px); }
.login-box h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { margin: 4px 0 18px 44px; color: var(--muted); font-size: 14px; }
.login-box label { display: block; margin-top: 14px; }
.login-box label span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; }
.login-box input { width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; color: var(--text);
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.16); border-radius: 12px; transition: border-color .12s, background .12s; }
.login-box input:focus { outline: none; border-color: var(--dusk); background: rgba(255,255,255,.1); }
.login-box .primary { margin-top: 22px; padding: 13px; font-size: 16px; border-radius: 12px; }
.err { color: #ffb3b3; background: var(--fault-dim); border: 1px solid rgba(255,92,92,.5); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 0 0 4px; }

/* ---- responsive ---- */
@media (max-width: 720px) {
  main { padding: 16px 14px 40px; }
  header.top { flex-wrap: wrap; gap: 8px 14px; padding: 10px 14px; }
  header.top .brand .sub, header.top .who { display: none; }
  header.top .brand .name { white-space: nowrap; font-size: 16px; }
  header.top nav { order: 3; width: 100%; }
  header.top nav a { padding: 6px 10px; }
  header.top .ghost { white-space: nowrap; padding: 7px 10px; }
  .grid { grid-template-columns: 1fr; }
  .controls button { padding: 15px; font-size: 16px; }
  ol.history li { grid-template-columns: 12px 1fr; }
  ol.history .ts { grid-column: 2; }
  ol.history .txt { grid-column: 2; }
  body.login-page { background-attachment: scroll; }
}

/* ---- site map ---- */
.site { margin-top: 26px; }
.site header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.site h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.site-map { position: relative; width: min(820px, 100%); margin: 0 auto; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow); background: var(--panel); }
.site-map img { display: block; width: 100%; height: auto; }
.marker { position: absolute; transform: translate(-17px, -50%); display: flex; align-items: center; gap: 6px;
  padding: 0; background: transparent; border: 0; cursor: default; border-radius: 999px; }
.marker .pin { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff; background: var(--off); border: 3px solid rgba(255,255,255,.85);
  box-shadow: 0 3px 10px rgba(0,0,0,.6); transition: background .2s, transform .12s; }
.marker .tag { font-size: 12px; font-weight: 700; color: #fff; background: rgba(11,20,36,.78); padding: 3px 8px; border-radius: 6px;
  white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.marker.ON .pin { background: var(--on); }
.marker.OFF .pin { background: var(--unknown); color: #111; }
.marker.FAULT .pin { background: var(--fault); animation: pinpulse 1.1s ease-in-out infinite; }
.marker.UNKNOWN .pin { background: var(--off); }
@keyframes pinpulse { 50% { box-shadow: 0 0 0 9px rgba(255,92,92,.45); transform: scale(1.06); } }
/* key */
.site header { flex-wrap: wrap; gap: 8px 18px; }
.key { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 12px 16px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; font-weight: 600; color: var(--text); }
.key span { display: inline-flex; align-items: center; gap: 10px; }
.key i { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.9); box-shadow: 0 2px 6px rgba(0,0,0,.5); }
@media (max-width: 720px) {
  .key { gap: 10px 18px; font-size: 15px; }
}
.key .k-on i { background: var(--on); }
.key .k-off i { background: var(--unknown); }
.key .k-fault i { background: var(--fault); }
.key .k-unknown i { background: var(--off); }
article.fan.flash { box-shadow: 0 0 0 3px var(--dusk), var(--shadow); }
@media (max-width: 720px) {
  .marker .tag { display: none; }
  .marker { transform: translate(-15px, -50%); }
  .marker .pin { width: 30px; height: 30px; font-size: 14px; }
}
