:root {
  --bg0: #070b14;
  --bg1: #101a2e;
  --card: rgba(18, 28, 48, 0.72);
  --line: rgba(120, 160, 220, 0.18);
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #5eb1ff;
  --ok: #3dbe7a;
  --danger: #e85d5d;
  --warn: #e0b34d;
  --radius: 18px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Outfit", var(--font);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(70, 120, 220, 0.28), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(40, 180, 160, 0.12), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 55%, #0a1220);
  background-attachment: fixed;
}
button, input { font: inherit; }
a { color: var(--accent); }

#app { min-height: 100vh; }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px 24px;
  border-radius: calc(var(--radius) + 4px);
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.brand {
  font-family: var(--display);
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}
.brand span { color: var(--accent); }
.sub { color: var(--muted); margin: 0 0 22px; font-size: 0.95rem; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin: 12px 0 6px; }
input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  outline: none;
}
input:focus { border-color: rgba(94,177,255,0.55); }
.pw-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.pw-row input { flex: 1; }
.pw-toggle {
  flex: 0 0 auto;
  min-width: 64px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pw-toggle:hover {
  border-color: rgba(94,177,255,0.45);
  background: rgba(94,177,255,0.1);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--accent);
  color: #041018;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled,
.btn-off {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.55);
  background: #4a5568 !important;
  color: #c5ccd6 !important;
}
.btn-chip.btn-off {
  background: rgba(80, 90, 110, 0.45) !important;
  color: #9aa6b8 !important;
}
.btn-block { width: 100%; margin-top: 16px; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-chip {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
}
.btn-active { outline: 2px solid var(--accent); }
.err { color: var(--danger); font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 14px; text-align: center; }
.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { flex: 1; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(7, 11, 20, 0.75);
}
.top h1 {
  font-family: var(--display);
  font-size: 1.35rem;
  margin: 0;
}
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.shell { padding: 18px; max-width: 1100px; margin: 0 auto; }
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
}
.pill.ok { color: var(--ok); }
.pill.wait { color: var(--warn); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.device-box {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  padding: 14px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  min-height: 120px;
  text-align: left;
  color: inherit;
  width: 100%;
}
.device-box:hover {
  border-color: rgba(94,177,255,0.45);
  transform: translateY(-2px);
}
.device-box .name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.98rem;
  margin-bottom: 8px;
  word-break: break-word;
}
.device-box .id {
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-all;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block; background: #667;
  margin-right: 6px;
}
.dot.on { background: var(--ok); box-shadow: 0 0 10px rgba(61,190,122,0.5); }

.room { display: grid; gap: 14px; }
.room-top {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
}
.stage {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #05080f;
  min-height: min(52vh, 420px);
  overflow: hidden;
}
.stage video {
  width: 100%;
  height: min(52vh, 420px);
  object-fit: contain;
  background: #000;
}
.placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}
.controls {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.status-line {
  color: var(--muted);
  font-size: 0.88rem;
  min-height: 1.3em;
}

.gallery-host {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 14px;
  animation: fadeIn 0.18s ease;
}
.gallery-panel {
  width: min(960px, 100%);
  height: min(860px, 92vh);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: linear-gradient(165deg, #121c32, #0c1424 60%, #0a101c);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.5);
  animation: fadeUp 0.22s ease;
}
.gallery-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.gallery-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
}
.gallery-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
  max-width: 48vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-top-actions { display: flex; gap: 8px; flex-shrink: 0; }
.gallery-body {
  overflow: auto;
  padding: 14px 16px 18px;
}
.gallery-meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 12px;
}
.gallery-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 220px;
  color: var(--muted);
  font-size: 0.92rem;
}
.g-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(94, 177, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.gallery-empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 18px;
  line-height: 1.5;
}
.gallery-empty-title {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.gallery-empty p { margin: 0; font-size: 0.9rem; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}
.gallery-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  color: inherit;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  min-width: 0;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.gallery-card:hover {
  border-color: rgba(94, 177, 255, 0.45);
  transform: translateY(-1px);
}
.gallery-folder .gallery-thumb-folder {
  color: var(--accent);
  background:
    radial-gradient(circle at 30% 30%, rgba(94, 177, 255, 0.18), transparent 55%),
    #0a1020;
}
.gallery-folder-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.gallery-folder-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-thumb-wrap {
  position: relative;
  width: 100%;
}
.gallery-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #0a1020;
}
.gallery-thumb-folder {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.gallery-skel {
  background:
    linear-gradient(110deg, #0a1020 25%, #152238 45%, #0a1020 65%);
  background-size: 200% 100%;
  animation: shimmer 1.1s ease infinite;
}
@keyframes shimmer {
  to { background-position: -200% 0; }
}
.gallery-badge {
  position: absolute;
  left: 7px;
  top: 7px;
  z-index: 2;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 7px;
  border-radius: 6px;
  color: #fff;
  background: rgba(20, 24, 32, 0.72);
  pointer-events: none;
}
.gallery-badge.photo {
  color: #041018;
  background: rgba(94, 177, 255, 0.92);
}
.gallery-badge.video {
  color: #fff;
  background: rgba(220, 60, 70, 0.92);
}
.gallery-more {
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
}
.gallery-play {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.3);
  pointer-events: none;
}
.gallery-play::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 7px;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent #fff;
}
.gallery-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 10px;
  min-width: 0;
}
.gallery-card-meta .g-name {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-card-meta .g-sub {
  color: var(--muted);
  font-size: 0.7rem;
}

.viewer-host {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(0, 0, 0, 0.82);
  display: grid;
  place-items: center;
  padding: 12px;
}
.viewer-host[hidden] { display: none !important; }
.viewer-panel {
  width: min(920px, 100%);
  height: min(860px, 92vh);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #0a101c;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
}
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.viewer-name {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.viewer-kind {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 6px;
  text-transform: uppercase;
}
.viewer-kind.photo {
  color: #041018;
  background: rgba(94, 177, 255, 0.92);
}
.viewer-kind.video {
  color: #fff;
  background: rgba(220, 60, 70, 0.92);
}
.viewer-count { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }
.viewer-stage {
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
  min-height: 0;
}
.viewer-media {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.viewer-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 22px;
  border-radius: calc(var(--radius) + 2px);
  border: 1px dashed rgba(120, 160, 220, 0.28);
  background:
    linear-gradient(160deg, rgba(30, 48, 78, 0.45), rgba(12, 18, 32, 0.55));
  animation: fadeUp 0.35s ease;
}
.empty-state.compact { padding: 22px 16px; }
.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background:
    radial-gradient(circle at 30% 30%, rgba(94,177,255,0.55), transparent 55%),
    rgba(94,177,255,0.12);
  border: 1px solid rgba(94,177,255,0.25);
}
.empty-title {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.empty-text {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  max-width: 420px;
  margin: 0 auto 10px;
}
.empty-note {
  color: var(--accent);
  font-size: 0.88rem;
  margin: 0 0 8px;
}
.empty-slots {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.modal-host {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 8, 16, 0.62);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}
.modal-card {
  width: min(400px, 100%);
  padding: 22px 20px;
  border-radius: calc(var(--radius) + 2px);
  background: #101a2e;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  animation: fadeUp 0.22s ease;
}
.modal-card h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  margin: 0 0 8px;
}
.modal-sub {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0 0 16px;
}
.feat-list { display: grid; gap: 10px; margin-bottom: 16px; }
.feat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  cursor: pointer;
}
.feat-row strong { display: block; font-size: 0.95rem; }
.feat-row small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.feat-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .brand { font-size: 1.8rem; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .gallery-panel,
  .viewer-panel { height: 96vh; height: 96dvh; border-radius: 14px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .gallery-sub { max-width: 40vw; }
}
