/* Savvy Domus account pages — minimal shared styling. */
:root {
  --bg: #0f1117;
  --card: #171a22;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8a92a6;
  --accent: #4f7cff;
  --accent-hover: #3d68e6;
  --danger: #ff5c5c;
  --ok: #3ecf8e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Dashboard: pin to the top of the page (still horizontally centered),
   instead of floating vertically centered like the small auth forms. */
body.dash { align-items: flex-start; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.card.wide { max-width: 1040px; }

h1 { font-size: 22px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

input {
  width: 100%;
  padding: 11px 12px;
  background: #0f1218;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}
input:focus { outline: none; border-color: var(--accent); }

select {
  width: 100%;
  padding: 11px 12px;
  background: #0f1218;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}
select:focus { outline: none; border-color: var(--accent); }

/* Inline add-row (e.g. New room): input + buttons on one line */
.inline-form { display: flex; gap: 8px; margin: 12px 0; align-items: center; }
.inline-form input { margin: 0; }

button {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.link { color: var(--accent); text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Breadcrumb header (← Dashboard / Rooms) — each segment is a .link */
.crumbs { font-size: 14px; }
.crumb-sep { color: var(--muted); margin: 0 2px; }

.foot { margin-top: 20px; font-size: 14px; color: var(--muted); text-align: center; }

.msg { margin-top: 16px; padding: 10px 12px; border-radius: 8px; font-size: 14px; display: none; }
.msg.error { display: block; background: rgba(255,92,92,0.12); color: var(--danger); }
.msg.ok    { display: block; background: rgba(62,207,142,0.12); color: var(--ok); }

.code-input { letter-spacing: 8px; text-align: center; font-size: 24px; }

table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; }
.badge.admin { background: rgba(79,124,255,0.15); color: var(--accent); }
.badge.user  { background: rgba(138,146,166,0.15); color: var(--muted); }
.row-actions button { width: auto; margin: 0; padding: 6px 12px; font-size: 13px; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.topbar button { width: auto; margin: 0; padding: 8px 14px; font-size: 13px; }
.profile { margin-top: 8px; line-height: 1.7; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 32px; }
.profile b { color: var(--muted); font-weight: 500; display: inline-block; width: 90px; }
@media (max-width: 560px) { .profile { grid-template-columns: 1fr; } }

/* Controllers: select checkboxes + version markers */
.cbcell { width: 30px; text-align: center; }
#ctlAll, .ctlpick { width: auto; margin: 0; vertical-align: middle; cursor: pointer; }
.upd-avail { color: #fbbf24; font-weight: 700; cursor: default; }
.upd-now { color: var(--accent); font-weight: 600; }

/* Controller status dots */
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot.online  { background: var(--ok);   box-shadow: 0 0 6px var(--ok); }
.dot.offline { background: var(--danger); }
.dot.provisioning { background: var(--ok); animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.muted { color: var(--muted); }
.refresh-note { color: var(--muted); font-size: 12px; margin-top: 14px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 24px 0 4px; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; width: auto; margin: 0; border-radius: 0;
}
.tab:hover { color: var(--text); background: transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }

/* Clients tab: panel header + action button */
.panel-head { display: flex; justify-content: flex-end; margin-top: 16px; }

/* Controllers tab filter bar (search + version/device dropdowns) */
.filter-bar { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.filter-bar input { flex: 1 1 220px; min-width: 180px; }
.filter-bar select { flex: 0 0 auto; width: auto; min-width: 150px; }
@media (max-width: 560px) { .filter-bar input, .filter-bar select { flex: 1 1 100%; width: 100%; } }
button.action {
  width: auto; margin: 0; padding: 9px 14px; font-size: 13px; font-weight: 600;
}
.req { color: var(--danger); }

/* Modal (new-client form) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 24px; z-index: 50; overflow-y: auto;
}
.card.modal { max-width: 440px; }
.card.modal h1 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { margin-top: 18px; }

/* Searchable controller picker (combobox) */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  max-height: 220px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.combo-item {
  padding: 10px 12px; cursor: pointer; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.combo-item:hover { background: #1b1f29; }
.combo-sub { color: var(--muted); font-size: 12px; }
.combo-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

/* Per-controller device detail (cloud devices view) */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #1b1f29; }

/* ===== Dashboard app shell (left sidebar layout) ===== */
body.app { display: block; align-items: stretch; justify-content: flex-start; padding: 0; }
.shell { display: flex; min-height: 100vh; align-items: stretch; }

/* Column 1 — persistent dark sidebar (Users / Controllers / Clients) */
.sidebar {
  flex: 0 0 236px; width: 236px; background: #20242f; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .who { text-align: center; padding: 28px 16px 22px; border-bottom: 1px solid var(--border); }
.sidebar .avatar {
  width: 64px; height: 64px; border-radius: 50%; background: #2b3040; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.sidebar .who .nm { font-weight: 600; font-size: 15px; letter-spacing: .3px; }
.sidebar .who .sub { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-top: 3px; }
.nav { display: flex; flex-direction: column; padding: 14px 0; flex: 1; gap: 2px; }
.nav .item {
  display: flex; align-items: center; gap: 13px; padding: 13px 24px; color: var(--muted);
  cursor: pointer; font-size: 14px; font-weight: 500; border: none; background: none;
  width: 100%; text-align: left; border-radius: 0; margin: 0;
}
.nav .item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav .item.active { color: #fff; background: var(--accent); }
.nav .item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.sidebar .foot { padding: 16px 20px; border-top: 1px solid var(--border); }
.sidebar .foot button { width: 100%; margin: 0; }

/* Content area. List views (Users/Controllers/Clients) are simple padded
   panels; the drill-down lays out a details header band on top, then a
   devices column (D) + device-details column (DD) below it. */
.content { flex: 1; min-width: 0; padding: 0; }
.content .page-title { font-size: 20px; margin: 0 0 6px; }
.content .page-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.cpanel { display: none; }
.cpanel.active { display: block; }
#panel-users, #panel-controllers, #panel-clients { padding: 26px 30px; }
.back-link { color: var(--accent); cursor: pointer; font-size: 13px; display: inline-block; margin-bottom: 12px; }

/* Z — controller/client details header band (spans the content width) */
.drill-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
  padding: 20px 30px; border-bottom: 1px solid var(--border);
}
.drill-head .dh-title { font-size: 18px; font-weight: 600; }
.drill-head .dh-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.drill-head .dh-meta { color: var(--muted); font-size: 13px; margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px 22px; }
.drill-head .dh-meta b { color: var(--text); font-weight: 500; }
.drill-head .dh-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.drill-head .dh-actions button {
  width: auto; margin: 0; padding: 7px 16px; font-size: 13px; font-weight: 600; border-radius: 8px;
  background: transparent; border: 1px solid var(--border); color: var(--muted); cursor: pointer;
}
.drill-head .dh-actions button:hover { color: var(--text); }
.drill-head .dh-actions button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Cascading columns below the header band: nav columns (devices/rooms/cats)
   + a wider detail column on the right. */
.drill-body { display: flex; align-items: stretch; }
.drill-col { flex: 0 0 268px; border-right: 1px solid var(--border); min-height: 62vh; overflow-y: auto; }
.drill-col.narrow { flex-basis: 180px; }
.drill-col .sub-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; padding: 14px 18px 4px; }
.drill-col .sub-label-row { display: flex; align-items: center; justify-content: space-between; }
.add-icon {
  width: auto; margin: 0; padding: 0 4px; line-height: 1; font-size: 20px; font-weight: 700;
  background: transparent; border: none; color: var(--accent); cursor: pointer;
}
.add-icon:hover { color: var(--accent-hover); }
.drill-col table { margin: 0; }
.drill-col tr.clickable td { border-bottom: 1px solid var(--border); }
.drill-col tr.active td { background: rgba(79,124,255,0.12); }
.drill-col .navrow {
  display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; cursor: pointer;
  border-bottom: 1px solid var(--border); color: var(--text); font-size: 14px; font-weight: 500;
}
.drill-col .navrow:hover { background: #1b1f29; }
.drill-col .navrow.active { background: rgba(79,124,255,0.12); color: var(--accent); }
.drill-col .inline-form { margin: 0; padding: 10px 14px 6px; }
.drill-col .inline-form input { font-size: 13px; padding: 8px 10px; }
.drill-col .inline-form .action { padding: 8px 12px; }
.drill-detail { flex: 1; min-width: 0; padding: 22px 26px; }
.drill-detail .placeholder { color: var(--muted); padding: 28px 4px; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { flex-basis: auto; width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .drill-body { flex-direction: column; }
  .drill-col { flex-basis: auto; border-right: none; border-bottom: 1px solid var(--border); min-height: 0; }
}

/* Device row item — shared with the on-device LAN dashboard (see deviceRowHtml). */
.name { font-size: 15px; font-weight: 600; }
.name .chev { float: right; color: #5a616e; }
.dev-sub { font-size: 12.5px; margin-top: 3px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; }
.pill-ok { background: rgba(62,207,142,.15); color: var(--ok); }
.pill-no { background: rgba(138,146,166,.15); color: var(--muted); }
.det-state { font-size: 15px; }
.st-on { color: var(--ok); font-weight: 700; } .st-off { color: var(--muted); font-weight: 700; }
.kv { color: var(--muted); font-size: 13px; margin: 4px 0; }
.kv b { color: var(--text); font-weight: 500; }
.btnrow { display: flex; gap: 10px; margin-top: 16px; }
.btn { flex: 1; padding: 13px; border: 1px solid var(--border); border-radius: 10px;
       background: #1b1f29; color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; }
.btn.on  { background: rgba(62,207,142,.12); color: var(--ok); border-color: #1c5235; }
.btn.off { background: rgba(255,92,92,.12); color: var(--danger); border-color: #4a1c1c; }
