/* Relay — switchboard console
   Palette: graphite field, brass signal, engraved lines.
   Type: IBM Plex Serif (wordmark moments) / Plex Sans (UI) / Plex Mono (data). */

:root {
  --bg: #10161f;
  --panel: #161e29;
  --panel-2: #1d2735;
  --panel-inset: #0b1017;
  --line: #2b3648;
  --line-soft: #222c3b;
  --text: #e9e6da;
  --muted: #8f9aab;
  --accent: #f0b429;
  --accent-strong: #ffd257;
  --accent-ink: #241a05;
  --good: #58c98b;
  --warn: #f0b429;
  --bad: #e5644e;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-display: "IBM Plex Serif", Georgia, serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(240, 180, 41, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--bad);
  min-height: 1.2em;
  margin: 4px 0 0;
  font-size: 13px;
}

.small {
  font-size: 0.82rem;
}

/* ── Brand ─────────────────────────────────────────────── */

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand.large {
  font-size: 34px;
}

.mark {
  width: 44px;
  height: 44px;
  color: var(--accent);
  flex: none;
}

.mark.small {
  width: 26px;
  height: 26px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Login ─────────────────────────────────────────────── */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 480px at 50% -20%, rgba(240, 180, 41, 0.09), transparent 65%),
    var(--bg);
}

.login-card {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 36px 34px 30px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-masthead {
  display: flex;
  align-items: center;
  gap: 16px;
}

.login-tag {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  max-width: 40ch;
}

.login-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
}

.login-rule span {
  display: block;
  height: 1px;
  flex: 1;
  background: var(--line);
}

.login-card p {
  margin: 0;
}

/* ── Forms ─────────────────────────────────────────────── */

.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stack > span,
label.stack > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

input,
textarea,
select {
  width: 100%;
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder,
textarea::placeholder {
  color: #5d6879;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.16);
}

textarea {
  resize: vertical;
  min-height: 96px;
  font-family: var(--font-mono);
  font-size: 13px;
}

button.primary,
button.ghost {
  border-radius: var(--radius);
  padding: 9px 16px;
  border: 1px solid transparent;
  font-weight: 600;
  transition: background 130ms ease, border-color 130ms ease, color 130ms ease;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover {
  background: var(--accent-strong);
}

button.primary:disabled,
button.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.wide {
  width: 100%;
  padding: 12px 16px;
}

/* ── Badges & pills ────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel-inset);
  color: var(--muted);
  padding: 4px 11px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

.badge.online {
  color: var(--good);
  border-color: rgba(88, 201, 139, 0.4);
  background: rgba(88, 201, 139, 0.09);
}

.badge.online::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px rgba(88, 201, 139, 0.7);
}

.badge.offline {
  color: var(--muted);
}

.badge.plan-pro {
  color: var(--accent-strong);
  border-color: rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.08);
}

.badge.plan-enterprise {
  color: #ffd257;
  border-color: rgba(255, 210, 87, 0.5);
  background: rgba(255, 210, 87, 0.1);
}

.count-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-strong);
  border: 1px solid var(--line);
  background: var(--panel-inset);
  border-radius: 4px;
  padding: 1px 8px;
  min-width: 30px;
  text-align: center;
}

/* ── App shell ─────────────────────────────────────────── */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 22, 31, 0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  font-family: var(--font-mono);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  flex: 1;
}

/* ── Sidebar: the device strip ─────────────────────────── */

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #0d131b;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 8px;
  border-bottom: 1px solid var(--line-soft);
}

.sidebar-head h2 {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.device-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 11px;
  transition: background 120ms ease, border-color 120ms ease;
}

.device-item:hover {
  background: var(--panel);
}

.device-item.active {
  background: var(--panel-2);
  border-color: var(--line-soft);
  border-left-color: var(--accent);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3a4556;
  flex: none;
}

.dot.online {
  background: var(--good);
  box-shadow: 0 0 8px rgba(88, 201, 139, 0.65);
}

.device-item-text {
  min-width: 0;
}

.device-item-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-item-meta {
  display: block;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.empty-note {
  padding: 8px 6px;
  font-size: 13px;
  line-height: 1.55;
}

.sidebar-note {
  margin-top: auto;
  padding: 12px 6px 2px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  line-height: 1.55;
}

/* ── Main column ───────────────────────────────────────── */

.main {
  padding: 28px 32px 64px;
  min-width: 0;
}

.empty-state {
  min-height: 62vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}

.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  margin: 10px 0 0;
}

.empty-state p {
  max-width: 46ch;
  margin: 0;
  line-height: 1.6;
}

.empty-mark {
  width: 72px;
  height: 72px;
  color: var(--line);
}

.device-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.device-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 27px;
  letter-spacing: 0.005em;
}

.device-head p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── Tabs ──────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  padding: 10px 16px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

.tab-panel {
  animation: panel-in 160ms ease;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Overview: spec sheet ──────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.detail-grid > div {
  background: var(--panel);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

code {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--accent-strong);
}

/* ── Toolbars, outputs, tables ─────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  flex-wrap: wrap;
}

.grow {
  flex: 1;
  min-width: 200px;
}

.screen-frame {
  border: 1px solid var(--line);
  background: var(--panel-inset);
  border-radius: var(--radius-lg);
  min-height: 340px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.screen-frame img {
  max-width: 100%;
  max-height: 72vh;
  display: block;
}

.output {
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 160px;
  max-height: 460px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: #cfd8c9;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 520px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  vertical-align: top;
}

.data-table tr:hover td {
  background: rgba(240, 180, 41, 0.05);
}

.link-button {
  background: none;
  border: none;
  color: var(--accent-strong);
  padding: 0;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

/* ── Admin cards ───────────────────────────────────────── */

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 0;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.card p {
  line-height: 1.55;
}

.installer-hint {
  font-size: 12px;
  line-height: 1.65;
  margin-top: 4px;
}

.installer-hint code {
  color: var(--text);
  word-break: break-word;
}

.token {
  display: block;
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  word-break: break-all;
  user-select: all;
  color: var(--accent-strong);
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
}

.user-row .user-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Modal & toast ─────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 7, 11, 0.75);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-card .device-head {
  margin-bottom: 10px;
}

.modal-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
}

.modal-card .stack {
  margin-top: 14px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: min(420px, calc(100vw - 40px));
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.toast.bad {
  border-left-color: var(--bad);
}

.toast.good {
  border-left-color: var(--good);
}

/* ── Screen tab ────────────────────────────────────────── */

.screen-select {
  width: auto;
  min-width: 160px;
  padding: 9px 12px;
}

#screen-control[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.screen-frame:fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  border: none;
  border-radius: 0;
  background: #000;
}

.screen-frame:fullscreen img {
  max-width: 100vw;
  max-height: 100vh;
}

.screen-frame img.control-enabled {
  cursor: none;
}

/* ── Top navigation (segmented) ────────────────────────── */

.topnav {
  display: flex;
  gap: 2px;
  background: var(--panel-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 3px;
}

.topnav-item {
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 16px;
  transition: background 120ms ease, color 120ms ease;
}

.topnav-item:hover {
  color: var(--text);
}

.topnav-item.active {
  background: var(--panel-2);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--line);
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
}

/* ── Sidebar search ────────────────────────────────────── */

.sidebar-search {
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

.sidebar-search input {
  padding-left: 32px;
  font-size: 13px;
}

.sidebar-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* ── Status bar (footer) ───────────────────────────────── */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 34px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  background: #0d131b;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}

.statusbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.status-item {
  white-space: nowrap;
}

.status-clock {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.status-sep {
  width: 1px;
  height: 14px;
  background: var(--line);
}

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

.conn-dot.connecting {
  background: var(--warn);
  animation: conn-pulse 1.4s ease-in-out infinite;
}

.conn-dot.live {
  background: var(--good);
  box-shadow: 0 0 7px rgba(88, 201, 139, 0.7);
}

.conn-dot.down {
  background: var(--bad);
  animation: conn-pulse 1s ease-in-out infinite;
}

@keyframes conn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (max-width: 860px) {
  .statusbar-center {
    display: none;
  }

  .topnav-item {
    padding: 6px 10px;
  }
}

/* ── Responsive ────────────────────────────────────────── */

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

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 250px;
    overflow: auto;
  }

  .sidebar-note {
    display: none;
  }

  .main {
    padding: 18px 16px 52px;
  }

  .topbar {
    padding: 0 14px;
  }

  .topbar-right {
    gap: 6px;
  }

  .user-chip {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
