:root { color-scheme: dark; }
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, #1b2735, #090a0f 70%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #e8ecf1;
}

/* -- Sign-in card (also used for small info states) ------------------------- */
.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.card {
  width: 100%; max-width: 380px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px; padding: 32px;
}
.card h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
.card p.tagline { color: #aab4c0; margin: 0 0 24px; font-size: 0.95rem; }
label { display: block; font-size: 0.85rem; color: #aab4c0; margin-bottom: 6px; }
input, select {
  width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 10px 12px; color: #e8ecf1; font-size: 1rem; margin-bottom: 16px;
}
input:focus, select:focus { outline: 2px solid #3fa9f5; border-color: transparent; }
input[type=color] { padding: 3px; height: 42px; cursor: pointer; }
button {
  padding: 11px 16px; border-radius: 8px; border: none; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; margin-bottom: 10px; font-family: inherit;
}
button.primary { background: #3fa9f5; color: #06131f; }
button.secondary { background: rgba(255,255,255,0.08); color: #e8ecf1; border: 1px solid rgba(255,255,255,0.15); }
button.danger { background: rgba(240,90,90,0.15); color: #f5a3a3; border: 1px solid rgba(240,90,90,0.3); }
button.link { background: none; color: #8fbfe8; font-weight: 400; text-decoration: underline; padding: 4px; }
button:disabled { opacity: 0.5; cursor: default; }
.divider { display: flex; align-items: center; gap: 10px; color: #5a6472; font-size: 0.8rem; margin: 6px 0 16px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,0.1); }
.msg { font-size: 0.85rem; padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; }
.msg.error { background: rgba(240,90,90,0.12); color: #f5a3a3; border: 1px solid rgba(240,90,90,0.3); }
.msg.ok { background: rgba(143,211,163,0.1); color: #8fd3a3; border: 1px solid rgba(143,211,163,0.25); }
.hidden { display: none !important; }

/* -- Dashboard shell ---------------------------------------------------------- */
#dashboard { max-width: 1100px; margin: 0 auto; padding: 20px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.25rem; margin: 0; }
.topbar .spacer { flex: 1; }
.topbar button { margin-bottom: 0; }
.conn-status { font-size: 0.75rem; color: #5a6472; display: flex; align-items: center; gap: 6px; }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: #5a6472; }
.conn-status.live .conn-dot { background: #8fd3a3; }
.conn-status.polling .conn-dot { background: #e0b24a; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  gap: 12px;
}
@media (max-width: 700px) { .grid { grid-template-columns: repeat(2, 1fr); } }

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 10px; text-align: center;
  cursor: pointer; user-select: none;
  transition: transform 0.1s ease;
  border: 1px solid rgba(255,255,255,0.08);
}
.tile:active { transform: scale(0.96); }
.tile .icon { opacity: 0.95; }
.tile .label { font-size: 0.78rem; font-weight: 600; line-height: 1.2; }
.tile .sublabel { font-size: 0.68rem; opacity: 0.75; }
.tile.add-tile { background: rgba(255,255,255,0.03); border: 1px dashed rgba(255,255,255,0.25); color: #aab4c0; }

.tile.edit-mode { cursor: grab; }
.tile.edit-mode.dragging { opacity: 0.4; }
.tile-edit-btn {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.35); border: none; color: #fff; font-size: 13px; display: flex;
  align-items: center; justify-content: center; cursor: pointer; margin: 0; padding: 0;
}

/* -- Modal ------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center;
  justify-content: center; padding: 20px; z-index: 50;
}
.modal { width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto; }
.modal h2 { font-size: 1.1rem; margin: 0 0 16px; }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 16px; }
.icon-choice {
  aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.05); border: 1px solid transparent; cursor: pointer; color: #e8ecf1;
}
.icon-choice.selected { border-color: #3fa9f5; background: rgba(63,169,245,0.15); }
.color-row { display: flex; gap: 12px; }
.color-row > div { flex: 1; }
.attr-list { list-style: none; padding: 0; margin: 0 0 16px; font-size: 0.85rem; }
.attr-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.attr-list li span:first-child { color: #aab4c0; }
