:root {
  color-scheme: dark;
  --bar-h: 76px;
  --navy-950: #0f172a;
  --navy-800: #1e293b;
  --navy-700: #243044;
  --navy-100: #334155;
  --coral-600: #e94324;
  --coral-100: rgba(233, 67, 36, 0.14);
  --accent: #38bdf8;
  --surface: #1e293b;
  --surface-2: #243044;
  --canvas: #0f172a;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --success: #4ade80;
  --shadow: 0 8px 28px rgba(2, 6, 23, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--canvas);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
iframe {
  font: inherit;
}

/* Header */
#toolbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 24px;
  height: var(--bar-h);
  padding: 10px clamp(16px, 2.4vw, 34px);
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(30, 41, 59, 0.98);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-width: 0;
  gap: 12px;
  user-select: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 50px;
  height: 50px;
  padding: 7px;
  overflow: hidden;
  background: linear-gradient(145deg, #f8fafc, #e9f1f8);
  border: 1px solid #475569;
  border-radius: 15px;
  box-shadow: 0 5px 16px rgba(2, 6, 23, 0.28);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-copy,
.tab-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.brand-name {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.brand-name span {
  color: var(--coral-600);
}

.brand-tagline {
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* App switcher */
.tabs {
  display: flex;
  align-items: stretch;
  gap: 5px;
  padding: 5px;
  background: var(--navy-950);
  border: 1px solid var(--border);
  border-radius: 17px;
}

.tab {
  appearance: none;
  display: flex;
  align-items: center;
  min-width: 172px;
  gap: 10px;
  padding: 8px 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab:active {
  transform: translateY(1px);
}

.tab:focus-visible {
  outline: 3px solid rgba(56, 189, 248, 0.25);
  outline-offset: 2px;
}

.tab.active {
  color: var(--accent);
  background: var(--surface-2);
  border-color: #475569;
  box-shadow: 0 3px 12px rgba(2, 6, 23, 0.28);
}

.tab-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  border-radius: 10px;
}

.tab-icon svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.active .tab-icon {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

.tab-label {
  color: currentColor;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
}

.tab-description {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  min-width: 0;
  gap: 7px;
  padding: 8px 11px;
  color: var(--muted);
  background: var(--navy-950);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border: 2px solid rgba(74, 222, 128, 0.28);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(32, 166, 106, 0.12);
}

.status strong {
  max-width: 110px;
  overflow: hidden;
  color: var(--accent);
  font-weight: 750;
  text-overflow: ellipsis;
}

/* App stage. Both iframes remain mounted to preserve their internal state. */
#stage {
  position: absolute;
  inset: var(--bar-h) 0 0;
  background: var(--canvas);
}

.app-frame {
  position: absolute;
  z-index: 1;
  display: none;
  width: 100%;
  height: 100%;
  background: var(--canvas);
  border: 0;
}

.app-frame.active {
  display: block;
}

.loading-panel {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  background:
    radial-gradient(circle at 50% 20%, rgba(56, 189, 248, 0.12), transparent 34%),
    var(--canvas);
  font-size: 14px;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.loading-panel[hidden] {
  display: none;
}

.loading-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 750ms linear infinite;
}

.noscript-message {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: 16px;
  left: 16px;
  margin: 0;
  padding: 12px 16px;
  color: #7b301f;
  background: #fff3ed;
  border: 1px solid #ffcbbb;
  border-radius: 12px;
  text-align: center;
}

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

@media (max-width: 920px) {
  #toolbar {
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    padding-right: 16px;
    padding-left: 16px;
  }

  .brand-tagline,
  .status-label,
  .tab-description {
    display: none;
  }

  .tabs {
    justify-self: center;
  }

  .tab {
    min-width: 0;
    padding: 8px 12px;
  }
}

@media (max-width: 680px) {
  :root {
    --bar-h: 66px;
  }

  #toolbar {
    grid-template-columns: auto 1fr;
    gap: 10px;
    padding: 8px 10px;
  }

  .brand {
    gap: 7px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    padding: 6px;
    border-radius: 13px;
  }

  .brand-copy {
    display: none;
  }

  .tabs {
    width: 100%;
    min-width: 0;
    justify-self: stretch;
    padding: 4px;
    border-radius: 14px;
  }

  .tab {
    flex: 1 1 0;
    justify-content: center;
    gap: 7px;
    padding: 6px 8px;
    border-radius: 10px;
  }

  .tab-icon {
    width: 30px;
    height: 30px;
  }

  .tab-icon svg {
    width: 19px;
    height: 19px;
  }

  .tab-label {
    font-size: 12px;
  }

  .status {
    display: none;
  }
}

@media (max-width: 390px) {
  .tab-copy {
    display: none;
  }
}

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