/* ═══════════════════════════════════════════════════════════════════════════
   FOURM Relay IDE — Master Stylesheet
   Design: Glassmorphic dark IDE with electric violet accent palette
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. DESIGN TOKENS ─────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  /* Surfaces */
  --bg:          #0A0A0F;
  --surface-1:   #12121A;
  --surface-2:   #1A1A24;
  --surface-3:   #22222E;

  /* Borders */
  --border:        rgba(255, 255, 255, 0.06);
  --border-accent: rgba(108, 92, 231, 0.3);

  /* Accents */
  --accent:       #6C5CE7;
  --accent-glow:  rgba(108, 92, 231, 0.4);
  --accent-2:     #00D2FF;
  --accent-2-glow: rgba(0, 210, 255, 0.3);

  /* Semantic */
  --success: #00E676;
  --warning: #FFD600;
  --error:   #FF5252;

  /* Typography */
  --text-primary:   #F0F0F5;
  --text-secondary: #A0A0B5;
  --text-muted:     #606075;
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;

  /* Radii */
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);

  /* Motion */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast:   150ms;
  --duration-normal: 300ms;
  --duration-slow:   500ms;

  /* Z-index scale */
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;
  --z-drawer:   600;

  /* Grid sizing (set by JS drag) */
  --col-left: 50%;
  --row-top:  50%;
}


/* ── 2. RESET & BASE ──────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle ambient gradient — low-key depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(108, 92, 231, 0.15), transparent 42%),
    radial-gradient(ellipse at 82% 8%,  rgba(0, 210, 255, 0.08),  transparent 36%),
    radial-gradient(ellipse at 50% 90%, rgba(108, 92, 231, 0.06), transparent 40%);
  z-index: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 700;
  margin: 0;
}

p { margin: 0; }

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

button { cursor: pointer; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .monaco-host, .terminal-output, #terminalCmdInput,
.search-match-snippet, .editor-tabs {
  font-family: var(--font-mono) !important;
}

[hidden], .hidden { display: none !important; }


/* ── 3. CUSTOM SCROLLBARS ─────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(108, 92, 231, 0.25);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(108, 92, 231, 0.45);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(108, 92, 231, 0.25) transparent;
}


/* ── 4. APP SHELL ─────────────────────────────────────────────────────── */

.ide-app {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
  z-index: 1;
}


/* ── 5. TOPBAR ────────────────────────────────────────────────────────── */

.ide-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: rgba(18, 18, 26, 0.82);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

/* ── Brand Block ── */
.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hamburger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin-right: 4px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 20px;
  transition: all var(--duration-fast) ease;
}

.hamburger-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border);
}

.hamburger-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hamburger-btn:active {
  transform: scale(0.95);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--surface-2);
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
}

.brand-block strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

/* ── Session Strip ── */
.session-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.session-strip label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.session-strip input {
  flex: 1;
  min-width: 0;
}

.connection-pill,
.session-id,
.token-count {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

.connection-pill.connected,
.connection-pill.online {
  color: var(--success);
  text-shadow: 0 0 8px rgba(0, 230, 118, 0.5);
  animation: pulseGlow 2s ease-in-out infinite;
}

.connection-pill.offline {
  color: var(--error);
}

@keyframes pulseGlow {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

/* ── Topbar Actions ── */
.topbar-actions,
.panel-actions,
.composer-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.thinking-indicator {
  padding: 4px 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  animation: pulseGlow 1.2s ease-in-out infinite;
}

.thinking-indicator span::after {
  content: "";
  animation: thinkingDots 1.2s infinite;
}


/* ── 6. INPUTS & BUTTONS ─────────────────────────────────────────────── */

.session-strip input,
.preview-bar input,
.auth-card input,
.search-input-row input,
.secret-form input,
.secret-form textarea {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  background: var(--surface-1);
  font-size: 13px;
  outline: none;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.session-strip input:focus,
.preview-bar input:focus,
.auth-card input:focus,
.search-input-row input:focus,
.chat-composer textarea:focus,
.secret-form input:focus,
.secret-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

/* Buttons */
.btn,
.icon-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  background: var(--surface-2);
  transition: all var(--duration-fast) ease;
}

.btn {
  min-height: 36px;
  padding: 0 14px;
  font-weight: 600;
  font-size: 13px;
}

.icon-btn {
  min-width: 36px;
  min-height: 30px;
  padding: 0 8px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
}

.btn:hover,
.icon-btn:hover {
  background: var(--surface-3);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  transform: scale(1.02);
}

.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:active,
.icon-btn:active {
  transform: scale(0.98);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.btn.primary:hover {
  background: #7d6ef0;
  border-color: #7d6ef0;
  box-shadow: var(--shadow-glow);
}

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

.btn.subtle:hover {
  background: var(--surface-2);
}


/* ── 7. GLASSMORPHIC NAV DRAWER ───────────────────────────────────────── */

.nav-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) ease;
}

.nav-drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: env(safe-area-inset-left, 0px);
  bottom: 0;
  width: min(300px, 80vw);
  z-index: calc(var(--z-drawer) + 1);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  background: rgba(18, 18, 26, 0.88);
  border-right: 1px solid var(--border-accent);
  box-shadow: 10px 0 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(108, 92, 231, 0.08);
  transform: translateX(-100%);
  transition: transform var(--duration-normal) var(--ease-out-expo);
  display: flex;
  flex-direction: column;
}

.nav-drawer.active {
  transform: translateX(0);
}

.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
}

.nav-drawer-header h2 {
  margin: 0;
  font-size: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.close-drawer-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 22px;
  transition: all var(--duration-fast) ease;
}

.close-drawer-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.12);
}

.close-drawer-btn:active {
  transform: scale(0.95);
}

.nav-drawer-links {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-drawer-links .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--duration-fast) ease;
  /* Staggered entrance animation */
  opacity: 0;
  transform: translateX(-12px);
}

.nav-drawer.active .nav-link {
  opacity: 1;
  transform: translateX(0);
  transition: all var(--duration-normal) var(--ease-out-expo);
}

.nav-drawer.active .nav-link:nth-child(1) { transition-delay: 50ms; }
.nav-drawer.active .nav-link:nth-child(2) { transition-delay: 100ms; }
.nav-drawer.active .nav-link:nth-child(3) { transition-delay: 150ms; }
.nav-drawer.active .nav-link:nth-child(4) { transition-delay: 200ms; }
.nav-drawer.active .nav-link:nth-child(5) { transition-delay: 250ms; }
.nav-drawer.active .nav-link:nth-child(6) { transition-delay: 300ms; }

.nav-drawer-links .nav-link:hover {
  background: rgba(108, 92, 231, 0.1);
  color: var(--text-primary);
  border-color: rgba(108, 92, 231, 0.15);
}

.nav-drawer-links .nav-link.active {
  background: rgba(108, 92, 231, 0.18);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(108, 92, 231, 0.15);
}

.nav-drawer-links .nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ── 8. IDE GRID — 4-PANE LAYOUT ──────────────────────────────────────── */

.ide-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, var(--col-left)) 6px minmax(280px, 1fr);
  grid-template-rows: minmax(200px, var(--row-top)) 6px minmax(180px, 1fr);
  min-height: 0;
  height: 100%;
  max-width: 1800px;
  margin: 0 auto;
  width: 100%;
}

.divider {
  background: var(--surface-1);
  border: 1px solid var(--border);
  z-index: 4;
  transition: background var(--duration-fast) ease;
}

.divider:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.divider.vertical {
  grid-column: 2;
  grid-row: 1 / 4;
  cursor: col-resize;
}

.divider.horizontal {
  grid-column: 1 / 4;
  grid-row: 2;
  cursor: row-resize;
}


/* ── 9. PANELS (SHARED) ──────────────────────────────────────────────── */

.panel {
  display: grid;
  grid-template-rows: 42px 1fr;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 0;
  outline: none;
  overflow: hidden;
}

.panel:focus-visible {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

.panel-header h1 {
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

/* Panel grid placements (grid mode) */
.chat-panel {
  grid-column: 1;
  grid-row: 1;
  grid-template-rows: 42px 1fr;
}

.editor-panel {
  grid-column: 3;
  grid-row: 1;
}

.terminal-panel {
  grid-column: 1;
  grid-row: 3;
}

.preview-panel {
  grid-column: 3;
  grid-row: 3;
  grid-template-rows: 42px auto 1fr;
}


/* ── 10. VIEW SWITCHING (TRANSITIONS) ─────────────────────────────────── */

/* Non-grid views: fullscreen single panel */
body[data-active-view]:not([data-active-view="grid"]) .ide-grid {
  display: block !important;
  height: 100%;
  position: relative;
}

body[data-active-view]:not([data-active-view="grid"]) .divider {
  display: none !important;
}

body[data-active-view]:not([data-active-view="grid"]) .panel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transform: translateX(20px);
  transition: opacity var(--duration-normal) var(--ease-out-expo),
              transform var(--duration-normal) var(--ease-out-expo),
              visibility var(--duration-normal) var(--ease-out-expo);
  z-index: 1;
  border: none;
  border-radius: 0;
  visibility: hidden;
}

/* Active panels */
body[data-active-view="chat"] #panel-chat,
body[data-active-view="projects"] #panel-editor,
body[data-active-view="terminal"] #panel-terminal,
body[data-active-view="preview"] #panel-preview,
body[data-active-view="secrets"] #panel-secrets {
  display: grid !important;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  z-index: 5;
  visibility: visible;
}


/* ── 11. CHAT VIEW (PRIMARY) ─────────────────────────────────────────── */

body[data-active-view="chat"] #panel-chat {
  display: flex !important;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  background: transparent;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

body[data-active-view="chat"] .panel-header {
  background: rgba(18, 18, 26, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

body[data-active-view="chat"] .chat-panel-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
}

body[data-active-view="chat"] .chat-timeline {
  padding: 20px 24px;
}

body[data-active-view="chat"] .chat-composer {
  background: rgba(18, 18, 26, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}

.chat-panel-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}


/* ── 12. CHAT TIMELINE & MESSAGES ─────────────────────────────────────── */

.chat-timeline {
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  flex: 1;
}

.message {
  width: fit-content;
  max-width: min(720px, 92%);
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  line-height: 1.55;
  word-break: break-word;
  font-size: 13px;
  animation: messageSlideIn var(--duration-normal) var(--ease-out-expo);
}

@keyframes messageSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.commander {
  margin-left: auto;
  border-color: var(--border-accent);
  background: rgba(108, 92, 231, 0.12);
}

.message.fourm {
  margin-right: auto;
}

.message.system {
  margin: 8px auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  background: transparent;
  border: none;
  padding: 4px 12px;
}

.message.error {
  border-color: rgba(255, 82, 82, 0.3);
  background: rgba(255, 82, 82, 0.08);
}

.message pre {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg);
  font-size: 12px;
  margin: 8px 0;
}

.message code {
  font-family: var(--font-mono);
  font-size: 12px;
}

.message table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.message th,
.message td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 12px;
}

.message th {
  background: var(--surface-2);
  font-weight: 600;
}

.file-link {
  border: 0;
  padding: 0;
  color: var(--accent-2);
  background: transparent;
  text-decoration: underline;
  cursor: pointer;
  transition: color var(--duration-fast) ease;
}

.file-link:hover {
  color: #66e0ff;
}

/* ── Thinking Card ── */
.thinking-card.message {
  border-left: 3px solid var(--accent);
  background: rgba(108, 92, 231, 0.06);
}

.thinking-card .thinking-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 6px;
}

.thinking-card .thinking-body {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.thinking-toggle {
  opacity: 0.01;
  width: 8px;
  height: 8px;
  padding: 0;
  margin: 0;
  border: 0;
  position: absolute;
  top: 4px;
  right: 4px;
  cursor: pointer;
  pointer-events: auto;
}

/* ── Thinking Indicator (Relay orb) ── */
.relay-thinking-message { width: min(300px, 100%); }

.relay-thinking {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

.relay-thinking-orb {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(108, 92, 231, 0.12);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 900;
  animation: relayThinkingPulse 800ms ease-in-out infinite;
}

.relay-thinking-orb svg {
  position: absolute;
  inset: -3px;
  width: 50px;
  height: 50px;
  overflow: visible;
}

.relay-thinking-trace {
  fill: none;
  stroke: var(--thinking-color, var(--accent));
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 114;
  animation: relayThinkingTrace 2s linear infinite;
}

.relay-thinking-copy {
  min-width: 0;
  color: var(--text-muted);
  font-size: 11px;
}

/* ── Swarm Agent Cards ── */
.swarm-agent-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(12px);
  overflow: hidden;
  margin-bottom: 8px;
}

.swarm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
}

.swarm-card-body {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.swarm-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  animation: relayDotPulse 800ms ease-in-out infinite;
}


/* ── 13. CHAT COMPOSER ────────────────────────────────────────────────── */

.chat-composer {
  border-top: 1px solid var(--border);
  padding: 12px;
  background: var(--surface-1);
  flex-shrink: 0;
}

.chat-composer textarea {
  width: 100%;
  min-height: 52px;
  max-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  background: var(--surface-2);
  outline: none;
  font-size: 13px;
  line-height: 1.5;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

#chatInput {
  min-height: 48px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.composer-footer {
  justify-content: flex-end;
  margin-top: 8px;
}

.composer-footer span {
  margin-right: auto;
  color: var(--text-muted);
  font-size: 11px;
}


/* ── 14. EDITOR PANEL ─────────────────────────────────────────────────── */

.editor-workspace {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 0;
}

.file-sidebar {
  min-width: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface-1);
}

.sidebar-title {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-1);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.file-tree { padding: 8px; }

.tree-node {
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  color: var(--text-primary);
  background: transparent;
  text-align: left;
  white-space: nowrap;
  font-size: 12px;
  transition: background var(--duration-fast) ease;
  min-height: 30px;
  display: flex;
  align-items: center;
}

.tree-node:hover { background: var(--surface-2); }
.tree-node.active { background: rgba(108, 92, 231, 0.15); color: #fff; }

.tree-group {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 8px 8px 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tree-children { padding-left: 12px; }

.editor-main {
  position: relative;
  display: grid;
  grid-template-rows: 34px 1fr;
  min-width: 0;
  min-height: 0;
}

.editor-tabs {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

.editor-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 100px;
  max-width: 200px;
  border: 0;
  border-right: 1px solid var(--border);
  padding: 0 12px;
  color: var(--text-muted);
  background: transparent;
  font-size: 12px;
  transition: all var(--duration-fast) ease;
}

.editor-tab:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.editor-tab.active {
  color: var(--text-primary);
  background: var(--surface-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.editor-tab span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dirty-dot { color: var(--warning); }

.monaco-host { min-height: 0; }

.editor-empty {
  position: absolute;
  inset: 34px 0 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  background: var(--surface-1);
  font-size: 14px;
}


/* ── 15. TERMINAL PANEL ───────────────────────────────────────────────── */

.terminal-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
  min-height: 0;
  background: var(--bg);
}

.search-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header-simple {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
}

.search-input-row {
  display: flex;
  padding: 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search-input-row input { flex: 1; }

.search-results-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-match-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: all var(--duration-fast) ease;
}

.search-match-item:hover {
  background: var(--surface-3);
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.search-match-file {
  font-size: 11px;
  color: var(--accent-2);
  margin-bottom: 4px;
  font-weight: 600;
}

.search-match-snippet {
  font-size: 12px;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
}

.terminal-panel-interactive {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.terminal-output {
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  padding: 12px 16px;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.5;
  white-space: pre-wrap;
  font-size: 12px;
  flex: 1;
}

.terminal-line.stderr { color: var(--error); }
.terminal-line.command { color: var(--accent-2); }

.terminal-input-form {
  display: flex;
  align-items: center;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  gap: 8px;
}

.prompt-sym {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 14px;
}

#terminalCmdInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  min-height: 32px;
}

#terminalCmdInput:focus { outline: none; }


/* ── 16. PREVIEW PANEL ────────────────────────────────────────────────── */

.preview-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

.preview-bar input { width: 100%; }

.preview-stage {
  position: relative;
  min-height: 0;
  background: var(--bg);
}

.preview-stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.preview-empty,
.preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 14px;
}

.preview-loading {
  gap: 10px;
  grid-auto-flow: column;
}

.preview-loading span,
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}


/* ── 17. SECRETS PANEL ────────────────────────────────────────────────── */

.secrets-panel {
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.secrets-workspace {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  height: 100%;
  min-height: 0;
  background: var(--bg);
}

.secrets-left,
.secrets-right {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.secrets-left { border-right: 1px solid var(--border); }

.secrets-left h3,
.secrets-right h3 {
  font-size: 16px;
  color: var(--text-primary);
}

.secret-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.secret-form label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.secret-form textarea {
  min-height: 120px;
  font-family: var(--font-mono);
  resize: vertical;
}

.secrets-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.secret-item-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color var(--duration-fast) ease;
}

.secret-item-card:hover {
  border-color: var(--border-accent);
}

.secret-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.secret-item-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.secret-item-meta {
  font-size: 10px;
  color: var(--text-muted);
}

.delete-secret-btn {
  background: rgba(255, 82, 82, 0.08);
  border: 1px solid rgba(255, 82, 82, 0.2);
  color: var(--error);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  min-height: 32px;
  transition: all var(--duration-fast) ease;
}

.delete-secret-btn:hover {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.delete-secret-btn:active {
  transform: scale(0.97);
}


/* ── 18. RECENT PROJECTS (CHAT VIEW) ─────────────────────────────────── */

.recent-repos-section {
  margin-top: 16px;
  padding: 0 24px 20px;
  flex-shrink: 0;
  max-height: 240px;
  overflow-y: auto;
}

.recent-repos-section h3 {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}

.recent-projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.project-card {
  background: rgba(18, 18, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out-expo);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-accent);
  box-shadow: 0 8px 28px rgba(108, 92, 231, 0.12);
}

.project-card:active {
  transform: translateY(-1px) scale(0.99);
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.project-card strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.project-status-badge.building {
  background: rgba(0, 210, 255, 0.12);
  color: var(--accent-2);
}

.project-status-badge.complete,
.project-status-badge.deployed {
  background: rgba(0, 230, 118, 0.12);
  color: var(--success);
}

.project-status-badge.error {
  background: rgba(255, 82, 82, 0.12);
  color: var(--error);
}

.project-prompt-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.project-card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}

.preview-badge-link {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 500;
}

.preview-badge-link:hover { text-decoration: underline; }

/* Hide recent projects in non-chat views */
body[data-active-view="grid"] .recent-repos-section,
.floating-chatbox .recent-repos-section,
body:not([data-active-view="chat"]) .recent-repos-section {
  display: none !important;
}


/* ── 19. FLOATING CHATBOX ─────────────────────────────────────────────── */

.floating-chatbox {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  right: calc(22px + env(safe-area-inset-right, 0px));
  width: 380px;
  height: 520px;
  z-index: var(--z-overlay);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  background: rgba(18, 18, 26, 0.92);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(108, 92, 231, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-out-expo);
  animation: floatingChatSlideUp var(--duration-normal) var(--ease-out-expo);
}

@keyframes floatingChatSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.floating-chatbox.minimized {
  height: 48px;
  width: 220px;
  border-radius: var(--radius-pill);
}

.floating-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(108, 92, 231, 0.1), transparent);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  min-height: 48px;
}

.floating-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.floating-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  font-size: 9px;
  font-weight: 800;
  color: #fff;
}

#floatingChatContextLabel {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.floating-chat-actions button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  transition: all var(--duration-fast) ease;
}

.floating-chat-actions button:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border);
}

.floating-chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.floating-chatbox.minimized .floating-chat-body { display: none; }

/* Chat inside floating host — compact */
.floating-chat-body .chat-panel-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.floating-chat-body .chat-timeline {
  padding: 10px;
  font-size: 12px;
}

.floating-chat-body .message {
  max-width: 95%;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.floating-chat-body .chat-composer {
  padding: 8px;
  border-top: 1px solid var(--border);
  background: rgba(18, 18, 26, 0.95);
}

.floating-chat-body .chat-composer textarea {
  min-height: 36px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.floating-chat-body .composer-footer { margin-top: 4px; }


/* ── 20. TOAST NOTIFICATIONS ──────────────────────────────────────────── */

.toast-region {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 28px));
}

.toast {
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  background: rgba(18, 18, 26, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toastSlideIn var(--duration-normal) var(--ease-out-expo);
}

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast.error {
  border-color: rgba(255, 82, 82, 0.4);
}

.toast.success {
  border-color: rgba(0, 230, 118, 0.3);
}


/* ── 21. AUTH MODAL ───────────────────────────────────────────────────── */

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 10, 15, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 28px;
  background: rgba(18, 18, 26, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(108, 92, 231, 0.1);
}

.auth-card h2 {
  font-size: 22px;
  margin: 0 0 4px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 14px;
}

.form-error {
  min-height: 18px;
  color: var(--error);
  font-size: 12px;
  font-weight: 500;
}


/* ── 22. LOADING SKELETON ─────────────────────────────────────────────── */

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}

.skeleton * { visibility: hidden; }


/* ── 23. KEYFRAME ANIMATIONS ──────────────────────────────────────────── */

@keyframes thinkingDots {
  0%   { content: ""; }
  33%  { content: "."; }
  66%  { content: ".."; }
  100% { content: "..."; }
}

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

@keyframes relayThinkingPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

@keyframes relayThinkingTrace {
  from { stroke-dashoffset: 114; }
  to   { stroke-dashoffset: -114; }
}

@keyframes relayDotPulse {
  0%, 100% { transform: scale(1);   opacity: 0.6; }
  50%      { transform: scale(1.3); opacity: 1; }
}


/* ── 24. RESPONSIVE DESIGN ────────────────────────────────────────────── */

/* 320px — Minimum phone */
@media (max-width: 320px) {
  .ide-topbar { padding: 6px 8px; gap: 6px; }
  .session-strip { display: none; }
  .floating-chatbox { width: calc(100vw - 16px); right: 8px; }
}

/* 480px — Small phone */
@media (max-width: 480px) {
  .recent-projects-grid { grid-template-columns: 1fr; }
  .floating-chatbox { width: calc(100vw - 32px); right: 16px; }
  body[data-active-view="chat"] .chat-timeline { padding: 12px 14px; }
  body[data-active-view="chat"] .chat-composer { padding: 10px 14px; }
}

/* 640px — Large phone / small tablet */
@media (max-width: 640px) {
  .terminal-layout { grid-template-columns: 1fr; }
  .search-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .secrets-workspace { grid-template-columns: 1fr; }
  .secrets-left { border-right: none; border-bottom: 1px solid var(--border); }
  .editor-workspace { grid-template-columns: 1fr; }
  .file-sidebar { display: none; }
}

/* 768px — Tablet: disable grid mode, single views only */
@media (max-width: 768px) {
  body {
    overflow: auto;
  }

  .ide-app {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
  }

  .ide-topbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .session-strip,
  .topbar-actions {
    flex-wrap: wrap;
  }

  /* Collapse grid to stacked in grid mode */
  body[data-active-view="grid"] .ide-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(400px, 65vh));
    height: auto;
    max-width: 100%;
  }

  body[data-active-view="grid"] .panel {
    grid-column: 1 !important;
    min-height: 400px;
  }

  body[data-active-view="grid"] .chat-panel    { grid-row: 1; }
  body[data-active-view="grid"] .editor-panel  { grid-row: 2; }
  body[data-active-view="grid"] .terminal-panel { grid-row: 3; }
  body[data-active-view="grid"] .preview-panel { grid-row: 4; }
  body[data-active-view="grid"] .divider       { display: none; }

  .editor-workspace { grid-template-columns: 140px 1fr; }

  .floating-chatbox {
    width: calc(100vw - 32px);
    max-width: 400px;
  }
}

/* 1024px — Small desktop */
@media (min-width: 1024px) {
  body[data-active-view="chat"] #panel-chat {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* 1280px — Large desktop */
@media (min-width: 1280px) {
  body[data-active-view="chat"] .chat-timeline { padding: 28px 32px; }
  body[data-active-view="chat"] .chat-composer { padding: 18px 32px; }
}


/* ── 25. FOCUS & ACCESSIBILITY ────────────────────────────────────────── */

/* Universal focus ring for interactive elements */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* Minimum touch targets */
@media (pointer: coarse) {
  .btn,
  .icon-btn,
  .nav-link,
  .tree-node,
  .editor-tab,
  .hamburger-btn,
  .close-drawer-btn,
  .project-card,
  .search-match-item,
  .delete-secret-btn,
  .floating-chat-actions button {
    min-height: 44px;
  }
}


/* ── 26. UTILITY & MUTED TEXT ─────────────────────────────────────────── */

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