:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel2: #1a232e;
  --border: #24303d;
  --text: #e5e9f0;
  --dim: #6b7686;
  --green: #4ade80;
  --blue: #60a5fa;
  --red: #f87171;
  --amber: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  flex: 0 0 auto;
}

.h-left { display: flex; align-items: center; gap: 10px; }
.h-left h1 { font-size: 18px; font-weight: 600; }

.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--dim);
  display: inline-block;
}
.status-dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.warn { background: var(--amber); }
.status-dot.err { background: var(--red); box-shadow: 0 0 8px var(--red); }

#status-text { font-size: 12px; color: var(--dim); }

.h-right { display: flex; align-items: center; gap: 12px; }
#last-update { font-size: 12px; color: var(--dim); }
#btn-settings {
  background: none; border: none; color: var(--dim);
  font-size: 20px; cursor: pointer; padding: 4px;
}

main { flex: 1 1 auto; overflow-y: auto; padding: 0 16px 20px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}
.card .label { font-size: 13px; color: var(--dim); }
.card .val { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.card .num { font-size: 26px; font-weight: 600; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: -0.5px; }
.card .unit { font-size: 13px; color: var(--dim); }
.card .off { font-size: 24px; color: var(--dim); font-weight: 600; }
.card .raw { font-size: 11px; color: #4b5563; font-family: ui-monospace, monospace; }
.card.status-ok .num { color: var(--green); }
.card.status-err .num { color: var(--red); }

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
canvas#chart { width: 100%; height: 260px; display: block; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal-box {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 100%; max-width: 360px;
}
.modal-box h2 { font-size: 17px; margin-bottom: 8px; }
.modal-box p { font-size: 13px; color: var(--dim); margin-bottom: 14px; line-height: 1.5; }
.modal-box input {
  width: 100%; padding: 11px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 15px; margin-bottom: 16px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 14px; cursor: pointer;
}
.modal-actions button.primary { background: var(--green); border-color: var(--green); color: #05200e; font-weight: 600; }

@media (min-width: 700px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .card .num { font-size: 32px; }
}
