/* ==========================================================================
   Paleta neomorfista -- mismos valores que src/theme/palette.js del
   frontend anterior (React Native), para mantener la identidad visual.
   ========================================================================== */

:root,
[data-theme="light"] {
  --background: #E4E9F2;
  --surface: #E4E9F2;
  --shadow-light: #FFFFFF;
  --shadow-dark: #A3B1C6;
  --text-primary: #2E3440;
  --text-secondary: #7B8794;
  --accent-from: #7F5AF0;
  --accent-to: #4F8EF7;
  --accent-solid: #6C63FF;
  --accent-text: #FFFFFF;
  --online: #2ED573;
  --offline: #FF6B6B;
}

[data-theme="dark"] {
  --background: #1E2128;
  --surface: #1E2128;
  --shadow-light: #2A2E38;
  --shadow-dark: #121418;
  --text-primary: #ECEFF4;
  --text-secondary: #8891A3;
  --accent-from: #8A7CFF;
  --accent-to: #5AC8FA;
  --accent-solid: #8A7CFF;
  --accent-text: #12141A;
  --online: #32E875;
  --offline: #FF7B7B;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background: var(--background);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color .25s ease, color .25s ease;
}

button, textarea, input {
  font-family: inherit;
}

/* ============ Superficie neomorfista genérica ============ */
.neu {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 7px 7px 14px var(--shadow-dark), -7px -7px 14px var(--shadow-light);
  transition: box-shadow .2s ease, background-color .25s ease;
  border: none;
}

.neu-pressed {
  box-shadow: inset 5px 5px 10px var(--shadow-dark), inset -5px -5px 10px var(--shadow-light);
}

.icon-accent { color: var(--accent-solid); }

/* ============ Layout general ============ */
.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* ============ Header ============ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  gap: 12px;
}

.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.neu-logo {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.header-title-block { min-width: 0; }
.header-title { font-size: 16px; font-weight: 700; margin: 0; line-height: 1.2; }

.status-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-secondary); opacity: .5;
  transition: background-color .2s ease, opacity .2s ease;
}
.status-dot.online { background: var(--online); opacity: 1; }
.status-dot.offline { background: var(--offline); opacity: 1; }
.status-text { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
}
.icon-btn:active { box-shadow: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light); }
#theme-btn svg, #theme-btn { color: var(--accent-solid); }
#theme-icon { transition: transform .4s ease; }
#theme-btn.spin #theme-icon { transform: rotate(180deg); }

/* ============ Quota bar ============ */
.quota-bar {
  margin: 0 20px 12px;
  padding: 12px 16px;
  font-size: 12px;
}
.quota-row { display: flex; gap: 18px; }
.quota-item { flex: 1; min-width: 0; }
.quota-label { color: var(--text-secondary); font-size: 11px; display: block; margin-bottom: 4px; }
.quota-track {
  height: 6px; border-radius: 4px; overflow: hidden;
  background: var(--shadow-dark); opacity: .5; margin-bottom: 4px;
}
.quota-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-from), var(--accent-to));
  transition: width .4s ease;
}
.quota-value { color: var(--text-primary); font-size: 11px; font-variant-numeric: tabular-nums; }
.quota-meta { margin-top: 8px; color: var(--text-secondary); font-size: 11px; }

/* ============ Chat / mensajes ============ */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 8px;
  -webkit-overflow-scrolling: touch;
}

.messages { list-style: none; margin: 0; padding: 0; }

.msg-row { display: flex; padding: 6px 16px; }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant, .msg-row.error { justify-content: flex-start; }

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble.user {
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: var(--accent-text);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 7px 7px 14px var(--shadow-dark), -7px -7px 14px var(--shadow-light);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  background: var(--surface);
  color: var(--offline);
  box-shadow: 7px 7px 14px var(--shadow-dark), -7px -7px 14px var(--shadow-light);
  border: 1px solid var(--offline);
  border-bottom-left-radius: 4px;
}

.bubble code {
  background: rgba(127,127,127,.16);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.bubble pre {
  background: rgba(127,127,127,.16);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 6px 0;
}
.bubble pre code { background: none; padding: 0; }

.bubble a { color: inherit; text-decoration: underline; }

.msg-model {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 6px;
  opacity: .8;
}

/* ============ Empty state ============ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 32px;
  gap: 10px;
}
.empty-icon {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-solid);
  margin-bottom: 4px;
}
.empty-state p { margin: 0; font-size: 14px; }
.empty-hint { font-size: 12px !important; max-width: 320px; }

/* ============ Typing indicator ============ */
.typing-row { padding: 6px 16px; display: flex; justify-content: flex-start; }
.typing-bubble {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 18px; border-radius: 18px;
}
.typing-bubble .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-secondary);
  animation: bounce 1.1s infinite ease-in-out;
}
.typing-bubble .dot:nth-child(2) { animation-delay: .15s; }
.typing-bubble .dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .6; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ============ Composer ============ */
.composer { padding: 8px 16px 14px; }
.chat-form { display: flex; align-items: flex-end; gap: 10px; }

.input-wrapper {
  flex: 1;
  padding: 10px 16px;
  border-radius: 24px;
  min-height: 46px;
  display: flex;
  align-items: center;
}

#input-message {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.4;
  max-height: 120px;
  padding: 4px 0;
}
#input-message::placeholder { color: var(--text-secondary); }

.send-btn {
  width: 46px; height: 46px; border-radius: 23px;
  border: none; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity .15s ease, transform .1s ease;
}
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.send-btn:not(:disabled):active { transform: scale(.94); }

.composer-hint {
  margin: 8px 4px 0;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}
.composer-hint code {
  background: rgba(127,127,127,.16);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 10.5px;
}

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 20;
}
.modal-panel {
  width: 100%; max-width: 320px;
  padding: 22px 20px;
}
.modal-panel h2 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }

.option-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: none; border: none;
  padding: 12px 4px;
  font-size: 14px; font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.option-row.option-danger { color: var(--offline); }
.option-row.option-danger svg { color: var(--offline); }

.option-detail {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 0 4px 6px 32px;
  white-space: pre-line;
}
.option-detail:empty { display: none; }

.modal-close {
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 14px;
  background: rgba(127,127,127,.14);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--offline);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
  z-index: 30;
  max-width: 90%;
  text-align: center;
}

/* ============ Scrollbar discreta ============ */
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: var(--shadow-dark); border-radius: 3px; }

@media (max-width: 420px) {
  .header { padding: 14px 14px 10px; }
  .quota-bar { margin-left: 14px; margin-right: 14px; }
  .composer { padding: 6px 10px 12px; }
  .bubble { max-width: 88%; }
}
