:root {
  color-scheme: dark;
  --bg: #0f131a;
  --panel: #171d27;
  --border: #283244;
  --text: #e6edf7;
  --muted: #93a1b5;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

.hidden, .hidden-pane {
  display: none !important;
}

.login-overlay {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.subtitle {
  margin: -6px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-card input {
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

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

.login-error {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: #fca5a5;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.device-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn, .top-btn, .icon-btn, .nav-btn {
  background: #212a38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.top-btn.danger, .icon-btn.danger {
  color: #fecaca;
  border-color: #7f1d1d;
}

.topbar-actions {
  display: flex;
  gap: 6px;
}

.device-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}

.device-grid.single-mode {
  grid-template-columns: 1fr;
  justify-items: center;
}

.device-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
  width: 100%;
}

.device-card.focused-pane {
  max-width: 540px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.card-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.card-title-wrap h2 {
  margin: 0;
  font-size: 14px;
  white-space: nowrap;
}

.status-badge, .decoder-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #283244;
}

.status-badge.online { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.status-badge.booting { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.status-badge.offline { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.card-actions {
  display: flex;
  gap: 4px;
}

.card-metrics {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 10px;
  background: #121720;
  border-bottom: 1px solid var(--border);
}

.screen-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070b;
  overflow: hidden;
  padding: 4px;
}

.device-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.text-bar {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  background: #121720;
}

.text-bar input {
  flex: 1;
  min-width: 0;
  background: #0b0e14;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.text-bar button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.nav-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px 8px;
  background: #141a24;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  background: #1f2937;
  border: 1px solid var(--border);
  z-index: 9999;
}

.toast.error {
  background: #7f1d1d;
  border-color: #ef4444;
}

@media (min-width: 1024px) {
  .device-tabs {
    display: none;
  }
  .app-shell.single-mode .device-tabs {
    display: flex;
  }
}

@media (max-width: 1023px) {
  .brand {
    display: none;
  }
  .device-grid {
    padding: 4px;
  }
  .device-card.focused-pane {
    max-width: 100%;
  }
}
