:root {
  --bg-main: #05040c;
  --bg-sidebar: #090a14;
  --bg-sidebar-hover: #121524;
  --bg-chat-user: #121626;
  --bg-chat-ai: #090b14;
  --border-color: rgba(0, 246, 255, 0.13);
  --text-main: #ffffff;
  --text-muted: #94a3b8;
  --text-accent: #00f2fe;
  --primary: #00f2fe;
  --primary-hover: #38f9d7;
  --accent-cyan: #00f2fe;
  --danger: #f85149;
  --success: #00f2fe;
  --warning: #f59e0b;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  font-family: var(--font);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100%;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: fixed; /* Evita rebotes de scroll elástico en iOS */
}

/* Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 50;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.5px;
}

.brand-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.4);
  border: 1px solid rgba(0, 242, 254, 0.3);
  flex-shrink: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.badge-uncensored {
  font-size: 0.65rem;
  text-transform: uppercase;
  background: rgba(0, 242, 254, 0.12);
  color: #00f2fe;
  border: 1px solid rgba(0, 242, 254, 0.35);
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
}
  font-weight: 600;
}

.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  cursor: pointer;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.sidebar-close-btn:hover,
.sidebar-close-btn:active {
  background: #21262d;
  color: var(--text-main);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.new-chat-btn {
  margin: 12px 14px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background-color: #21262d;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 42px;
}

.new-chat-btn:hover,
.new-chat-btn:active {
  background-color: #30363d;
  border-color: #8b949e;
}

.history-section {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 6px 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  min-height: 38px;
}

.conv-item:hover,
.conv-item:active {
  background-color: var(--bg-sidebar-hover);
}

.conv-item.active {
  background-color: #262c36;
  border: 1px solid #38434f;
}

.conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  padding-right: 8px;
}

.conv-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (hover: hover) {
  .conv-delete-btn {
    opacity: 0;
  }
  .conv-item:hover .conv-delete-btn {
    opacity: 1;
  }
}

.conv-delete-btn:hover,
.conv-delete-btn:active {
  color: var(--danger);
}

/* Usage Widget */
.sidebar-usage {
  margin: 6px 12px;
  padding: 12px;
  background: rgba(0, 246, 255, 0.05);
  border: 1px solid rgba(0, 246, 255, 0.2);
  border-radius: 10px;
}

.usage-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 6px;
  font-weight: 600;
}

.usage-bar-bg {
  width: 100%;
  height: 6px;
  background: #111422;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.usage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #00f2fe, #0088ff);
  transition: width 0.3s;
}

.upgrade-mini-btn {
  width: 100%;
  padding: 8px 10px;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.25);
  transition: all 0.2s;
  min-height: 34px;
}

.upgrade-mini-btn:hover,
.upgrade-mini-btn:active {
  box-shadow: 0 0 18px rgba(0, 242, 254, 0.45);
  filter: brightness(1.08);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.user-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #30363d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-accent);
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-plan-badge {
  font-size: 0.7rem;
  color: #58a6ff;
}

.user-plan-badge.premium {
  color: #f1e05a;
  font-weight: 600;
}

.auth-btn-group {
  display: flex;
  gap: 8px;
  width: 100%;
}

.auth-btn-group button {
  flex: 1;
  padding: 9px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
}

.btn-login {
  background: #21262d;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-register {
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  font-weight: 700;
  border: none;
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.3);
  transition: all 0.2s;
}

.btn-register:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 18px rgba(0, 242, 254, 0.5);
}

/* Main Chat Section */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  position: relative;
  background-color: var(--bg-main);
  overflow: hidden;
}

.chat-header {
  height: 56px;
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1.4rem;
  cursor: pointer;
  margin-right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
}

.mobile-menu-toggle:active {
  background: #21262d;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #21262d;
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}

.model-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
}

/* Indicador de Consumo Desplegable en el Chat */
.usage-dropdown {
  position: relative;
  display: inline-block;
}

.usage-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #161b22;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.usage-toggle-btn:hover,
.usage-toggle-btn.active {
  background: #21262d;
  border-color: #3b82f6;
}

.usage-live-dot {
  width: 7px;
  height: 7px;
  background-color: #3b82f6;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.usage-btn-badge {
  background: #21262d;
  border: 1px solid var(--border-color);
  color: #58a6ff;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

.usage-chevron {
  transition: transform 0.2s ease;
}

.usage-dropdown.open .usage-chevron {
  transform: rotate(180deg);
}

.usage-dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-width: 90vw;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
  z-index: 100;
  animation: panelSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.usage-dropdown.open .usage-dropdown-panel {
  display: block;
}

@keyframes panelSlideIn {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.usage-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.usage-panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f0f6fc;
}

.usage-panel-badge {
  background: #21262d;
  color: #c9d1d9;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.usage-bar-track {
  height: 8px;
  background: #21262d;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}

.usage-bar-indicator {
  height: 100%;
  background: #3b82f6;
  border-radius: 999px;
  transition: width 0.4s ease, background 0.3s ease;
}

.usage-renew-info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #8b949e;
  font-size: 0.8rem;
  line-height: 1.4;
}

.usage-renew-info svg {
  flex-shrink: 0;
  color: #8b949e;
}

.usage-panel-action {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #21262d;
}

.usage-upgrade-action-btn {
  background: none;
  border: none;
  color: #58a6ff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.usage-upgrade-action-btn:hover {
  text-decoration: underline;
  color: #79c0ff;
}

/* Sidebar Renew Row */
.sidebar-renew-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
  margin-bottom: 10px;
}

.usage-badge-pill {
  background: #21262d;
  color: #c9d1d9;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pricing-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 242, 254, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  min-height: 34px;
}

.pricing-btn:hover,
.pricing-btn:active {
  transform: translateY(-1px);
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.55);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 120px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-container-inner {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar-ai-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.message-row.assistant .message-avatar {
  background: #090a14;
  border: 1px solid rgba(0, 242, 254, 0.35);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
  padding: 1px;
}

.message-row.user .message-avatar {
  background: #191f33;
  color: var(--text-accent);
  border: 1px solid rgba(0, 242, 254, 0.2);
}

.message-bubble {
  max-width: 84%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.94rem;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message-row.assistant .message-bubble {
  background-color: var(--bg-chat-ai);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-top-left-radius: 3px;
}

.message-row.user .message-bubble {
  background-color: #262f3d;
  border: 1px solid #384b63;
  color: #fff;
  border-bottom-right-radius: 3px;
}

/* Markdown styling inside bubbles */
.message-bubble p {
  margin-bottom: 10px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble pre {
  background: #0d1117;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.84rem;
  max-width: 100%;
}
.message-bubble code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.85rem;
  background: rgba(110, 118, 129, 0.2);
  padding: 2px 5px;
  border-radius: 4px;
}
.message-bubble pre code {
  background: transparent;
  padding: 0;
}
.message-bubble ul, .message-bubble ol {
  margin-left: 20px;
  margin-bottom: 10px;
}
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 12px 0 6px;
  font-size: 1.15rem;
}

/* Typing animation */
.typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: #8b949e;
  border-radius: 50%;
  animation: pulse 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* AI Streaming Typewriter Cursor */
.ai-typing-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background-color: var(--accent, #00d2ff);
  margin-left: 3px;
  vertical-align: -2px;
  border-radius: 1px;
  animation: cursorBlink 0.75s infinite ease-in-out;
  box-shadow: 0 0 6px rgba(0, 210, 255, 0.7);
}

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

.message-bubble.is-typing {
  cursor: pointer;
  position: relative;
}

/* Empty State Greeting */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: auto 0;
  padding: 30px 16px;
}
.welcome-logo {
  width: 76px;
  height: 76px;
  background: transparent;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 0 30px rgba(0, 242, 254, 0.35);
}
.welcome-logo-img {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  object-fit: cover;
  border: 1px solid rgba(0, 242, 254, 0.45);
  box-shadow: 0 0 25px rgba(0, 242, 254, 0.35);
  animation: logoPulse 3s ease-in-out infinite alternate;
}
@keyframes logoPulse {
  0% { box-shadow: 0 0 15px rgba(0, 242, 254, 0.25); transform: scale(1); }
  100% { box-shadow: 0 0 35px rgba(0, 242, 254, 0.55); transform: scale(1.02); }
}
.welcome-title {
  font-size: 1.7rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}
.welcome-subtitle {
  color: var(--text-muted);
  max-width: 500px;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 24px;
}
.starter-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 680px;
}
.starter-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  padding: 12px 14px;
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.4;
}
.starter-card:hover,
.starter-card:active {
  background: var(--bg-sidebar-hover);
  border-color: #00f2fe;
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.15);
  transform: translateY(-1px);
}

/* Chat Input Bar */
.chat-input-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(5, 4, 12, 0) 0%, rgba(5, 4, 12, 0.96) 35%, var(--bg-main) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 20;
}

.input-wrapper {
  max-width: 820px;
  width: 100%;
  background: #0d0f1c;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.6);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
  border-color: #00f2fe;
  box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2), 0 0 20px rgba(0, 242, 254, 0.15);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px; /* 16px impide que Safari en iOS haga zoom involuntario */
  resize: none;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.4;
  padding: 4px 0;
}

.send-btn {
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.3);
}

.send-btn:hover:not(:disabled),
.send-btn:active:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.6);
}

.send-btn:disabled {
  background: #191e2e;
  color: #4b5563;
  box-shadow: none;
  cursor: not-allowed;
}

/* Modales */
.modal-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-card {
  background: #161b22;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px;
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
}

.modal-close:hover,
.modal-close:active {
  background: #21262d;
  color: var(--text-main);
}

.paywall-badge {
  display: inline-block;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  margin-bottom: 12px;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.3);
}

.paywall-title {
  font-size: 1.38rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.paywall-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 16px;
  line-height: 1.45;
}

.modal-card.modal-card-wide {
  max-width: 900px;
  width: 96%;
}

/* Rejilla de Planes de Suscripción */
.plans-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 16px;
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .plans-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

@media (max-width: 580px) {
  .plans-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.plan-cycle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 2px;
}

.plan-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.tag-pro {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.tag-unlimited {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.plan-card {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: transform 0.15s, border-color 0.15s;
}

.plan-card:hover {
  border-color: #3b82f6;
  transform: translateY(-2px);
}

.plan-card.featured {
  border: 2px solid #3b82f6;
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.08) 0%, #0d1117 100%);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.2);
}

.plan-card-header {
  margin-bottom: 16px;
}

.plan-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}

.plan-price {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 2px;
}

.plan-amount {
  font-size: 1.85rem;
  font-weight: 800;
  color: #fff;
}

.plan-subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.plan-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.86rem;
  margin-bottom: 20px;
  flex: 1;
}

.plan-features li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  line-height: 1.4;
}

.plan-features li span.check {
  color: #22c55e;
  font-weight: bold;
}

.plans-footnote {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 14px;
  line-height: 1.4;
}

.plan-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: #21262d;
  color: #fff;
  transition: all 0.15s ease;
  min-height: 38px;
}

/* Todos los botones de elección y compra de planes con el mismo estilo unificado */
.plan-btn.plan-choose-btn,
.btn-credits.plan-choose-btn {
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  border: none;
  color: #05040c;
  font-weight: 800;
  box-shadow: 0 0 14px rgba(0, 242, 254, 0.35);
  transition: all 0.15s ease;
}

.plan-btn.plan-choose-btn:hover,
.btn-credits.plan-choose-btn:hover {
  filter: brightness(1.12);
  box-shadow: 0 0 22px rgba(0, 242, 254, 0.6);
  transform: translateY(-1px);
}

.plan-btn.btn-current-plan {
  background: #161b22 !important;
  color: var(--text-muted) !important;
  cursor: default !important;
  border: 1px solid #21262d !important;
  box-shadow: none !important;
  transform: none !important;
  filter: none !important;
}

/* Tarjeta de Pack de Créditos Sueltos */
.credits-pack-card {
  background: rgba(0, 242, 254, 0.05);
  border: 1px solid rgba(0, 242, 254, 0.2);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.btn-credits {
  padding: 9px 18px;
  width: auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.price-tag {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 18px;
}

.price-amount {
  font-size: 2.1rem;
  font-weight: 800;
  color: #fff;
}

.price-period {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.features-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 20px;
}

.features-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-main);
}

.features-list li span.check {
  color: var(--success);
  font-weight: bold;
}

.pay-btn {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  border-radius: 10px;
  font-size: 0.98rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.4);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
}

.pay-btn:hover,
.pay-btn:active {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(0, 242, 254, 0.6);
}

.test-mode-note {
  margin-top: 14px;
  padding: 10px;
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.3);
  border-radius: 8px;
  font-size: 0.78rem;
  color: #e3b341;
  text-align: center;
}

/* Tarjeta de Límite de Contexto por Chat */
.context-limit-card {
  background: linear-gradient(180deg, rgba(0, 242, 254, 0.08) 0%, rgba(5, 4, 12, 0.95) 100%);
  border: 1px solid rgba(0, 242, 254, 0.35);
  border-radius: 14px;
  padding: 18px 20px;
  margin: 14px 0;
  box-shadow: 0 0 25px rgba(0, 242, 254, 0.15);
}

.context-limit-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.context-limit-icon {
  font-size: 1.3rem;
}

.context-limit-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
}

.context-limit-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-upgrade-chat {
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.35);
}

.btn-upgrade-chat:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 0 22px rgba(0, 242, 254, 0.55);
}

.btn-new-chat-free {
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-new-chat-free:hover {
  background: #30363d;
  color: #fff;
  border-color: #8b949e;
}

.simulate-btn {
  margin-top: 8px;
  width: 100%;
  padding: 9px;
  background: #21262d;
  color: #e3b341;
  border: 1px solid rgba(210, 153, 34, 0.4);
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  min-height: 38px;
}

/* Auth Tabs */
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 18px;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  min-height: 42px;
}

.auth-tab.active {
  color: var(--text-main);
  border-bottom-color: var(--primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.form-group input {
  background: #0d1117;
  border: 1px solid var(--border-color);
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--text-main);
  font-size: 16px; /* 16px evita zoom en iOS */
  outline: none;
  min-height: 44px;
}

.form-group input:focus {
  border-color: var(--primary);
}

.submit-auth-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #00f2fe, #0088ff);
  color: #05040c;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 6px;
  min-height: 44px;
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.35);
  transition: all 0.2s;
}

.submit-auth-btn:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 22px rgba(0, 242, 254, 0.55);
}

.auth-error {
  background: rgba(248, 81, 73, 0.15);
  color: #ff7b72;
  border: 1px solid rgba(248, 81, 73, 0.3);
  padding: 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-bottom: 14px;
  display: none;
}

/* ========================================================
   OPTIMIZACIÓN MÓVIL (Smartphones & Tablets)
   ======================================================== */
@media (max-width: 768px) {
  /* Sidebar como Cajón Deslizante Lateral */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 84vw;
    max-width: 310px;
    height: 100%;
    height: 100dvh;
    transform: translate3d(-100%, 0, 0);
    z-index: 90;
    box-shadow: 4px 0 28px rgba(0, 0, 0, 0.7);
    padding-top: env(safe-area-inset-top);
  }

  .sidebar.open {
    transform: translate3d(0, 0, 0);
  }

  .sidebar-backdrop {
    display: block;
  }

  .sidebar-close-btn {
    display: flex;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  /* Header Compacto */
  .chat-header {
    height: 52px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
  }

  .model-badge {
    padding: 4px 10px;
    font-size: 0.78rem;
  }

  .pricing-btn {
    padding: 6px 10px;
    font-size: 0.76rem;
  }

  /* Chat y Burbujas */
  .chat-messages {
    padding: 12px 10px calc(76px + env(safe-area-inset-bottom)) 10px;
    gap: 14px;
  }

  .chat-container-inner {
    gap: 14px;
  }

  .message-row {
    gap: 8px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.82rem;
    border-radius: 7px;
  }

  .message-bubble {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 0.92rem;
    line-height: 1.5;
    border-radius: 14px;
  }

  .message-bubble pre {
    font-size: 0.8rem;
    padding: 8px 10px;
    margin: 8px 0;
  }

  /* Barra de Entrada de Texto en Móvil */
  .chat-input-area {
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom)) 10px;
  }

  .input-wrapper {
    border-radius: 14px;
    padding: 6px 8px 6px 12px;
    gap: 8px;
  }

  #chat-input {
    font-size: 16px;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.35;
  }

  .send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  /* Pantalla de Bienvenida en Móvil */
  .welcome-container {
    padding: 16px 8px;
  }

  .welcome-logo {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    border-radius: 14px;
    margin-bottom: 12px;
  }

  .welcome-title {
    font-size: 1.45rem;
    margin-bottom: 6px;
  }

  .welcome-subtitle {
    font-size: 0.86rem;
    margin-bottom: 18px;
    padding: 0 4px;
  }

  .starter-prompts {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .starter-card {
    padding: 10px 12px;
    font-size: 0.82rem;
  }

  /* Modales en Móvil */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end; /* Efecto bottom-sheet natural en teléfonos */
  }

  .modal-card {
    max-height: 88dvh;
    border-radius: 20px 20px 14px 14px;
    padding: 20px 16px;
  }
}

/* Pantallas Extra Pequeñas (<= 380px) */
@media (max-width: 380px) {
  .brand {
    font-size: 1rem;
    gap: 8px;
  }

  .brand-icon {
    width: 28px;
    height: 28px;
    font-size: 0.95rem;
  }

  .model-badge {
    padding: 3px 8px;
    font-size: 0.72rem;
  }

  .pricing-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .message-bubble {
    max-width: 93%;
    font-size: 0.88rem;
  }
}
