:root {
  --bg: #f4f5f7;
  --bg-soft: #eceef2;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #111827;
  --primary-hover: #000000;
  --primary-soft: #f3f4f6;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --warn: #a16207;
  --warn-soft: #fffbeb;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 8px 24px rgba(17, 24, 39, 0.04);
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --topbar-h: 56px;
  --max: 880px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
pre {
  font: inherit;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.screen {
  min-height: 100vh;
}

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

.small {
  font-size: 0.875rem;
}

.center {
  text-align: center;
}

.error {
  color: var(--danger);
  min-height: 1.15rem;
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.68rem 1.05rem;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  line-height: 1.2;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--line-strong);
}

.btn.secondary:hover:not(:disabled) {
  background: var(--primary-soft);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--text);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.btn.danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn.full {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  align-items: center;
}

.btn-row.wrap {
  flex-wrap: wrap;
}

.btn-row.spaced {
  margin-top: 0.9rem;
}

.field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.78rem 0.95rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field:focus {
  outline: none;
  border-color: #9ca3af;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08);
}

.field.narrow {
  width: 84px;
  flex: 0 0 auto;
}

.file-btn {
  display: inline-flex;
  cursor: pointer;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}

.pill.soft {
  background: var(--bg-soft);
  color: var(--muted);
}

.pill.live {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}

.brand.compact {
  gap: 0.55rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--text);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark.sm {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 0.15rem 0 0;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
}

#login-view {
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 70% 45% at 50% -5%, rgba(37, 99, 235, 0.08), transparent 60%),
    var(--bg);
}

.login-shell {
  width: min(400px, 100%);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1.65rem 1.5rem 1.4rem;
  box-shadow: var(--shadow);
}

.login-form {
  margin-top: 1.35rem;
  display: grid;
  gap: 0.4rem;
}

.login-form label {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.login-form .btn {
  margin-top: 0.45rem;
}

.login-footer {
  margin-top: 1.2rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.55rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: var(--topbar-h);
  padding: 0.65rem 1.15rem;
  background: rgba(244, 245, 247, 0.88);
  border-bottom: 1px solid transparent;
  backdrop-filter: blur(14px);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.player {
  width: min(var(--max), calc(100% - 2rem));
  margin: 0.75rem auto 0;
  padding: 1.15rem 1.2rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: 1.4fr auto 1fr;
  gap: 1rem;
  align-items: center;
}

.player-main {
  min-width: 0;
}

.player-main h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-main .muted {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
}

.player-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.player-volume {
  display: grid;
  gap: 0.4rem;
}

.vol-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
  color: var(--muted);
}

.vol-label strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--text);
  height: 4px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: min(var(--max), calc(100% - 2rem));
  margin: 0.7rem auto 0;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.38rem 0.85rem;
  box-shadow: var(--shadow-sm);
}

.stat strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.stat span {
  color: var(--muted);
  font-size: 0.84rem;
}

.stat.warn {
  background: var(--warn-soft);
  border-color: #fde68a;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  width: min(var(--max), calc(100% - 2rem));
  margin: 0.85rem auto 0;
  padding: 0.28rem;
  background: var(--bg-soft);
  border-radius: 14px;
  position: sticky;
  top: calc(var(--topbar-h) + 2px);
  z-index: 15;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.68rem 0.5rem;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

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

.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.page {
  width: min(var(--max), 100%);
  margin: 0 auto;
  padding: 0.85rem 1rem 2.75rem;
  display: grid;
  gap: 0.85rem;
}

.tab-panel {
  display: grid;
  gap: 0.85rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 0.95rem;
}

.card-head p {
  margin: 0.2rem 0 0;
}

.card-head.stack-head {
  margin-bottom: 0.75rem;
}

.toolbar {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  margin-bottom: 0.85rem;
}

.banner strong {
  display: block;
  margin-bottom: 0.1rem;
}

.banner p {
  margin: 0;
}

.cmd-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.15rem 0 0.75rem;
}

.cmd-row .field:first-child {
  flex: 1 1 220px;
}

.simple-list,
.device-list {
  display: grid;
  gap: 0.55rem;
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.simple-list li,
.device-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  background: #fafbfc;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.simple-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.simple-list li.active {
  border-color: #cbd5e1;
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.04);
}

.item-main {
  min-width: 0;
}

.item-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.item-main span {
  color: var(--muted);
  font-size: 0.84rem;
}

.item-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.device-card.selected {
  border-color: #93c5fd;
  background: #f8fbff;
}

.device-card.outdated {
  border-color: #fbbf24;
}

.device-head {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.device-head label {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.device-head input[type="checkbox"] {
  margin-top: 0.2rem;
  width: 17px;
  height: 17px;
  accent-color: var(--text);
}

.device-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.device-more {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.5rem;
}

.device-more.hidden {
  display: none !important;
}

.inline-range {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.stack {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.stack label {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.stack .btn {
  margin-top: 0.35rem;
  justify-self: start;
}

.output {
  margin: 0.35rem 0 0.55rem;
  min-height: 150px;
  max-height: 320px;
  overflow: auto;
  padding: 0.95rem 1rem;
  border-radius: 14px;
  border: 1px solid #1f2937;
  background: #111827;
  color: #e5e7eb;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.output:empty::before {
  content: "Command output appears here.";
  color: #9ca3af;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.6rem 0.9rem;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: #fafbfc;
  grid-column: 1 / -1;
}

.simple-list li.empty {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  justify-content: initial;
  text-align: center;
  border-style: dashed;
  background: #fafbfc;
  padding: 1.8rem 1rem;
}

.simple-list li.empty strong {
  color: var(--text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 100;
  max-width: min(440px, calc(100vw - 2rem));
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--danger);
}

.toast.ok {
  background: var(--ok);
}

.simple-list li.empty {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  text-align: center;
  padding: 1.8rem 1rem;
}

.simple-list li.empty strong {
  color: var(--text);
}

@media (max-width: 820px) {
  .player {
    grid-template-columns: 1fr;
    width: auto;
    margin-left: 1rem;
    margin-right: 1rem;
  }

  .player-controls {
    justify-content: stretch;
  }

  .player-controls .btn {
    flex: 1;
  }

  .tabs,
  .stats {
    width: auto;
    margin-left: 1rem;
    margin-right: 1rem;
  }

  .tabs {
    overflow-x: auto;
  }
}

@media (max-width: 560px) {
  .card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .simple-list li {
    flex-direction: column;
    align-items: stretch;
  }

  .item-actions {
    width: 100%;
  }

  .item-actions .btn {
    flex: 1;
  }

  .banner {
    flex-direction: column;
    align-items: stretch;
  }

  .cmd-row {
    flex-direction: column;
  }

  .cmd-row .field.narrow {
    width: 100%;
  }

  .topbar {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .login-card {
    padding: 1.35rem 1.15rem 1.2rem;
  }
}
