/* ==============================================================
   chat2.css — Diseño profesional (oscuro/claro)
   Basado en GitHub y sistemas de diseño modernos.
   Mantiene todas las funcionalidades existentes.
   ============================================================== */

/* ---------- Variables y reset ---------- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

body.ui-theme {
  /* Oscuro profesional */
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2128;
  --panel-bg: rgba(255,255,255,.04);
  --panel-bg2: rgba(255,255,255,.02);
  --panel-solid: #161b22;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #f0f6fc;
  --text-soft: #8b949e;
  --text-strong: #f0f6fc;
  --accent: #58a6ff;
  --accent-2: #79c0ff;
  --accent-rgb: 88,166,255;
  --accent-glow: 0 0 12px rgba(var(--accent-rgb), .25);
  --danger: #f85149;
  --warn: #d29922;
  --ok: #3fb950;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ---------- Temas neón (mantenidos como acentos) ---------- */
body.ui-theme.theme-neon-green { --accent: #3fb950; --accent-2: #56d364; --accent-rgb: 63,185,80; }
body.ui-theme.theme-neon-blue  { --accent: #58a6ff; --accent-2: #79c0ff; --accent-rgb: 88,166,255; }
body.ui-theme.theme-neon-red   { --accent: #f85149; --accent-2: #ff7b72; --accent-rgb: 248,81,73; }
body.ui-theme.theme-neon-yellow{ --accent: #d29922; --accent-2: #e3b341; --accent-rgb: 210,153,34; }

/* ---------- Modo claro ---------- */
body.ui-theme.theme-light {
  --bg: #f6f8fa;
  --bg2: #ffffff;
  --bg3: #f3f4f6;
  --panel-bg: rgba(0,0,0,.02);
  --panel-bg2: rgba(0,0,0,.01);
  --panel-solid: #ffffff;
  --border: #d0d7de;
  --border-soft: #e1e4e8;
  --text: #24292f;
  --text-soft: #57606a;
  --text-strong: #24292f;
  --accent: #0969da;
  --accent-2: #1f7ce0;
  --accent-rgb: 9,105,218;
  --accent-glow: 0 0 12px rgba(var(--accent-rgb), .12);
  --danger: #cf222e;
  --warn: #9a6700;
  --ok: #1a7f37;
  --shadow: 0 8px 24px rgba(0,0,0,.08);
}

body.ui-theme {
  background: var(--bg) !important;
  color: var(--text) !important;
  font-family: var(--font-sans) !important;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Texto y enlaces ---------- */
body.ui-theme p, body.ui-theme div, body.ui-theme span,
body.ui-theme label, body.ui-theme li, body.ui-theme td,
body.ui-theme th { color: var(--text) !important; }
body.ui-theme .text-muted, body.ui-theme small,
body.ui-theme .form-text { color: var(--text-soft) !important; }
body.ui-theme h1, body.ui-theme h2, body.ui-theme h3,
body.ui-theme h4, body.ui-theme h5, body.ui-theme h6,
body.ui-theme strong, body.ui-theme b,
body.ui-theme .card-title, body.ui-theme .modal-title,
body.ui-theme .navbar-brand { color: var(--text-strong) !important; }
body.ui-theme a { color: var(--accent) !important; text-decoration: none; }
body.ui-theme a:hover { color: var(--accent-2) !important; text-decoration: underline; }

/* ---------- Navbar ---------- */
body.ui-theme .navbar {
  background: var(--bg2) !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  padding: .6rem 1rem;
}
body.ui-theme .navbar .nav-link,
body.ui-theme .navbar-brand { color: var(--text-strong) !important; }
body.ui-theme .navbar .nav-link:hover { color: var(--accent) !important; }
body.ui-theme .navbar .btn {
  background: var(--bg3) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
}

/* ---------- Tabs ---------- */
body.ui-theme .nav-tabs {
  border-bottom: 1px solid var(--border) !important;
}
body.ui-theme .nav-tabs .nav-link {
  background: transparent !important;
  color: var(--text-soft) !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: .6rem 1.2rem;
  font-weight: 500;
}
body.ui-theme .nav-tabs .nav-link:hover {
  color: var(--text-strong) !important;
  border-color: var(--border) var(--border) transparent !important;
}
body.ui-theme .nav-tabs .nav-link.active {
  background: var(--bg) !important;
  color: var(--text-strong) !important;
  border-color: var(--border) var(--border) var(--bg) !important;
}

/* ---------- Cards ---------- */
body.ui-theme .card {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}
body.ui-theme .card-header,
body.ui-theme .card-footer {
  background: var(--bg3) !important;
  border-color: var(--border) !important;
}

/* ---------- Botones ---------- */
body.ui-theme .btn,
body.ui-theme button {
  background: var(--bg3) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  transition: all .15s ease;
}
body.ui-theme .btn:hover,
body.ui-theme button:hover {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
body.ui-theme .btn-primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}
body.ui-theme .btn-primary:hover {
  background: var(--accent-2) !important;
  border-color: var(--accent-2) !important;
}
body.ui-theme .btn-outline-primary {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  background: transparent !important;
}
body.ui-theme .btn-outline-primary:hover {
  background: rgba(var(--accent-rgb), .1) !important;
}
body.ui-theme .btn-outline-danger {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}
body.ui-theme .btn-outline-danger:hover {
  background: rgba(248,81,73,.1) !important;
}
body.ui-theme .btn-outline-success {
  color: var(--ok) !important;
  border-color: var(--ok) !important;
}
body.ui-theme .btn-outline-success:hover {
  background: rgba(63,185,80,.1) !important;
}

/* ---------- Formularios ---------- */
body.ui-theme .form-control,
body.ui-theme select,
body.ui-theme textarea {
  background: var(--bg3) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
}
body.ui-theme .form-control:focus,
body.ui-theme select:focus,
body.ui-theme textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .2) !important;
}

/* ---------- Dropdowns ---------- */
body.ui-theme .dropdown-menu {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
}
body.ui-theme .dropdown-item {
  color: var(--text) !important;
}
body.ui-theme .dropdown-item:hover {
  background: rgba(var(--accent-rgb), .08) !important;
  color: var(--accent) !important;
}

/* ---------- Modales ---------- */
body.ui-theme .modal-content {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}
body.ui-theme .modal-header,
body.ui-theme .modal-footer {
  border-color: var(--border) !important;
}

/* ---------- Tablas ---------- */
body.ui-theme .table {
  background: transparent !important;
  color: var(--text) !important;
}
body.ui-theme .table thead th {
  background: var(--bg3) !important;
  color: var(--text-strong) !important;
  border-bottom: 2px solid var(--border) !important;
}
body.ui-theme .table td,
body.ui-theme .table th {
  border-color: var(--border) !important;
}
body.ui-theme .table-hover tbody tr:hover {
  background: rgba(var(--accent-rgb), .04) !important;
}

/* ---------- Badges ---------- */
body.ui-theme .badge {
  background: var(--bg3) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  font-weight: 500;
}
body.ui-theme .badge-success { background: rgba(63,185,80,.15) !important; color: var(--ok) !important; border-color: var(--ok) !important; }
body.ui-theme .badge-danger  { background: rgba(248,81,73,.15) !important; color: var(--danger) !important; border-color: var(--danger) !important; }
body.ui-theme .badge-warning { background: rgba(210,153,34,.15) !important; color: var(--warn) !important; border-color: var(--warn) !important; }
body.ui-theme .badge-info    { background: rgba(88,166,255,.15) !important; color: var(--accent) !important; border-color: var(--accent) !important; }

/* ---------- SIDEBAR ---------- */
.sidebar-panel {
  background: var(--bg2) !important;
  border-right: 1px solid var(--border) !important;
  padding: 1rem .75rem;
  height: calc(100vh - 56px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.sidebar-panel .accordion-section {
  background: var(--bg3) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
}
.sidebar-panel .accordion-header {
  padding: .6rem .8rem;
  font-weight: 600;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--text-strong) !important;
  border-bottom: 1px solid var(--border-soft) !important;
  background: var(--bg2) !important;
}
.sidebar-panel .accordion-header:hover {
  background: rgba(var(--accent-rgb), .06) !important;
}
.sidebar-panel .accordion-body {
  padding: .6rem .4rem;
  max-height: 240px;
  overflow-y: auto;
  font-size: .85rem;
}
.sidebar-panel .sb-item {
  padding: .4rem .6rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background .1s ease;
  color: var(--text) !important;
}
.sidebar-panel .sb-item:hover {
  background: rgba(var(--accent-rgb), .06) !important;
}
.sidebar-panel .sb-item.active {
  background: rgba(var(--accent-rgb), .15) !important;
  color: var(--accent) !important;
  font-weight: 500;
}
.sidebar-panel .project-group {
  margin-bottom: .5rem;
}
.sidebar-panel .project-session {
  padding-left: 1.2rem !important;
  font-size: .8rem;
  border-left: 2px solid var(--border) !important;
  margin-left: .4rem;
  margin-top: 2px;
}

/* ---------- CHAT ---------- */
#chat2Messages {
  flex: 1 1 auto;
  min-height: 0 !important;
  overflow-y: auto !important;
  background: var(--bg) !important;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
#chat2Messages .chat-msg {
  max-width: 85%;
  padding: .7rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border) !important;
  background: var(--bg2) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
#chat2Messages .chat-user {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: var(--bg3) !important;
  border-color: var(--border) !important;
}
#chat2Messages .chat-assistant {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: rgba(var(--accent-rgb), .06) !important;
  border-color: rgba(var(--accent-rgb), .25) !important;
}
/* Alineación explícita izquierda/derecha */
#chat2Messages .align-left {
  align-self: flex-start !important;
  margin-right: auto;
}
#chat2Messages .align-right {
  align-self: flex-end !important;
  margin-left: auto;
}
/* Header y contenido de mensajes */
.chat-msg .msg-header {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chat-msg .msg-content {
  line-height: 1.6;
  font-size: 0.9rem;
}
#chat2Messages .chat-md {
  line-height: 1.6;
  font-size: .9rem;
}
#chat2Messages .chat-md pre {
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: .8rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: .8rem;
}

/* Contenedor de bloques de código con botón de copiar */
.chat-code-wrapper {
  position: relative;
  margin: 0.5rem 0;
}

.chat-code-wrapper .chat-code-block {
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: 0.8rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin: 0;
}

.chat-code-wrapper .chat-code-copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
  z-index: 10;
}

.chat-code-wrapper .chat-code-copy-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.4);
}

.chat-code-wrapper .chat-code-copy-btn.copied {
  background: rgba(34, 197, 94, 0.8);
  border-color: rgba(34, 197, 94, 1);
}

.chat-code-wrapper .chat-code-copy-btn i {
  font-size: 0.7rem;
}

.chat-code-wrapper .chat-code-copy-btn span {
  white-space: nowrap;
}

#chat2Messages .chat-md code {
  font-family: var(--font-mono);
  background: var(--bg3) !important;
  padding: .1rem .3rem;
  border-radius: 4px;
  font-size: .85em;
}

/* ---------- Fuentes del proyecto ---------- */
#chat2SourcesPanel {
  background: var(--bg3) !important;
  border-bottom: 1px solid var(--border) !important;
  padding: .5rem 1rem;
}
#chat2SourcesList .list-group-item {
  background: transparent !important;
  border: none !important;
  padding: .2rem .4rem !important;
  font-size: .75rem;
}
#chat2SourcesList .list-group-item:hover {
  background: rgba(var(--accent-rgb), .04) !important;
}

/* ---------- Toasts ---------- */
.chat-toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-toast {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: .75rem 1rem;
  box-shadow: var(--shadow);
  min-width: 260px;
  max-width: 360px;
  color: var(--text) !important;
}
.chat-toast .ct-title {
  font-weight: 600;
  color: var(--text-strong) !important;
}
.chat-toast .ct-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: .3rem;
}
.chat-toast button {
  background: transparent !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px;
  padding: .15rem .6rem;
  font-size: .8rem;
  color: var(--text) !important;
}
.chat-toast button:hover {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ---------- Dashboard & Contexto ---------- */
#pane-Dashboard .card,
#pane-Contexto .card {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
}
#pane-Dashboard .card-header,
#pane-Contexto .card-header {
  background: var(--bg3) !important;
  border-bottom: 1px solid var(--border) !important;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

/* ---------- Ajustes para modo claro ---------- */
body.ui-theme.theme-light .sidebar-panel { background: #ffffff !important; border-right: 1px solid #d0d7de !important; }
body.ui-theme.theme-light .chat-header { background: #ffffff !important; box-shadow: 0 1px 0 rgba(16,24,40,.04); }
body.ui-theme.theme-light .card { box-shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 0 rgba(16,24,40,.03); }
body.ui-theme.theme-light #chat2Messages .chat-msg { box-shadow: 0 1px 2px rgba(16,24,40,.06); }
body.ui-theme.theme-light .btn-new-session { box-shadow: 0 4px 14px rgba(9,105,218,.18); }
body.ui-theme.theme-light .user-avatar { box-shadow: 0 2px 6px rgba(9,105,218,.25); }
body.ui-theme.theme-light .chat-toast { background: #ffffff !important; border-color: #d0d7de !important; box-shadow: 0 8px 24px rgba(16,24,40,.12); }

/* Layout y acciones de mensaje se resuelven de forma autoritativa en
   design-system.css (Responsive Shell V3). Se retiraron aquí los parches
   históricos duplicados para evitar reglas de altura/footer en conflicto. */

/* Bloque de instrucciones */
.chat-instruction-block {
  background: rgba(255, 193, 7, 0.1) !important;
  border-left: 3px solid #ffc107 !important;
  padding: 8px !important;
  margin: 8px 0 !important;
  border-radius: 4px !important;
  font-style: italic;
}
