:root {
  color-scheme: dark;
  --bg: #101827;
  --panel: #162236;
  --panel-2: #1b2a42;
  --line: #2c3c56;
  --line-strong: #3d516f;
  --text: #eef4ff;
  --muted: #9fb0c9;
  --soft: #c6d3e6;
  --good: #46d38a;
  --warn: #f2c15d;
  --bad: #ff6978;
  --accent: #72a7ff;
  --accent-strong: #24508f;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --sidebar-width: 220px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  padding: 18px;
}

button,
input,
select,
textarea,
table {
  font: inherit;
}

button,
input,
select,
textarea {
  min-height: 36px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #111c2d;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:disabled,
select:disabled,
textarea:disabled {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(148, 163, 184, 0.16);
  color: rgba(229, 238, 255, 0.58);
  cursor: not-allowed;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  min-height: 118px;
  resize: vertical;
  outline: none;
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

label.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--soft);
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: calc(100vh - 36px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.compatibility-panel {
  width: min(520px, 100%);
}

.compatibility-message {
  margin: 12px 0 0;
  color: var(--soft);
  font-size: 14px;
  line-height: 1.45;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.logo {
  width: 136px;
  max-width: 38vw;
  height: auto;
  display: block;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.subhead {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.form-grid,
.stack {
  display: grid;
  gap: 11px;
}

.form-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.toolbar-spread {
  justify-content: space-between;
}

.status-toolbar,
.stack-section {
  margin-top: 12px;
}

.status-toolbar {
  margin-top: 0;
  margin-bottom: 12px;
}

.button {
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  white-space: nowrap;
}

.button.primary {
  border-color: #8bb8ff;
  background: var(--accent-strong);
}

.button.danger {
  border-color: rgba(255, 105, 120, 0.7);
  background: rgba(255, 105, 120, 0.12);
  color: #ffd9de;
}

.button:hover {
  border-color: var(--accent);
  color: #ffffff;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  width: 100%;
  min-height: calc(100vh - 36px);
  padding-left: calc(var(--sidebar-width) + 14px);
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto 14px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.topbar-notice-slot {
  position: relative;
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.identity {
  justify-self: end;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.layout {
  display: block;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow-x: hidden;
  overflow-y: auto;
  padding-top: 18px;
}

.nav-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--soft);
  padding: 10px 13px;
  text-align: left;
  cursor: pointer;
}

.nav-button.active {
  background: var(--panel-2);
  color: #ffffff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-button:hover {
  background: rgba(255, 255, 255, 0.04);
}

.event-nav-item {
  border-bottom: 1px solid var(--line);
}

.event-nav-item > .nav-button {
  border-bottom: 0;
}

.event-subnav {
  display: grid;
  padding: 0 0 6px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.event-subnav-button {
  width: 100%;
  min-height: 30px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  text-align: left;
  cursor: pointer;
}

.event-subnav-button:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--soft);
}

.event-subnav-button.active {
  border-left-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.takeover-subnav {
  display: grid;
  padding-left: 14px;
}

.takeover-subnav-button {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}

.takeover-subnav-button:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--soft);
}

.takeover-subnav-button.active {
  border-left-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-management {
  margin-top: auto;
  border-top: 1px solid var(--line);
}

.nav-management .nav-button:last-child {
  border-bottom: 0;
}

.nav-footer {
  padding: 10px;
  border-top: 1px solid var(--line);
}

.nav-footer .button {
  width: 100%;
}

.content {
  display: grid;
  gap: 12px;
  min-width: 0;
  max-width: 1320px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 13px 14px;
  min-height: 86px;
}

.section {
  overflow: hidden;
}

.section.control-disabled {
  opacity: 0.48;
}

.section.control-disabled .section-header,
.section.control-disabled .section-body {
  color: var(--muted);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.section-body {
  padding: 14px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.54);
}

.modal-overlay.hidden {
  display: none;
}

.connection-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 13, 22, 0.68);
  backdrop-filter: grayscale(1);
}

.connection-overlay.hidden {
  display: none;
}

.connection-modal {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}

.connection-modal h2 {
  margin: 0;
}

.connection-modal p {
  margin: 10px 0 0;
  color: var(--soft);
  line-height: 1.45;
}

.modal-panel {
  width: min(460px, 100%);
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-confirm-body {
  display: grid;
  gap: 10px;
}

.modal-device-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.modal-device-list li {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(17, 28, 45, 0.72);
  padding: 7px 9px;
  color: var(--soft);
}

.generation-modal-panel {
  width: min(380px, 100%);
}

.generation-modal-body {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--soft);
}

.generation-spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: generation-spin 0.8s linear infinite;
}

@keyframes generation-spin {
  to {
    transform: rotate(360deg);
  }
}

.placeholder-body {
  min-height: 220px;
}

.label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.value {
  margin-top: 7px;
  font-size: 20px;
  line-height: 1.15;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.detail,
.muted {
  color: var(--soft);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.detail {
  margin-top: 4px;
}

.no-margin {
  margin: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--soft);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.ok .dot,
.reachable {
  background: var(--good);
}

.warn .dot {
  background: var(--warn);
}

.bad .dot,
.unreachable {
  background: var(--bad);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.015);
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.status-cell {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.error,
.notice {
  display: none;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.error {
  border: 1px solid rgba(255, 105, 120, 0.65);
  background: rgba(255, 105, 120, 0.1);
  color: #ffd9de;
}

.notice {
  border: 1px solid rgba(70, 211, 138, 0.5);
  background: rgba(70, 211, 138, 0.09);
  color: #d9ffe9;
}

.topbar-notice-slot .error,
.topbar-notice-slot .notice {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  display: block;
  width: max-content;
  max-width: min(520px, 100%);
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, calc(-50% - 4px));
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.topbar-notice-slot .error {
  z-index: 3;
}

.topbar-notice-slot .error.visible,
.topbar-notice-slot .notice.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%);
}

.error.visible,
.notice.visible {
  display: block;
}

.empty {
  padding: 18px 14px;
  color: var(--muted);
  font-size: 13px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 12px;
  align-items: start;
}

.split > .section {
  min-width: 0;
}

.inline-actions {
  display: inline-flex;
  gap: 7px;
}

.action-column {
  text-align: right;
}

.action-column .inline-actions {
  justify-content: flex-end;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.takeover-thumbnail,
.message-list-preview,
.message-preview {
  background: var(--good);
}

.takeover-thumbnail {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
}

.takeover-thumbnail.offline {
  display: grid;
  place-items: center;
  background: #5e6878;
  color: #eef4ff;
  font-size: 30px;
  font-weight: 800;
}

.takeover-thumbnail img,
.message-list-preview img,
.message-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.takeover-device-name,
.message-list-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.takeover-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.takeover-status-label {
  color: var(--muted);
}

.takeover-status-value.ok {
  color: var(--soft);
}

.takeover-status-value.bad {
  color: #ff6b78;
}

.takeover-mode.ready {
  color: var(--good);
}

.takeover-mode.takeover {
  color: var(--warn);
}

.takeover-mode.queued {
  color: var(--bad);
}

.takeover-mode {
  font-weight: 700;
}

.messaging-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.message-list-pane {
  display: grid;
  gap: 10px;
}

.message-list-pane .button {
  justify-self: stretch;
}

.message-list {
  display: grid;
  gap: 8px;
}

.message-editor-lock {
  border: 1px solid rgba(255, 206, 84, 0.55);
  border-radius: 6px;
  background: rgba(255, 206, 84, 0.13);
  color: #ffe8a3;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.message-list-item {
  width: 100%;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(17, 28, 45, 0.72);
  color: var(--text);
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.message-list-item.active,
.message-list-item:hover {
  border-color: var(--accent);
  background: rgba(114, 167, 255, 0.12);
}

.message-list-preview {
  width: 64px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
}

.message-editor-shell {
  min-width: 0;
}

.message-preview {
  width: min(360px, 100%);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  color: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.color-picker {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 7px;
}

.color-picker legend {
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.color-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(17, 28, 45, 0.86);
  color: var(--soft);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.color-swatch span {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18);
}

.color-swatch[data-color="black"] span {
  background: #000000;
}

.color-swatch[data-color="white"] span {
  background: #e8e8e8;
}

.color-swatch[data-color="red"] span {
  background: #aa1230;
}

.color-swatch[data-color="yellow"] span {
  background: #d6ba00;
}

.color-swatch[data-color="purple"] span {
  background: #4e2070;
}

.color-swatch.active {
  border-color: var(--accent);
  background: rgba(114, 167, 255, 0.14);
  color: #ffffff;
}

.color-swatch.active span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.color-swatch:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.audio-preview {
  min-height: 0;
  display: grid;
  gap: 3px;
  align-content: start;
  align-items: start;
}

.audio-preview-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.audio-preview-row .audio-preview {
  flex: 1 1 280px;
}

.audio-preview-heading {
  margin: 0;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
}

.audio-preview audio {
  display: block;
  width: min(420px, 100%);
  height: 32px;
}

.takeover-device-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 160px));
  gap: 12px;
  align-items: stretch;
  justify-content: start;
  overflow-x: hidden;
}

.takeover-device-row {
  width: 100%;
  min-width: 0;
  min-height: 204px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(17, 28, 45, 0.72);
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.takeover-device-row:hover {
  border-color: var(--accent);
  color: var(--soft);
}

.takeover-device-row.selected {
  border-color: rgba(70, 211, 138, 0.82);
  background: rgba(70, 211, 138, 0.13);
  color: #d9ffe9;
}

.takeover-device-name {
  min-width: 0;
  min-height: 34px;
  display: grid;
  gap: 3px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.takeover-device-id {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.takeover-device-row .takeover-thumbnail {
  width: min(136px, 100%);
  align-self: center;
  border-radius: 5px;
}

.takeover-device-row .takeover-status {
  min-width: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

.takeover-device-row .takeover-status-value,
.takeover-device-row .takeover-mode {
  text-align: right;
}

.takeover-control-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.control-message-list {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.selectable-row {
  cursor: pointer;
}

.selectable-row:hover td,
.selectable-row.selected td {
  background: rgba(114, 167, 255, 0.1);
}

.capability-list {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.capability {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--soft);
  font-size: 12px;
}

@media (max-width: 980px) {
  .split {
    grid-template-columns: 1fr;
  }

  .messaging-layout {
    grid-template-columns: 1fr;
  }

  .takeover-device-list {
    grid-template-columns: repeat(auto-fill, minmax(144px, 144px));
  }

  .takeover-device-row {
    min-height: 188px;
  }

  .takeover-device-row .takeover-thumbnail {
    width: min(120px, 100%);
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  body {
    padding: 12px;
  }

  .app-shell {
    min-height: calc(100vh - 24px);
    padding-left: 0;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding-top: 0;
  }

  .nav-button {
    border-right: 1px solid var(--line);
  }

  .nav-footer {
    padding: 0;
    border-top: 0;
  }

  .nav-management {
    margin-top: 0;
    border-top: 0;
  }

  .brand,
  .login-brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .identity {
    justify-self: start;
    text-align: left;
  }

  .sidebar,
  .grid,
  .takeover-device-list,
  .option-grid {
    grid-template-columns: 1fr;
  }
}
