/* ═══════════════════════════════════════════════
   Escape Dashboard — Premium Design System
   ═══════════════════════════════════════════════ */

:root {
  /* Deep, rich dark palette */
  --bg-0: #0a0b10;
  --bg-1: #12141d;
  --bg-2: #1b1e2b;
  --bg-3: #24283b;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  
  /* Text */
  --text: #e0e2eb;
  --text-secondary: #9aa0b8;
  --text-muted: #6b728e;
  
  /* Vibrant accents */
  --accent: #7a5cff;
  --accent-hover: #9177ff;
  --accent-bg: rgba(122, 92, 255, 0.15);
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Modern shapes */
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  /* Soft shadows & Glass */
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --glass-bg: rgba(18, 20, 29, 0.7);
  --glass-border: rgba(255, 255, 255, 0.05);
  
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Scrollbar ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Buttons ─── */
button, .btn-primary, .btn-accent, .btn-ghost {
  font-family: var(--font);
  font-size: 14px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius);
  transition: all var(--transition);
  white-space: nowrap;
  outline: none;
}

.btn-primary {
  background: var(--text);
  color: var(--bg-0);
  padding: 12px 24px;
  font-weight: 600;
}
.btn-primary:hover { 
  background: #fff; 
  transform: translateY(-1px);
}

.btn-accent {
  background: var(--bg-2);
  color: var(--text);
  padding: 10px 18px;
  font-weight: 500;
  border: 1px solid var(--border);
}
.btn-accent:hover { background: var(--bg-3); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-2); }

.btn-sm { font-size: 13px; padding: 6px 12px; }
.btn-sm svg { width: 16px; height: 16px; }

.text-muted { color: var(--text-muted); font-size: 12px; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  background: var(--danger-bg);
  padding: 10px;
  border-radius: var(--radius);
}

/* Spin animation */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }

/* ═══════════════════════════════════════════════
   Login
   ═══════════════════════════════════════════════ */

#login-overlay {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-0);
}

.login-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 400px;
  text-align: center;
}

.login-icon { margin-bottom: 20px; }
.login-icon svg { width: 48px; height: 48px; color: var(--accent); }

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.login-sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  margin-bottom: 16px;
  transition: all var(--transition);
}
.input-group:focus-within { 
  border-color: var(--accent); 
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.input-group svg { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.input-group input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 14px 0;
  outline: none;
}
.input-group input::placeholder { color: var(--text-muted); }

#login-form .btn-primary {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  padding: 14px;
  font-size: 15px;
}

/* ═══════════════════════════════════════════════
   Dashboard Layout
   ═══════════════════════════════════════════════ */

#dashboard {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-0);
}

/* ── Sidebar ─── */
#sidebar-container {
  display: flex;
  height: 100%;
  z-index: 50;
  box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  position: relative; /* So it's part of the flow but the panel can be absolute */
}

#icon-rail {
  width: 64px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 0;
  align-items: center;
  position: relative;
  z-index: 52; /* Above the panel */
}

.rail-top, .rail-bottom {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  align-items: center;
}

.sidebar-tab {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: transparent;
  transition: all var(--transition);
}
.sidebar-tab:hover {
  color: var(--text);
  background: var(--bg-2);
}
.sidebar-tab.active {
  color: var(--text);
  background: var(--bg-3);
}
.sidebar-tab svg { width: 22px; height: 22px; }

#logout-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  justify-content: center;
  padding: 0;
}

#sidebar-panel-container {
  position: absolute;
  left: 64px; /* Width of the icon rail */
  top: 0;
  height: 100%;
  width: 420px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.2s ease-out;
  display: flex;
  flex-direction: column;
  z-index: 51; /* Below the icon rail but above the main content */
  box-shadow: 4px 0 16px rgba(0,0,0,0.2);
}
#sidebar-panel-container.open { transform: translateX(0); }

.sidebar-content {
  width: 420px; /* Fixed width to prevent reflow during animation */
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel-header h3 svg { width: 18px; height: 18px; color: var(--accent); }

/* ── Context Menu ─── */
.dropdown-container {
  position: relative;
  display: inline-block;
}
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 140px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-5px);
  transition: all var(--transition);
}
.dropdown-menu.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.dropdown-item {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
}
.dropdown-item:hover {
  background: var(--bg-3);
}
.dropdown-item.danger {
  color: var(--danger);
}
.dropdown-item.danger:hover {
  background: var(--danger-bg);
}
.dropdown-item svg {
  width: 14px;
  height: 14px;
}

/* ── Content inside Sidebar Panels ─── */

.ai-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-0);
  flex-shrink: 0;
  position: relative;
}

.ai-input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 6px 12px;
  transition: all var(--transition);
}
.ai-input-wrapper:focus-within { 
  border-color: var(--accent);
  background: var(--bg-1);
}

.ai-input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 40px 8px 4px; /* padding right for button */
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}
.ai-input-wrapper textarea::placeholder { color: var(--text-muted); }

.chat-send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}
.chat-send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}
.chat-send-btn svg {
  width: 16px;
  height: 16px;
  margin-left: -2px; /* slight visual center tweak for send icon */
}

/* Generation Inputs (Image/Audio) */
.generation-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-0);
  flex-shrink: 0;
}

.generation-input-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all var(--transition);
}

.generation-input-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.generation-input-card textarea {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  outline: none;
  line-height: 1.5;
  padding: 0;
}

.generation-input-card textarea::placeholder {
  color: var(--text-muted);
}

.generation-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.generation-select-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 6px 10px;
  gap: 8px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.generation-select-wrapper:hover {
  border-color: var(--border-light);
}

.generation-select-wrapper svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.generation-select-wrapper select {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  padding: 0;
}

.generation-controls .btn-primary {
  padding: 8px 16px;
  font-size: 13px;
  border-radius: var(--radius);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state span {
  font-size: 13px;
  max-width: 250px;
  line-height: 1.4;
}

/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-msg {
  max-width: 90%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  background: var(--bg-2);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.assistant p { margin: 0 0 8px 0; }
.chat-msg.assistant p:last-child { margin: 0; }
.chat-msg.assistant code {
  background: var(--bg-0);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
}
.chat-msg.assistant pre {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}
.chat-msg.assistant pre code { background: none; padding: 0; }

.chat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
  margin-bottom: 6px;
}

/* Image/Audio results */
.image-results, .audio-results {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.image-result img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.image-result .image-prompt {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

.audio-result {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.audio-result audio { width: 100%; height: 40px; margin-top: 12px; }
.audio-result .audio-prompt { font-size: 13px; color: var(--text-muted); }

/* Files Dropzone */
.drop-zone {
  margin: 16px;
  padding: 32px 20px;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-0);
}
.drop-zone svg { width: 32px; height: 32px; color: var(--text-muted); }
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
}
.drop-zone.drag-over svg { color: var(--accent); }

.progress-bar {
  height: 6px;
  background: var(--bg-0);
  border-radius: 3px;
  margin: 8px 0;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0;
  transition: width 0.3s;
}
#upload-status { font-size: 13px; color: var(--text-muted); }

.file-list {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-0);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.file-item:hover { border-color: var(--border-light); transform: translateY(-1px); }

.file-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb svg { width: 20px; height: 20px; color: var(--text-muted); }

.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.file-meta { font-size: 12px; color: var(--text-muted); }

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

/* Console Logs */
.console-logs-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-0);
}
.console-log-entry {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-1);
  border-left: 3px solid transparent;
  word-break: break-all;
}

/* ═══════════════════════════════════════════════
   Main Area
   ═══════════════════════════════════════════════ */

#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Header ─── */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 72px;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.team-avatar {
  width: 40px;
  height: 40px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.team-avatar svg { width: 20px; height: 20px; }
.header-left h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.5px; }

.header-right { display: flex; align-items: center; gap: 12px; }

.api-key-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 16px 6px 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.api-key-badge:hover { border-color: var(--accent); background: var(--bg-3); }
.api-key-badge svg { width: 16px; height: 16px; color: var(--accent); }
.api-key-badge code { font-family: var(--mono); color: var(--text); font-size: 13px; }

/* ── Bottom Panel (Iframes) ─── */
#bottom-panel {
  flex: 1;
  display: flex;
  background: var(--bg-0);
  min-height: 0;
}

.iframe-container {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-1);
}

.iframe-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-1);
}
.iframe-header svg { width: 16px; height: 16px; color: var(--text-muted); }
.iframe-header span { flex: 1; }

.iframe-container iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff; /* Most iframes expect white bg */
}

/* ── Toast ─── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 9999;
  animation: toast-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-bottom: 3px solid var(--success); }
.toast.error { border-bottom: 3px solid var(--danger); }

@keyframes toast-in {
  from { transform: translateY(40px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
