/* ============================================
   Fórmula Dinero AI — Chat-first layout
   Faithful port of interface-FD-AI.html mockup.
   All classes prefixed fd-, tokens scoped to .fd-root
   so they don't leak into MudBlazor/Bootstrap.
   ============================================ */

.fd-root {
  --fd-azul: #155EEF;
  --fd-azul-deep: #0F172A;
  --fd-gris-oscuro: #1E293B;
  --fd-gris: #64748B;
  --fd-fondo: #F8FAFC;
  --fd-blanco: #FFFFFF;
  --fd-azul-soft: #E6EEFD;
  --fd-line: #E2E8F0;
  --fd-line-strong: #CBD5E1;
  --fd-text: #0F172A;
  --fd-text-soft: #64748B;

  --fd-radius-lg: 20px;
  --fd-radius-md: 14px;
  --fd-radius-sm: 10px;

  --fd-shadow-card: 0 1px 2px rgba(15,23,42,0.04), 0 12px 32px -16px rgba(15,23,42,0.16);

  font-family: 'Sora', system-ui, sans-serif;
  color: var(--fd-text);
  line-height: 1.5;

  /* Full-bleed across the MudContainer gutter + cancel the layout's mt-4,
     so the chat fills the content area cleanly (see CLAUDE.md /metas notes). */
  margin: -16px -16px 0;
}
@media (min-width: 600px) {
  .fd-root { margin: -16px -24px 0; }
}

.fd-root *, .fd-root *::before, .fd-root *::after { box-sizing: border-box; }
.fd-root button { font-family: inherit; }

.fd-app {
  display: grid;
  grid-template-columns: 280px 1fr;
  /* --xs-content-offset la define shell.css (topbar sticky del shell nuevo);
     fallback 80px = chrome MudBlazor viejo (64px appbar + 16px mt-4). */
  height: calc(100vh - var(--xs-content-offset, 80px));
  background: var(--fd-blanco);
  border-top: 1px solid var(--fd-line);
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}
.fd-app.fd-sidebar-collapsed { grid-template-columns: 0px 1fr; }

/* ============================================ Sidebar ============================================ */

.fd-sidebar {
  background: var(--fd-fondo);
  color: var(--fd-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
  border-right: 1px solid var(--fd-line);
  overflow: hidden;
  transition: padding 0.25s ease;
}
.fd-app.fd-sidebar-collapsed .fd-sidebar { padding: 0; border-right: none; }

.fd-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
}

.fd-brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.fd-brand-mark img { width: 100%; height: 100%; object-fit: contain; }

.fd-sidebar-toggle {
  border: none; background: var(--fd-blanco);
  width: 32px; height: 32px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--fd-text-soft); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.fd-sidebar-toggle:hover { background: var(--fd-azul-soft); color: var(--fd-azul); }
.fd-sidebar-toggle svg { width: 15px; height: 15px; }

.fd-new-chat-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 1px solid var(--fd-line-strong);
  background: var(--fd-blanco); color: var(--fd-text);
  border-radius: var(--fd-radius-sm);
  padding: 11px 14px; font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.fd-new-chat-btn:hover { background: var(--fd-azul-soft); border-color: var(--fd-azul); color: #1149C2; }
.fd-new-chat-btn svg { width: 15px; height: 15px; }

.fd-sidebar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--fd-blanco);
  border: 1px solid var(--fd-line);
  border-radius: var(--fd-radius-sm);
  padding: 9px 12px;
}
.fd-sidebar-search svg { width: 14px; height: 14px; color: var(--fd-text-soft); flex-shrink: 0; }
.fd-root .fd-sidebar-search input {
  background: none; border: none; outline: none;
  color: var(--fd-text); font-size: 13px; width: 100%;
}
.fd-sidebar-search input::placeholder { color: #94A3B8; }

.fd-history-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  padding-right: 2px; margin-right: -2px;
}
.fd-history-list::-webkit-scrollbar { width: 4px; }
.fd-history-list::-webkit-scrollbar-thumb { background: var(--fd-line-strong); border-radius: 4px; }

.fd-history-empty { font-size: 12.5px; color: var(--fd-text-soft); padding: 4px 8px; }

.fd-history-group-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--fd-text-soft);
  padding: 0 8px 8px;
}

.fd-history-group { display: flex; flex-direction: column; gap: 2px; }

.fd-history-item {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left;
  background: none; border: none;
  border-radius: var(--fd-radius-sm);
  padding: 9px 10px; cursor: pointer; color: var(--fd-text);
  transition: background 0.12s ease;
}
.fd-history-item:hover { background: var(--fd-blanco); }
.fd-history-item.fd-active { background: var(--fd-azul-soft); color: #1149C2; }

.fd-history-item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.fd-history-item-title {
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fd-history-item-preview {
  font-size: 11.5px; color: var(--fd-text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fd-history-item.fd-active .fd-history-item-preview { color: #1149C2; opacity: 0.7; }

.fd-history-del {
  border: none; background: none; cursor: pointer;
  color: var(--fd-text-soft); width: 24px; height: 24px;
  border-radius: 6px; display: none; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.fd-history-item:hover .fd-history-del { display: flex; }
.fd-history-del:hover { background: #FEE2E2; color: #DC2626; }
.fd-history-del svg { width: 13px; height: 13px; }

/* ============================================ Main area ============================================ */

.fd-main {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--xs-content-offset, 80px));
  min-width: 0; background: var(--fd-blanco);
}

.fd-main-header { display: flex; align-items: center; padding: 16px 24px; flex-shrink: 0; }
.fd-header-spacer { flex: 1; }

.fd-open-sidebar-btn {
  border: none; background: var(--fd-fondo);
  width: 32px; height: 32px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--fd-text-soft); cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, background 0.15s ease, color 0.15s ease;
}
.fd-open-sidebar-btn svg { width: 15px; height: 15px; }
.fd-open-sidebar-btn:hover { background: var(--fd-azul-soft); color: var(--fd-azul); }
.fd-app.fd-sidebar-collapsed .fd-open-sidebar-btn { opacity: 1; pointer-events: auto; }

/* ============================================ Welcome state ============================================ */

.fd-welcome {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 0 24px 60px; overflow-y: auto;
}
.fd-welcome-inner {
  max-width: 720px; width: 100%;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.fd-welcome-mark {
  width: 64px; height: 64px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px; overflow: hidden;
}
.fd-welcome-mark img { width: 100%; height: 100%; object-fit: contain; }
.fd-root .fd-welcome h1 {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: clamp(28px, 4vw, 38px); color: var(--fd-text);
  letter-spacing: -0.01em; margin-bottom: 8px;
}
.fd-welcome-sub { font-size: 15px; color: var(--fd-text-soft); margin-bottom: 32px; }

/* ---- Big composer ---- */
.fd-big-composer {
  width: 100%;
  border: 1.5px solid var(--fd-line-strong);
  border-radius: var(--fd-radius-lg);
  background: var(--fd-blanco);
  box-shadow: var(--fd-shadow-card);
  padding: 18px 18px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.fd-big-composer:focus-within {
  border-color: var(--fd-azul);
  box-shadow: 0 0 0 4px rgba(21,94,239,0.10), var(--fd-shadow-card);
}
.fd-root .fd-big-composer textarea {
  width: 100%; border: none; outline: none; resize: none;
  background: transparent; font-family: inherit; font-size: 16px;
  color: var(--fd-text); min-height: 28px; max-height: 160px; text-align: left;
}
.fd-big-composer textarea::placeholder { color: #94A3B8; }

.fd-big-composer-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px;
}

.fd-icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--fd-fondo); color: var(--fd-text-soft);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.fd-icon-btn svg { width: 17px; height: 17px; }
.fd-icon-btn:hover { background: var(--fd-azul-soft); color: var(--fd-azul); }
.fd-icon-btn.fd-send { background: var(--fd-azul); color: #fff; }
.fd-icon-btn.fd-send:hover { background: #1149C2; }
.fd-icon-btn:disabled { opacity: 0.5; cursor: default; }

/* ---- Suggestion chips ---- */
.fd-suggestion-row {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 28px;
}
.fd-suggestion-chip {
  border: 1px solid var(--fd-line-strong); background: var(--fd-blanco);
  border-radius: 100px; padding: 10px 18px; font-size: 13.5px; color: var(--fd-text);
  cursor: pointer; transition: all 0.15s ease;
  max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fd-suggestion-chip:hover { border-color: var(--fd-azul); color: var(--fd-azul); background: var(--fd-azul-soft); }

/* ============================================ Chat state ============================================ */

.fd-chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.fd-chat-scroll { flex: 1; overflow-y: auto; padding: 8px 24px 24px; }
.fd-chat-scroll::-webkit-scrollbar { width: 6px; }
.fd-chat-scroll::-webkit-scrollbar-thumb { background: var(--fd-line-strong); border-radius: 6px; }

.fd-chat-thread { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.fd-chat-msg { display: flex; gap: 12px; max-width: 100%; animation: fd-rise 0.25s ease; }
@keyframes fd-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.fd-chat-msg.fd-user { flex-direction: row-reverse; margin-left: auto; }

.fd-chat-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 12.5px; font-weight: 700;
  font-family: 'Space Grotesk', sans-serif;
}
.fd-chat-msg.fd-user .fd-chat-avatar { background: var(--fd-azul-soft); color: #1149C2; }
.fd-chat-msg.fd-bot .fd-chat-avatar { background: var(--fd-blanco); border: 1px solid var(--fd-line); overflow: hidden; }
.fd-chat-msg.fd-bot .fd-chat-avatar img { width: 100%; height: 100%; object-fit: contain; }

.fd-chat-bubble { border-radius: var(--fd-radius-md); padding: 13px 16px; font-size: 14.5px; line-height: 1.6; max-width: 540px; }
.fd-chat-msg.fd-user .fd-chat-bubble {
  background: var(--fd-azul); color: #fff;
  border-radius: var(--fd-radius-md) var(--fd-radius-md) 4px var(--fd-radius-md);
}
.fd-chat-msg.fd-bot .fd-chat-bubble {
  background: var(--fd-fondo); border: 1px solid var(--fd-line); color: var(--fd-text);
  border-radius: var(--fd-radius-md) var(--fd-radius-md) var(--fd-radius-md) 4px;
}
.fd-chat-bubble p { margin: 0 0 10px; }
.fd-chat-bubble p:last-child { margin-bottom: 0; }
.fd-chat-bubble ul { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 10px 0; padding: 0; }
.fd-chat-bubble li {
  display: flex; gap: 9px; font-size: 14px;
  background: var(--fd-blanco); border-radius: var(--fd-radius-sm); padding: 10px 12px;
}
.fd-chat-bubble li::before {
  content: ''; flex-shrink: 0; width: 6px; height: 6px; margin-top: 6px;
  border-radius: 50%; background: var(--fd-azul);
}

.fd-chat-meta { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.fd-chat-feedback { display: flex; gap: 6px; }
.fd-feedback-btn {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--fd-line-strong); background: var(--fd-blanco);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--fd-text-soft); transition: all 0.15s ease;
}
.fd-feedback-btn svg { width: 12px; height: 12px; }
.fd-feedback-btn:hover { border-color: var(--fd-azul); color: var(--fd-azul); }
.fd-feedback-btn.fd-active { background: var(--fd-azul); border-color: var(--fd-azul); color: #fff; }

/* ---- Typing indicator ---- */
.fd-chat-msg.fd-typing .fd-chat-bubble { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.fd-typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--fd-text-soft);
  animation: fd-typing-bounce 1.2s infinite ease-in-out;
}
.fd-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.fd-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes fd-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* ---- Follow-up suggestions ---- */
.fd-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; margin-left: 44px; }

/* ============================================ Composer (chat state) ============================================ */

.fd-composer { border-top: 1px solid var(--fd-line); background: var(--fd-blanco); padding: 16px 24px 18px; flex-shrink: 0; }
.fd-composer-field {
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  border: 1.5px solid var(--fd-line-strong); border-radius: var(--fd-radius-md);
  background: var(--fd-fondo); padding: 10px 10px 10px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.fd-composer-field:focus-within { border-color: var(--fd-azul); box-shadow: 0 0 0 4px rgba(21,94,239,0.10); background: var(--fd-blanco); }
.fd-root .fd-composer-field textarea {
  flex: 1; border: none; outline: none; background: transparent; resize: none;
  font-family: inherit; font-size: 14.5px; color: var(--fd-text); max-height: 140px; padding: 6px 0;
}
.fd-composer-field textarea::placeholder { color: #94A3B8; }

.fd-composer-send {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--fd-azul); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.fd-composer-send:hover { background: #1149C2; }
.fd-composer-send:active { transform: scale(0.95); }
.fd-composer-send:disabled { opacity: 0.5; cursor: default; }
.fd-composer-send svg { width: 16px; height: 16px; }

.fd-composer-mic {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: transparent; color: var(--fd-text-soft);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.fd-composer-mic:hover { background: var(--fd-azul-soft); color: var(--fd-azul); }
.fd-composer-mic:disabled { opacity: 0.5; cursor: default; }
.fd-composer-mic svg { width: 17px; height: 17px; }

/* Listening state (shared by welcome icon-btn and chat composer mic) */
.fd-mic-active { background: #FEE2E2 !important; color: #DC2626 !important; animation: fd-mic-pulse 1.2s infinite; }
@keyframes fd-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.35); }
  50% { box-shadow: 0 0 0 5px rgba(220,38,38,0); }
}

.fd-composer-hint { max-width: 720px; margin: 10px auto 0; font-size: 11.5px; color: var(--fd-text-soft); text-align: center; }

/* ============================================ Responsive ============================================ */

@media (max-width: 920px) {
  .fd-app { grid-template-columns: 1fr !important; }
  .fd-sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px;
    z-index: 1400; padding: 18px 14px;
    box-shadow: 0 0 0 9999px rgba(15,23,42,0.4);
  }
  .fd-app.fd-sidebar-collapsed .fd-sidebar { transform: translateX(-280px); box-shadow: none; padding: 18px 14px; }
  .fd-suggestions { margin-left: 0; }
}

@media (max-width: 560px) {
  .fd-main-header { padding: 14px 16px; }
  .fd-welcome { padding: 0 16px 40px; }
  .fd-chat-scroll { padding: 8px 16px 16px; }
  .fd-composer { padding: 12px 16px 14px; }
  .fd-chat-bubble { max-width: 100%; }
  .fd-suggestion-row { flex-direction: column; align-items: stretch; }
  .fd-suggestion-chip { white-space: normal; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .fd-chat-msg, .fd-typing-dot { animation: none !important; }
}
