/* ==========================================================================
   KORSH AI — PURE CHAT INTERFACE
   Strictly Monochromatic Apple Glass Design System (KorshLab Standards)
   Pure #000000, #0a0a0a, #121212, #181818, #222222, #888888, #ffffff
   Zero Chromatic Colors (No red, blue, green, cyan, yellow, purple)
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Geist Mono', 'Fira Code', ui-monospace, monospace;

  /* Superficies y Fondos */
  --bg-primary: #000000;
  --bg-surface: #0a0a0a;
  --bg-surface-elevated: #121212;
  --bg-surface-card: #181818;
  --bg-surface-hover: #1e1e1e;
  --bg-input: #111111;
  --bg-code: #080808;

  /* Bordes Especulares */
  --border-subtle: #1c1c1c;
  --border-color: #222222;
  --border-hover: #333333;
  --border-focus: #ffffff;

  /* Tipografía y Contraste */
  --text-primary: #ffffff;
  --text-secondary: #8c8c8c;
  --text-tertiary: #525252;
  --text-inverted: #000000;

  /* Geometría y Radios */
  --sidebar-w: 280px;
  --header-h: 56px;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-squircle: 24px;
  --radius-pill: 9999px;

  /* Transiciones y Físicas Hápticas Apple */
  --transition: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  --spring: 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  --ease-haptic: cubic-bezier(0.16, 1, 0.3, 1);

  /* Reflejos de Cristal y Sombras (Liquid Crystal visionOS) */
  --glass-blur: 32px;
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.16), inset 0 -1px 0 rgba(0, 0, 0, 0.6);
  --glass-highlight-subtle: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --shadow-workspace: 0 20px 60px -10px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.08);
  --shadow-modal: 0 32px 80px -15px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   TEMA CLARO (LIGHT THEME — MONOCHROME APPLE GLASS)
   ========================================================================== */
[data-theme="light"] {
  /* Superficies y Fondos Apple Light Glass */
  --bg-primary: #f5f5f5;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #fafafa;
  --bg-surface-card: #f0f0f0;
  --bg-surface-hover: #e8e8e8;
  --bg-input: #ffffff;
  --bg-code: #f2f2f2;

  /* Bordes Especulares */
  --border-subtle: #e5e5e5;
  --border-color: #d1d1d1;
  --border-hover: #aeaeae;
  --border-focus: #000000;

  /* Tipografía y Contraste */
  --text-primary: #111111;
  --text-secondary: #5a5a5a;
  --text-tertiary: #8e8e8e;
  --text-inverted: #ffffff;

  /* Reflejos de Cristal y Sombras (Frosted Crystal) */
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 -1px 0 rgba(0, 0, 0, 0.04);
  --glass-highlight-subtle: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  --shadow-workspace: 0 16px 45px -8px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.08);
  --shadow-modal: 0 28px 70px -12px rgba(0, 0, 0, 0.14), 0 0 0 1px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .main-header {
  background: rgba(245, 245, 245, 0.88);
}

/* Logotipo nativo de alto contraste según tema (korshai.png en oscuro, korshaiblack.png en claro) */
[data-theme="light"] .splash-logo,
[data-theme="light"] .sidebar-logo,
[data-theme="light"] .pegasus-welcome-img,
[data-theme="light"] .user-pill-avatar img,
[data-theme="light"] .msg-pegasus-avatar img,
[data-theme="light"] .info-logo-frame img {
  filter: none;
}

[data-theme="light"] .welcome-fx .w-orb {
  opacity: 0.15;
}

[data-theme="light"] .w-halo {
  background: radial-gradient(circle, rgba(0, 0, 0, 0.06) 0%, transparent 70%);
}

[data-theme="light"] .msg-row.user .msg-user-bubble {
  background: #111111;
  color: #ffffff;
}

[data-theme="light"] .input-wrapper {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06), 0 0 0 1px var(--border-color);
}

[data-theme="light"] .input-area {
  background: linear-gradient(180deg, transparent 0%, rgba(245, 245, 245, 0.95) 30%);
}

[data-theme="light"] .modal {
  background: rgba(0, 0, 0, 0.45);
}

[data-theme="light"] .starter-chip:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08), var(--glass-highlight);
}

[data-theme="light"] .code-container {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .segmented-btn.active {
  background: #ffffff;
  color: #111111;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .btn-primary:hover {
  background: #2c2c2c;
  color: #ffffff;
}

/* Reset Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-sans);
  color: var(--text-primary);
}

input, textarea {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
}

img {
  display: block;
}

code, pre {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  -webkit-font-feature-settings: "tnum" 1;
  font-feature-settings: "tnum" 1;
}

/* ==========================================================================
   PANTALLA DE CARGA (SPLASH SCREEN)
   ========================================================================== */
#splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.45s ease;
}

#splash.fade-out {
  opacity: 0;
  pointer-events: none;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.splash-logo-wrap {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-squircle);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-workspace), var(--glass-highlight);
  animation: splashPulse 2s ease-in-out infinite;
}

.splash-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
  filter: grayscale(100%);
}

.splash-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.splash-bar {
  width: 130px;
  height: 2px;
  background: var(--border-color);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.splash-fill {
  height: 100%;
  width: 0%;
  background: var(--text-primary);
  border-radius: var(--radius-pill);
  animation: splashBarFill 1.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes splashBarFill {
  to { width: 100%; }
}

@keyframes splashPulse {
  0%, 100% { transform: scale(0.97); opacity: 0.75; }
  50% { transform: scale(1.03); opacity: 1; }
}

/* ==========================================================================
   DISTRIBUCIÓN DE LA APLICACIÓN (LAYOUT)
   ========================================================================== */
.app-layout {
  display: flex;
  width: 100vw;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   PANEL LATERAL (SIDEBAR)
   ========================================================================== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  z-index: 50;
  transition: margin-left 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.22s ease,
              border-color 0.2s ease;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w)) !important;
  border-right-color: transparent !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-frame {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glass-highlight-subtle);
}

.sidebar-logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: grayscale(100%);
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: translateY(0) scale(0.94);
  transition-duration: 0.08s;
}

/* Navegación del Sidebar */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  width: 100%;
  text-align: left;
}

.sidebar-nav-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.sidebar-nav-item:active {
  transform: scale(0.98);
  transition-duration: 0.08s;
}

.sidebar-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  padding: 10px 14px 4px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-list::-webkit-scrollbar {
  width: 4px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.chat-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.chat-item:active {
  transform: scale(0.98);
  transition-duration: 0.08s;
}

.chat-item.active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: var(--glass-highlight-subtle);
}

.chat-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.btn-delete-chat {
  display: none;
  background: transparent;
  color: var(--text-tertiary);
  padding: 2px;
  border-radius: var(--radius-xs);
}

.chat-item:hover .btn-delete-chat,
.chat-item.active .btn-delete-chat {
  display: flex;
}

.btn-delete-chat:hover {
  color: var(--text-primary);
}

/* Pie del Sidebar */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}

.user-pill-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-card);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.user-pill-avatar img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  filter: grayscale(100%);
}

.user-pill-info {
  display: flex;
  flex-direction: column;
}

.user-pill-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-pill-email {
  font-size: 0.65rem;
  color: var(--text-tertiary);
}

/* ==========================================================================
   ÁREA PRINCIPAL DE CHAT
   ========================================================================== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

.main-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  z-index: 10;
}

.btn-icon-round {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-icon-round:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.btn-icon-round:active {
  transform: translateY(0) scale(0.94);
  transition-duration: 0.08s;
}

.header-title-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-chat-title {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.beta-badge {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  line-height: 1.4;
}

.beta-badge-lg {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  margin-left: 8px;
  vertical-align: middle;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-glass-pill {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  user-select: none;
}

.btn-glass-pill:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.btn-glass-pill:active {
  transform: translateY(0);
}

.icon-sun, .icon-moon {
  transition: transform 0.25s ease, opacity 0.2s ease;
}

/* Control Segmentado (Tema e Idioma) */
.segmented-control {
  display: inline-flex;
  background: var(--bg-surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.segmented-btn {
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  transition: all var(--transition);
}

.segmented-btn:hover {
  color: var(--text-primary);
}

.segmented-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), var(--glass-highlight-subtle);
}

/* ==========================================================================
   ESTADO DE BIENVENIDA (HERO)
   ========================================================================== */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: auto 0;
  max-width: 760px;
  width: 100%;
  animation: fadeIn 0.4s var(--transition);
  position: relative;
}

.welcome-fx {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  width: 440px;
  height: 280px;
  pointer-events: none;
}

.w-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
}

.w-orb.o1 {
  width: 200px; height: 200px;
  background: rgba(255, 255, 255, 0.03);
  top: 10px; left: 15%;
}

.w-orb.o2 {
  width: 220px; height: 220px;
  background: rgba(255, 255, 255, 0.02);
  top: 0; right: 15%;
}

.welcome-stage {
  position: relative;
  margin-bottom: 20px;
}

.w-halo {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, transparent 70%);
}

.welcome-logo-box {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-squircle);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-workspace), var(--glass-highlight);
  position: relative;
  z-index: 1;
}

.pegasus-welcome-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  filter: grayscale(100%);
}

.welcome-title {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

/* Tarjetas Rápidas de Inicio */
.work-starter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
}

.starter-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all var(--transition);
  box-shadow: var(--glass-highlight-subtle);
}

.starter-chip:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-focus);
  transform: translateY(-2px);
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.75), var(--glass-highlight);
}

.starter-chip:active {
  transform: translateY(0) scale(0.98);
  transition-duration: 0.08s;
}

.chip-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chip-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ==========================================================================
   MENSAJES DE CONVERSACIÓN
   ========================================================================== */
.chat-thread {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  animation: fadeIn 0.25s var(--transition);
}

.msg-row.user {
  align-items: flex-end;
}

.msg-row.assistant {
  align-items: flex-start;
}

.msg-user-bubble {
  max-width: 80%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
  padding: 12px 18px;
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.55;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), var(--glass-highlight-subtle);
  word-break: break-word;
}

.msg-assistant-wrapper {
  display: flex;
  gap: 14px;
  width: 100%;
}

.msg-pegasus-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--glass-highlight-subtle);
}

.msg-pegasus-avatar img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: grayscale(100%);
}

.msg-assistant-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-text {
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.65;
  word-break: break-word;
}

.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-top: 14px;
  margin-bottom: 8px;
}

.msg-text h1 { font-size: 1.4rem; }
.msg-text h2 { font-size: 1.2rem; }
.msg-text h3 { font-size: 1.05rem; }
.msg-text h4 { font-size: 0.92rem; }

.msg-text p { margin-bottom: 12px; }
.msg-text ul, .msg-text ol { margin: 8px 0 14px 22px; }
.msg-text li { margin-bottom: 5px; }
.msg-text hr { border: 0; height: 1px; background: var(--border-color); margin: 16px 0; }
.msg-text blockquote { border-left: 2px solid var(--border-focus); padding-left: 12px; color: var(--text-secondary); margin: 12px 0; font-style: italic; }

.msg-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.8rem;
}

.msg-text th, .msg-text td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

.msg-text th {
  background: var(--bg-surface-elevated);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.msg-text :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

/* Bloques de Código */
.code-container {
  margin: 14px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-code);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
}

.code-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.btn-copy-code {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: 0.7rem;
  padding: 2px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition);
}

.btn-copy-code:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.code-container pre {
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-primary);
}

.streaming-cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background-color: var(--text-primary);
  vertical-align: middle;
  margin-left: 4px;
  animation: cursorBlink 0.8s infinite ease-in-out;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ==========================================================================
   ÁREA DE ENTRADA (ESTILO KORA LIMPIO)
   ========================================================================== */
.input-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 20px 18px;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.95) 45%, #000000 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 15;
}

.input-wrapper {
  width: 100%;
  max-width: 820px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-squircle);
  box-shadow: var(--shadow-workspace), var(--glass-highlight);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  display: flex;
  align-items: flex-end;
  padding: 8px 12px;
  gap: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.9), 0 0 0 1px var(--border-focus), var(--glass-highlight);
}

.input-side-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}

.input-side-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.input-side-btn:active {
  transform: translateY(0) scale(0.94);
  transition-duration: 0.08s;
}

.user-input {
  flex: 1;
  min-height: 36px;
  max-height: 180px;
  padding: 6px 4px;
  font-size: 0.94rem;
  line-height: 1.5;
  resize: none;
}

.user-input::placeholder {
  color: var(--text-tertiary);
}

.send-action-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--text-inverted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.send-action-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.25);
}

.send-action-btn:active {
  transform: scale(0.94);
  transition-duration: 0.08s;
}

.send-action-btn.stopping {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-focus);
  color: var(--text-primary);
}

.input-disclaimer {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  margin-top: 6px;
  text-align: center;
}

/* ==========================================================================
   MODALES (PROYECTOS, CONFIGURACIÓN, INFORMACIÓN)
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  width: 100%;
  max-width: 500px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-squircle);
  box-shadow: var(--shadow-modal), var(--glass-highlight);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn var(--spring) both;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.modal-body-padding {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.projects-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-item {
  padding: 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all var(--transition);
}

.project-item:hover, .project-item.active {
  border-color: var(--border-focus);
}

.project-item-title {
  font-weight: 600;
  font-size: 0.82rem;
}

.project-create-form {
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-input, .textarea-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--text-primary);
  outline: none;
}

.text-input:focus, .textarea-input:focus {
  border-color: var(--border-focus);
}

.textarea-input {
  min-height: 55px;
  resize: vertical;
}

.btn-primary {
  padding: 8px 16px;
  background: var(--text-primary);
  color: var(--text-inverted);
  font-weight: 600;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  align-self: flex-end;
}

.btn-primary:hover {
  background: #e5e5e5;
}

.settings-list {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.card-row-title {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
}

.settings-card-sub {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.btn-danger-badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.btn-danger-badge:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.info-hero {
  padding: 20px 18px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.info-logo-frame {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-squircle);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: var(--shadow-workspace);
}

.info-logo-frame img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: grayscale(100%);
}

.info-hero h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.info-tag {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.info-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 380px;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    margin-left: 0 !important;
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    max-width: var(--sidebar-w) !important;
    opacity: 1 !important;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0) !important;
    pointer-events: auto !important;
  }
  .sidebar.collapsed {
    margin-left: 0 !important;
    transform: translateX(-100%) !important;
  }
  .work-starter-grid {
    grid-template-columns: 1fr;
  }
}
