/* ==============================================================
   Asistente PIE - Sistema de Diseño y Tokens Visuales
   Desarrollado por Carlos Díaz
   Soporte completo de Modo Claro / Modo Oscuro de Alto Contraste
   ============================================================== */

:root,
[data-theme="light"],
html:not([data-theme="dark"]) {
  /* Paleta Base - Modo Claro de Alto Contraste */
  --bg-app: #edf3ee;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f4f8f5;
  --bg-sidebar: #ffffff;
  --modal-bg: #ffffff;
  --modal-backdrop: rgba(10, 24, 18, 0.75);
  
  --border-color: #8daea0;
  --border-light: #c2d8cd;
  --border-focus: #145934;
  
  --text-main: #0c2426;
  --text-muted: #385154;
  --text-light: #526f72;
  
  --accent-primary: #155e37;
  --accent-hover: #0d4226;
  --accent-light: #dff0e3;
  --accent-subtle: #edf7ef;
  --accent-badge: #114a2b;
  
  --msg-user-bg: #155e37;
  --msg-user-text: #ffffff;
  --msg-asst-bg: #ffffff;
  --msg-asst-border: #8daea0;
  
  --sources-bg: #f4f9f5;
  --sources-border: #8daea0;
  
  --code-bg: #f0f5f2;
  --code-border: #8daea0;
  
  --card-shadow: 0 2px 10px rgba(12, 36, 38, 0.08);
  --card-shadow-hover: 0 10px 30px rgba(12, 36, 38, 0.16);
  
  color-scheme: light;
}

:root[data-theme="dark"],
html[data-theme="dark"],
html.dark,
body[data-theme="dark"],
body.dark,
[data-theme="dark"] {
  /* Paleta Base - Modo Oscuro de Alto Contraste */
  --bg-app: #0c1413;
  --bg-surface: #142220;
  --bg-surface-alt: #1a2d2a;
  --bg-sidebar: #142220;
  --modal-bg: #142220;
  --modal-backdrop: rgba(0, 0, 0, 0.88);
  
  --border-color: #3d685c;
  --border-light: #2c4d44;
  --border-focus: #10b981;
  
  --text-main: #f3f9f7;
  --text-muted: #a8ccc4;
  --text-light: #7da89f;
  
  --accent-primary: #10b981;
  --accent-hover: #059669;
  --accent-light: #183d34;
  --accent-subtle: #19352e;
  --accent-badge: #4ade80;
  
  --msg-user-bg: #0c6957;
  --msg-user-text: #ffffff;
  --msg-asst-bg: #162624;
  --msg-asst-border: #3d685c;
  
  --sources-bg: #182b28;
  --sources-border: #3d685c;
  
  --code-bg: #0d1a18;
  --code-border: #3d685c;
  
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.60);
  --card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.80);
  
  color-scheme: dark;
}

/* Reset y Base */
* {
  box-sizing: border-box;
}

html, body {
  background-color: var(--bg-app);
  color: var(--text-main);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars refinados y visibles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}

/* Botón Conmutador de Tema */
.btn-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}
.btn-theme-toggle:hover {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

/* Modales Opacos (100% Sin Transparencia) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-backdrop);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-content {
  background: var(--modal-bg) !important;
  background-color: var(--modal-bg) !important;
  border: 2px solid var(--border-color) !important;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5) !important;
  color: var(--text-main) !important;
  padding: 24px;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  position: relative;
  z-index: 2001;
  opacity: 1 !important;
}

/* Chips de Citas RAG Interactivas */
.rag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1.5px solid var(--border-color);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.18s ease;
  user-select: none;
}
.rag-chip:hover {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-badge);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
.rag-chip-icon {
  font-size: 13px;
}

/* Bloques de Código */
pre.code-block {
  background: var(--code-bg);
  border: 1.5px solid var(--code-border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  position: relative;
  margin: 10px 0;
  color: var(--text-main);
}
pre.code-block .btn-code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
pre.code-block .btn-code-copy:hover {
  border-color: var(--accent-primary);
  color: var(--text-main);
}

code.inline-code {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--accent-badge);
}

/* Tablas Markdown */
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border-color);
  background: var(--bg-surface);
}
.md-table th, .md-table td {
  padding: 9px 12px;
  border-bottom: 1.5px solid var(--border-color);
  text-align: left;
}
.md-table th {
  background: var(--bg-surface-alt);
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 2px solid var(--border-color);
}
.md-table tr:hover td {
  background: var(--accent-subtle);
}

/* Citas en Bloque */
blockquote.md-quote {
  margin: 10px 0;
  padding: 10px 14px;
  border-left: 4px solid var(--accent-primary);
  border: 1px solid var(--border-light);
  border-left-width: 4px;
  background: var(--bg-surface-alt);
  border-radius: 0 8px 8px 0;
  color: var(--text-main);
  font-style: italic;
}
