:root {
  --bg-base: #090d16;
  --bg-card: #111726;
  --bg-card-hover: #162035;
  --bg-card-sub: #0d121f;
  --border-subtle: #1e283d;
  --border-active: #314264;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-emerald: #10b981;
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-violet: #8b5cf6;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* --- LOCK SCREEN / AUTH VIEW --- */
.lock-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, #151d30 0%, #080b12 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 5000;
}

.lock-card {
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: 18px;
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.25rem;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
}

.lock-icon-wrapper {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  box-shadow: 0 0 25px rgba(6, 182, 212, 0.2);
}

.lock-title {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #f8fafc, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lock-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: -0.5rem;
}

.lock-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-password-wrapper {
  position: relative;
  width: 100%;
}

.lock-input {
  width: 100%;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.85rem 3rem 0.85rem 1rem;
  font-size: 0.95rem;
  color: var(--text-main);
  outline: none;
  font-family: var(--font-mono);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.lock-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
}

.btn-eye {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.btn-eye:hover { opacity: 1; }

.lock-remember-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
}

.btn-unlock {
  width: 100%;
  background: linear-gradient(135deg, #06b6d4, #0284c7);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.85rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.35);
  min-height: 48px;
}
.btn-unlock:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.5);
}

.lock-error-msg {
  font-size: 0.8rem;
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.3);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  width: 100%;
}

/* --- MAIN APP LAYOUT --- */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1.25rem 1.75rem;
  gap: 1.25rem;
  max-width: 1920px;
  margin: 0 auto;
}

/* Header */
.hub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  flex-wrap: wrap;
  gap: 0.85rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.6rem;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid rgba(6, 182, 212, 0.4);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.logo-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(90deg, #f1f5f9, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
}

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-stopped {
  background: rgba(100, 116, 139, 0.15);
  border: 1px solid rgba(100, 116, 139, 0.3);
  color: var(--text-muted);
}
.status-stopped .pulse-dot { background: #64748b; }

.status-starting {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.status-starting .pulse-dot {
  background: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse-ring 1.5s infinite;
}

.status-running {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.status-running .pulse-dot {
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
  animation: pulse-ring 2s infinite;
}

.status-error {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fb7185;
}
.status-error .pulse-dot { background: #f43f5e; }

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.btn-header-pill {
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.45);
  color: #c4b5fd;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.btn-header-pill:hover {
  background: rgba(139, 92, 246, 0.3);
}

.key-pill, .tunnel-pill {
  display: flex;
  align-items: center;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.key-label, .tunnel-label {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.72rem;
}

#api-key-display {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.25rem;
  border-radius: 4px;
  opacity: 0.8;
  transition: opacity 0.2s, background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.btn-logout {
  color: var(--accent-rose);
  opacity: 0.9;
}

.tunnel-url {
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.tunnel-url.active {
  color: var(--accent-emerald);
  font-weight: 600;
}

.btn-toggle-tunnel {
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-toggle-tunnel:hover {
  background: rgba(59, 130, 246, 0.35);
}
.btn-toggle-tunnel.active {
  background: rgba(244, 63, 94, 0.2);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fda4af;
}

/* --- TELEMETRY GRID --- */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.15rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: border-color 0.2s;
}
.metric-card:hover {
  border-color: var(--border-active);
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.metric-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.metric-big-num {
  font-size: 1.65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.metric-big-num .unit {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
}

.metric-pill {
  font-size: 0.75rem;
  margin-left: auto;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.metric-pill.secondary {
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border-color: rgba(6, 182, 212, 0.3);
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.vram-fill { background: linear-gradient(90deg, #06b6d4, #10b981); }
.gpu-fill  { background: linear-gradient(90deg, #3b82f6, #8b5cf6); }
.ram-fill  { background: linear-gradient(90deg, #10b981, #f59e0b); }
.cpu-fill  { background: linear-gradient(90deg, #8b5cf6, #ec4899); }

.metric-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

/* --- MAIN WORKSPACE SPLIT --- */
.main-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  flex: 1;
  min-height: 0;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  min-height: 0;
}

.right-col {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  min-height: 0;
  height: 100%;
}

/* Control Banner */
.control-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  gap: 1rem;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  display: block;
}

.active-recipe-headline {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0.2rem 0 0.4rem;
  line-height: 1.3;
}

.engine-meta-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.meta-tag {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.meta-tag.online {
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.action-buttons {
  display: flex;
  gap: 0.65rem;
  flex-shrink: 0;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.4rem;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  min-height: 48px;
}

.btn-start {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}
.btn-start:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}
.btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-stop {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35);
}
.btn-stop:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(244, 63, 94, 0.5);
}
.btn-stop:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

/* Tunnel Toggle & Tags */
.meta-tag.meta-tunnel {
  background: rgba(6, 182, 212, 0.08);
  border-color: rgba(6, 182, 212, 0.25);
  color: #38bdf8;
}

.meta-tag.meta-tunnel.online {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.45);
  color: #34d399;
}

.tunnel-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
  min-height: 48px;
}

.tunnel-toggle-label:hover {
  border-color: rgba(6, 182, 212, 0.4);
  background: rgba(6, 182, 212, 0.06);
}

.tunnel-toggle-label input[type="checkbox"] {
  accent-color: #06b6d4;
  width: 17px;
  height: 17px;
  cursor: pointer;
}

/* Engine Remote Access & Tunnel Banner */
.engine-tunnel-banner {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.12), rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.15);
  animation: pulse-border 3s ease-in-out infinite alternate;
}

@keyframes pulse-border {
  0% { border-color: rgba(6, 182, 212, 0.35); box-shadow: 0 0 10px rgba(6, 182, 212, 0.1); }
  100% { border-color: rgba(16, 185, 129, 0.6); box-shadow: 0 0 18px rgba(16, 185, 129, 0.2); }
}

.tunnel-banner-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.tunnel-live-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 10px #10b981;
  animation: pulse-ring 1.8s infinite;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes pulse-ring {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; filter: drop-shadow(0 0 6px #10b981); }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.tunnel-banner-title {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #38bdf8;
  text-transform: uppercase;
}

.tunnel-banner-urls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tunnel-url-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  flex-wrap: wrap;
}

.url-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 110px;
}

.tunnel-code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #a5f3fc;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  word-break: break-all;
  flex: 1;
}

.btn-tunnel-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #e0f2fe;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 34px;
  white-space: nowrap;
}

.btn-tunnel-copy:hover {
  background: rgba(6, 182, 212, 0.3);
  border-color: #38bdf8;
  transform: translateY(-1px);
}

/* Recipes Container */
.recipes-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.recipe-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.recipe-tab {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.75rem 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  min-height: 52px;
}
.recipe-tab .tab-sub {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: 0.2rem;
}
.recipe-tab:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}
.recipe-tab.active {
  background: rgba(6, 182, 212, 0.12);
  border-color: rgba(6, 182, 212, 0.5);
  color: var(--text-main);
}
.recipe-tab.active .tab-sub {
  color: #38bdf8;
}

.recipe-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.recipe-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.recipe-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}
.recipe-card.selected {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.1);
}

.recipe-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.recipe-card-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.recipe-badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.recipe-card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.recipe-card-specs {
  display: flex;
  gap: 0.65rem;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 0.2rem;
  flex-wrap: wrap;
}

/* Test Drawer */
.test-drawer {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.test-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.latency-tag {
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.test-input-row {
  display: flex;
  gap: 0.6rem;
}

.test-input {
  flex: 1;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
  min-height: 44px;
}
.test-input:focus {
  border-color: var(--accent-cyan);
}

.btn-test {
  background: rgba(6, 182, 212, 0.2);
  border: 1px solid rgba(6, 182, 212, 0.5);
  color: #38bdf8;
  font-weight: 600;
  padding: 0 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
  min-height: 44px;
}
.btn-test:hover:not(:disabled) {
  background: rgba(6, 182, 212, 0.35);
}
.btn-test:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.test-output {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem;
  font-size: 0.82rem;
}

.output-header {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
}

.output-body {
  color: #e2e8f0;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Terminal Panel */
.terminal-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: calc(100vh - 240px);
  overflow: hidden;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.terminal-header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card-sub);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.terminal-tabs {
  display: flex;
  gap: 0.4rem;
}

.term-tab {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.term-tab.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.terminal-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.term-checkbox-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  user-select: none;
}

.btn-term-action {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}
.btn-term-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.terminal-screen {
  flex: 1 1 0px;
  min-height: 0;
  height: 0;
  background: #06090f;
  padding: 0.85rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #cbd5e1;
  overflow-y: auto !important;
  overflow-x: hidden;
  display: block;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
}

.terminal-screen::-webkit-scrollbar {
  width: 7px;
}
.terminal-screen::-webkit-scrollbar-track {
  background: #080d16;
}
.terminal-screen::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.25);
  border-radius: 4px;
  border: 1px solid #080d16;
}
.terminal-screen::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.55);
}

.terminal-line {
  display: block;
  line-height: 1.45;
  word-break: break-all;
  white-space: pre-wrap;
  margin-bottom: 2px;
}

.terminal-line.system-line { color: #38bdf8; }
.terminal-line.ready-line  { color: #34d399; font-weight: 600; }
.terminal-line.warn-line   { color: #fbbf24; }
.terminal-line.err-line    { color: #fb7185; }

/* Floating Jump to Bottom Button */
.btn-scroll-bottom {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(6, 182, 212, 0.92);
  color: #041019;
  border: none;
  border-radius: 9999px;
  padding: 0.45rem 1.15rem;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.45);
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  backdrop-filter: blur(4px);
}
.btn-scroll-bottom:hover {
  background: #38bdf8;
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.6);
}

/* Mobile Segmented Navigation Bar */
.mobile-nav-tabs {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.35rem;
  gap: 0.35rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.mobile-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
  position: relative;
}

.mobile-nav-btn .m-icon {
  font-size: 0.95rem;
}

.mobile-nav-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.mobile-nav-btn.active {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.45);
  color: #38bdf8;
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.2);
}

.mobile-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  display: none;
  box-shadow: 0 0 6px #10b981;
}
.mobile-dot.live {
  display: inline-block;
  animation: pulse-ring 1.8s infinite;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6000;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: 16px;
  padding: 1.5rem;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.modal-input {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  min-height: 44px;
}
.modal-input:focus {
  border-color: var(--accent-cyan);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-primary {
  background: var(--accent-cyan);
  color: #041019;
  font-weight: 700;
  border: none;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #1e293b;
  border: 1px solid var(--border-active);
  color: #f1f5f9;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  pointer-events: none;
  z-index: 7000;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 9999px;
}

/* --- RESPONSIVE & PORTRAIT SCREEN OPTIMIZATIONS --- */
@media (max-width: 860px), (orientation: portrait) and (max-width: 1024px) {
  .app-layout {
    padding: 0.65rem;
    gap: 0.65rem;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    box-sizing: border-box;
  }

  /* Show the mobile segmented navigation tabs */
  .mobile-nav-tabs {
    display: flex;
  }

  /* Header Compact 2-Row Layout */
  .hub-header {
    flex-direction: column;
    align-items: stretch;
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .header-left {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
  }

  .key-pill, .tunnel-pill {
    flex: 1;
    min-width: 0;
    padding: 0.25rem 0.45rem;
    font-size: 0.72rem;
  }

  #api-key-display {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tunnel-url {
    max-width: 85px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .btn-toggle-tunnel {
    padding: 0.2rem 0.45rem;
    font-size: 0.68rem;
    white-space: nowrap;
  }

  /* --- SEGMENTED TAB SWITCHING LOGIC --- */
  /* Default / Controls Tab */
  .app-layout:not([data-mobile-tab="terminal"]):not([data-mobile-tab="telemetry"]) #telemetry-section,
  .app-layout[data-mobile-tab="controls"] #telemetry-section {
    display: none !important;
  }

  .app-layout:not([data-mobile-tab="terminal"]):not([data-mobile-tab="telemetry"]) .main-split,
  .app-layout[data-mobile-tab="controls"] .main-split {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.75rem;
    padding-bottom: 1.5rem;
  }

  .app-layout:not([data-mobile-tab="terminal"]):not([data-mobile-tab="telemetry"]) #controls-section,
  .app-layout[data-mobile-tab="controls"] #controls-section {
    display: flex;
    width: 100%;
    gap: 0.75rem;
  }

  .app-layout:not([data-mobile-tab="terminal"]):not([data-mobile-tab="telemetry"]) #terminal-section,
  .app-layout[data-mobile-tab="controls"] #terminal-section {
    display: none !important;
  }

  /* Live Terminal Tab - Full Viewport Height */
  .app-layout[data-mobile-tab="terminal"] #telemetry-section {
    display: none !important;
  }

  .app-layout[data-mobile-tab="terminal"] .main-split {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    gap: 0;
  }

  .app-layout[data-mobile-tab="terminal"] #controls-section {
    display: none !important;
  }

  .app-layout[data-mobile-tab="terminal"] #terminal-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
  }

  .app-layout[data-mobile-tab="terminal"] .terminal-panel {
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 1;
  }

  .app-layout[data-mobile-tab="terminal"] .terminal-screen {
    flex: 1 1 0px !important;
    min-height: 0 !important;
    height: 0 !important;
  }

  /* Telemetry Tab */
  .app-layout[data-mobile-tab="telemetry"] #telemetry-section {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1.5rem;
  }

  .app-layout[data-mobile-tab="telemetry"] .main-split {
    display: none !important;
  }

  /* Controls Banner in Portrait */
  .control-banner {
    flex-direction: column;
    align-items: stretch;
    padding: 0.9rem 1rem;
    gap: 0.75rem;
  }

  .action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  .tunnel-toggle-label {
    grid-column: span 2;
    justify-content: center;
    min-height: 42px;
  }

  .btn-action {
    min-height: 46px;
  }

  /* Remote Banner */
  .tunnel-url-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .url-label {
    min-width: unset;
  }

  .btn-tunnel-copy {
    width: 100%;
  }

  /* Recipes Container */
  .recipes-container {
    padding: 0.9rem;
    gap: 0.65rem;
  }

  .recipe-tabs {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .recipe-tab {
    padding: 0.6rem 0.75rem;
    min-height: 44px;
  }

  .recipe-tab .tab-sub {
    font-size: 0.65rem;
  }

  .recipe-cards-list {
    max-height: 320px;
  }

  .test-drawer {
    padding: 0.9rem;
  }

  .test-input-row {
    flex-direction: column;
  }

  .btn-test {
    width: 100%;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .app-layout[data-mobile-tab="telemetry"] #telemetry-section {
    grid-template-columns: 1fr;
  }

  .metric-big-num {
    font-size: 1.35rem;
  }

  .recipe-tab .tab-sub {
    display: none;
  }
}
