*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-elevated: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --error: #f85149;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Pantalla de login — diseño moderno */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1000;
  padding: 1.5rem;
}

.login-screen[hidden] {
  display: none;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(88, 166, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(88, 166, 255, 0.06), transparent);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03),
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 12px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.login-card-inner {
  padding: 2.25rem 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo {
  display: block;
  max-width: 140px;
  width: 100%;
  height: auto;
  margin: 0 auto 1.25rem;
  object-fit: contain;
  mix-blend-mode: lighten;
}

.login-title {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-subtitle {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.login-form .form-row {
  margin-bottom: 1.25rem;
  width: 100%;
  min-width: 0;
}

.login-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  padding: 0 1rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.25;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.login-form input:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.login-error {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--error);
  background: rgba(248, 81, 73, 0.1);
  border-radius: 8px;
  min-height: 1.25rem;
}

.login-error:empty {
  display: none;
}

.login-submit-btn {
  margin-top: 0.25rem;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.login-submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(88, 166, 255, 0.35);
}

.login-google-wrap {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.login-divider {
  text-align: center;
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.login-divider span {
  padding: 0 0.75rem;
  background: var(--surface);
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #3c4043;
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  text-decoration: none;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.btn-google:hover {
  background: #f8f9fa;
  border-color: #dadce0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn-google:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.btn-google-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-google .btn-google-icon svg {
  display: block;
}

@media (max-width: 420px) {
  .login-card-inner {
    padding: 1.75rem 1.5rem;
  }
  .login-title {
    font-size: 1.5rem;
  }
}

.btn-block {
  width: 100%;
}

/* Layout tipo ChatGPT: barra lateral izq + contenido principal */
.app-layout {
  display: flex;
  min-height: 100vh;
  height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .site-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sidebar-header .subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.sidebar-nav {
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-tab,
.tab-btn.sidebar-tab {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.sidebar-tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-tab.active .sidebar-tab-icon {
  opacity: 1;
}

.sidebar-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-tab.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
  border-left-color: var(--accent);
}

.sidebar-chats {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.sidebar-new-chat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1.25rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.sidebar-new-chat:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.06);
}

.sidebar-chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-chat-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1.25rem;
  font-size: 0.85rem;
  text-align: left;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s, background 0.15s;
}

.sidebar-chat-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-chat-item.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
}

.sidebar-logout-wrap {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.5rem 0.6rem;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-info::before {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--error);
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.sidebar-logout-btn:hover {
  color: #fff;
  background: var(--error);
  border-color: var(--error);
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 1rem 1.25rem 1.25rem;
  text-align: center;
  background: transparent;
}

.sidebar-logo {
  display: block;
  max-width: 140px;
  width: 100%;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  background: transparent;
  mix-blend-mode: lighten;
}

.sidebar-close {
  display: none;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.sidebar-close:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-toggle:hover {
  background: var(--surface-elevated);
}

.main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 1.5rem 1.25rem 2rem;
  background: var(--bg);
}

.tab-panels {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

#panel-consultar.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}


#panel-consultar.active:has(.chat-expanded) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#panel-consultar .chat-agent-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  overflow: hidden;
}

.site-title {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tabs-nav {
  display: flex;
  gap: 0;
  margin-top: 1.5rem;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px 10px 0 0;
  overflow: hidden;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.tab-btn.active {
  color: var(--accent);
  background: var(--surface-elevated);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  padding: 1.5rem;
  animation: tabIn 0.2s ease;
}

.tab-panel.active {
  display: block;
}

@keyframes tabIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin: 0;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.upload-form,
.ask-form .form-row + .form-row {
  margin-top: 0;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-row select,
.form-row input[type="text"] {
  max-width: 280px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}


.form-row select:focus,
.form-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Login: ambos campos al mismo ancho (anular max-width de .form-row input) */
.login-form .form-row input[type="text"],
.login-form .form-row input[type="password"] {
  max-width: 100%;
}

.optional-fields input::placeholder {
  color: var(--text-muted);
}

.file-label {
  display: block;
  cursor: pointer;
}

.file-label input[type="file"] {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.file-label-text {
  display: inline-block;
  margin-right: 0.5rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.file-list {
  min-height: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.file-list span {
  display: block;
  margin-bottom: 0.25rem;
}

/* ----- Formulario de ingesta: estilo moderno ----- */
.ingest-card {
  border-radius: 14px;
  padding: 1.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.ingest-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.ingest-title {
  margin: 0 0 0.4rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.ingest-hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.ingest-form {
  gap: 1.5rem;
}

.ingest-defaults {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin: 0;
  background: rgba(0, 0, 0, 0.15);
}

.ingest-legend {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  padding: 0 0.5rem;
  margin-bottom: 0.25rem;
}

.ingest-defaults-hint {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.ingest-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
  margin-bottom: 1rem;
}

.ingest-fields-grid .form-row select,
.ingest-fields-grid .form-row input[type="text"] {
  max-width: 100%;
}

.ingest-apply-btn {
  margin-top: 0.25rem;
}

.ingest-upload-zone-wrap {
  margin: 0;
}

.ingest-file-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 140px;
  padding: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: rgba(88, 166, 255, 0.04);
  transition: border-color 0.2s, background 0.2s;
}

.ingest-file-label:hover {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
}

.ingest-file-label .file-label-icon {
  font-size: 2rem;
  opacity: 0.8;
}

.ingest-file-label .file-label-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
}

.ingest-file-label .file-label-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ingest-file-label input[type="file"] {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.ingest-actions {
  margin-top: 0.5rem;
}

.ingest-submit-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  min-height: 48px;
}

.ingest-card #upload-status {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.ingest-card #upload-status.success {
  background: rgba(63, 185, 80, 0.12);
  border: 1px solid rgba(63, 185, 80, 0.3);
  color: var(--success);
}

.ingest-card #upload-status.error {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.3);
  color: var(--error);
}

.file-classification-list {
  margin: 0;
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.1);
}

@media (max-width: 640px) {
  .ingest-card {
    padding: 1.25rem;
  }
  .ingest-fields-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .ingest-file-label {
    min-height: 120px;
    padding: 1.25rem;
  }
}

.file-classification-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.file-classification-table th,
.file-classification-table td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.file-classification-table th {
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.file-classification-table .file-row-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-classification-table .file-row-tipo,
.file-classification-table .file-row-categoria,
.file-classification-table .file-row-fecha,
.file-classification-table .file-row-sistema {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.file-classification-table .file-row-tipo:focus,
.file-classification-table .file-row-categoria:focus,
.file-classification-table .file-row-fecha:focus,
.file-classification-table .file-row-sistema:focus {
  outline: none;
  border-color: var(--accent);
}

#apply-defaults-btn {
  margin-top: 0.5rem;
}

.btn {
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  align-self: flex-start;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-google.btn-block {
  box-sizing: border-box;
}

.status {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.status.success {
  background: rgba(63, 185, 80, 0.15);
  color: var(--success);
}

.status.error {
  background: rgba(248, 81, 73, 0.15);
  color: var(--error);
}

.status.info {
  color: var(--text-muted);
}

.links {
  margin: 0;
  padding: 0;
  list-style: none;
}

.links a {
  color: var(--accent);
  text-decoration: none;
}

.links a:hover {
  text-decoration: underline;
}

.links li + li {
  margin-top: 0.5rem;
}

/* Consultar documentos */
.ask-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ask-form textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

.ask-form textarea::placeholder {
  color: var(--text-muted);
}

.ask-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.recent-queries-block[hidden] {
  display: none;
}

.recent-queries-block {
  margin-bottom: 0.5rem;
}

.recent-queries-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.recent-queries-summary {
  padding: 0.5rem 0.65rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
}

.recent-queries-summary::-webkit-details-marker {
  display: none;
}

.recent-queries-summary::before {
  content: "▶ ";
  font-size: 0.65rem;
  margin-right: 0.35rem;
}

.recent-queries-details[open] .recent-queries-summary::before {
  content: "▼ ";
}

.recent-queries-list {
  margin: 0;
  padding: 0.35rem 0 0.65rem;
  list-style: none;
  max-height: 12rem;
  overflow-y: auto;
}

.recent-query-item {
  margin: 0;
  padding: 0;
}

.recent-query-btn {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  text-align: left;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-query-btn:hover {
  background: rgba(88, 166, 255, 0.1);
  color: var(--accent-hover);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ask-result {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.ask-result[hidden] {
  display: none;
}

.chat-card {
  display: flex;
  flex-direction: column;
  max-height: 75vh;
}

.chat-card .chat-hint {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.chat-area {
  flex: 1 1 auto;
  min-height: 200px;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
}

.chat-status {
  margin: 0 0.75rem 0.5rem;
}

.chat-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-empty.chat-welcome {
  padding: 3rem 1.5rem 2rem;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--text);
  font-weight: 500;
}

.chat-agent-card:not(.chat-expanded) .chat-agent-area {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  padding: 0;
}

.chat-agent-card .chat-agent-area {
  flex: 1;
  min-height: 0;
  background: transparent;
}

.chat-agent-card.chat-expanded .chat-agent-area {
  background: transparent;
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-agent-card.chat-expanded .chat-agent-area::-webkit-scrollbar {
  width: 8px;
}

.chat-agent-card.chat-expanded .chat-agent-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-agent-card.chat-expanded .chat-agent-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.chat-agent-card.chat-expanded .chat-agent-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.chat-agent-card:not(.chat-expanded) .chat-welcome {
  margin-bottom: 0;
  padding-bottom: 0.25rem;
}

.chat-agent-card:not(.chat-expanded) .chat-agent-area .chat-empty {
  padding-bottom: 0.25rem;
}

.chat-agent-card:not(.chat-expanded) .chat-input-wrap {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.chat-agent-area .chat-empty {
  padding: 2.5rem 1rem;
}

.chat-empty[hidden] {
  display: none;
}

.chat-input-wrap {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.chat-options {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.chat-options summary {
  cursor: pointer;
  color: var(--text-muted);
}

.chat-form textarea {
  width: 100%;
  margin-bottom: 0.5rem;
  resize: vertical;
  min-height: 72px;
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.conversation-thread {
  padding: 0 0.75rem;
}

/* Chat tipo agente (estilo ChatGPT) */
.chat-agent-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-agent-card.chat-expanded,
.chat-agent-card:not(.chat-expanded) {
  flex: 1;
  min-height: 0;
}

.chat-agent-card.chat-expanded .chat-agent-area {
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
}

.chat-agent-area {
  padding: 1rem 0;
  min-height: 120px;
}

.chat-agent-thread {
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chat-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 85%;
}

.chat-msg-user-wrap {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-assistant-wrap {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-msg-role {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-msg {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg-user {
  background: rgba(88, 166, 255, 0.2);
  color: var(--text);
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
  background: transparent;
  color: var(--text);
  border: none;
  border-bottom-left-radius: 4px;
}

.chat-msg-body {
  margin: 0;
}

.chat-msg-sources {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-msg-sources-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.chat-msg-citas {
  margin-top: 0.75rem;
}

/* Bloque colapsado: documentación y fragmentos ocultos por defecto */
.chat-msg-doc-toggle {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.chat-msg-doc-summary {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.chat-msg-doc-summary::-webkit-details-marker {
  display: none;
}

.chat-msg-doc-summary::before {
  content: "▶ ";
  font-size: 0.65rem;
  margin-right: 0.35rem;
  color: var(--text-muted);
}

.chat-msg-doc-toggle[open] .chat-msg-doc-summary::before {
  content: "▼ ";
}

.chat-msg-doc-content {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.chat-msg-doc-content .chat-msg-sources {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.chat-msg-doc-content .chat-msg-citas {
  margin-top: 0.75rem;
}

/* Prompt estilo ChatGPT: caja redondeada única con sombra */
.chat-agent-form .chat-agent-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  margin-bottom: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-agent-form .chat-agent-input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(88, 166, 255, 0.2);
}

.chat-agent-form .chat-agent-input-bar textarea {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  margin: 0;
  padding: 0.65rem 0.25rem 0.65rem 0;
  border: none;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
}

.chat-agent-form .chat-agent-input-bar textarea::placeholder {
  color: var(--text-muted);
}

.chat-agent-form .chat-agent-input-bar textarea:focus {
  outline: none;
}

/* Botón enviar tipo ChatGPT: círculo con flecha */
.chat-send-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  margin-bottom: 0.15rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat-send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-icon {
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 700;
}

.chat-agent-actions {
  margin-top: 0;
}

.conversation-turn {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.conversation-turn:last-child {
  border-bottom: none;
}

.turn-question {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.35rem;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0.5rem 0.75rem;
  background: rgba(88, 166, 255, 0.08);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.turn-answer {
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  margin-left: 0.5rem;
}

.conversation-turn .turn-sources {
  margin-top: 1rem;
}

.conversation-turn .sources-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.conversation-turn .citas-details {
  margin-top: 0.75rem;
}

.btn-sm {
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
}

.result-title,
.sources-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sources-title {
  margin-top: 1rem;
}

.answer-content {
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.sources-block[hidden] {
  display: none;
}

.sources-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sources-list a {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  color: var(--accent);
  background: rgba(88, 166, 255, 0.12);
  border-radius: 6px;
  text-decoration: none;
}

.sources-list a:hover {
  background: rgba(88, 166, 255, 0.2);
  text-decoration: none;
}

.citas-block[hidden] {
  display: none;
}

.citas-block {
  margin-top: 1rem;
}

.citas-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.citas-summary {
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
}

.citas-summary::-webkit-details-marker {
  display: none;
}

.citas-summary::before {
  content: "▶ ";
  font-size: 0.7rem;
  margin-right: 0.35rem;
}

.citas-details[open] .citas-summary::before {
  content: "▼ ";
}

.citas-content {
  padding: 0 0.75rem 0.75rem;
  max-height: 20rem;
  overflow-y: auto;
}

.cita-item {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.cita-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.cita-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.cita-text {
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  background: var(--bg);
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border-left: 3px solid var(--border);
}

/* Resumen y filtros Documentos */
.docs-summary {
  margin-bottom: 1rem;
}

.summary-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.summary-card {
  padding: 0.5rem 0.75rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4rem;
}

.summary-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.summary-fecha {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.summary-error {
  margin: 0;
  color: var(--error);
  font-size: 0.9rem;
}

.docs-filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  align-items: end;
  gap: 0 1rem;
  margin-bottom: 1rem;
}

.docs-filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.docs-filter-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.docs-filter-group select {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.docs-filter-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.docs-filter-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.15rem;
}

/* Documentos ingestados – grilla */
.docs-grid-wrap {
  margin: 0 0 1rem;
  overflow-x: auto;
}

.docs-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.docs-grid th,
.docs-grid td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.docs-grid th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  white-space: nowrap;
}

.docs-grid tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.docs-grid-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.docs-grid-fecha,
.docs-grid-tipo,
.docs-grid-sistema {
  color: var(--text-muted);
  white-space: nowrap;
}

.docs-grid-actions {
  white-space: nowrap;
}

.docs-grid-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 1rem 0;
  margin: 0;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}

.btn-danger {
  background: rgba(248, 81, 73, 0.2);
  color: var(--error);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 81, 73, 0.35);
}

.btn-sm {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

/* ========== Responsive ========== */

/* Sidebar responsive: colapsable en tablet/móvil */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }

  .app-layout.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
  }

  .app-layout.sidebar-open .sidebar-overlay {
    display: block;
  }

  .main-content {
    padding-top: 5rem;
  }
}

@media (max-width: 640px) {
  .main-content {
    max-width: 100%;
    padding: 1rem 0.75rem 1.5rem;
    padding-top: 4.5rem;
  }

  .sidebar-header .site-title {
    font-size: 1.2rem;
  }

  .sidebar-header .subtitle {
    font-size: 0.75rem;
  }

  .sidebar-tab {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }

  .tab-panels {
    min-height: 280px;
    border-radius: 0 0 8px 8px;
  }

  .tab-panel {
    padding: 1rem 0.75rem;
  }

  .tab-panel.active {
    padding: 1rem 0.75rem;
  }

  .card {
    padding: 1rem 0.75rem;
    border-radius: 8px;
  }

  .card h2 {
    font-size: 1.05rem;
  }

  .hint,
  .chat-hint {
    font-size: 0.8rem;
  }

  .form-row select,
  .form-row input[type="text"] {
    max-width: 100%;
    font-size: 16px;
  }

  .file-classification-table {
    min-width: 480px;
    font-size: 0.8rem;
  }

  .file-classification-table th,
  .file-classification-table td {
    padding: 0.4rem 0.3rem;
  }

  .file-classification-table .file-row-name {
    max-width: 100px;
  }

  .btn {
    align-self: stretch;
    min-height: 44px;
  }

  .chat-card {
    max-height: 85vh;
  }

  .chat-area {
    min-height: 160px;
    margin-bottom: 0.75rem;
  }

  .chat-input-wrap {
    padding-top: 0.75rem;
  }

  .chat-form textarea {
    min-height: 64px;
    font-size: 16px;
  }

  .chat-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chat-actions .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }

  .conversation-thread {
    padding: 0 0.5rem;
  }

  .turn-question,
  .turn-answer {
    padding: 0.4rem 0.5rem;
    font-size: 0.875rem;
  }

  .turn-answer {
    margin-left: 0.25rem;
  }

  .chat-msg-wrap {
    max-width: 95%;
  }

  .chat-agent-input-bar {
    padding: 0.4rem 0.5rem 0.4rem 0.75rem;
    border-radius: 20px;
  }

  .chat-agent-input-bar textarea {
    min-height: 40px;
    font-size: 16px;
  }

  .chat-send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }

  .summary-cards {
    gap: 0.5rem;
  }

  .summary-card {
    min-width: 3.5rem;
    padding: 0.4rem 0.5rem;
  }

  .summary-value {
    font-size: 1.1rem;
  }

  .summary-label {
    font-size: 0.65rem;
  }

  .docs-filters {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .docs-filter-actions {
    padding-bottom: 0;
  }

  #docs-consultar-estos-btn {
    width: 100%;
    min-height: 44px;
  }

  .docs-grid {
    font-size: 0.85rem;
  }

  .docs-grid th,
  .docs-grid td {
    padding: 0.5rem 0.4rem;
  }

  .docs-grid-name {
    max-width: 120px;
  }

  .cita-item .cita-text {
    font-size: 0.8rem;
  }
}

@media (max-width: 380px) {
  .main-content {
    padding: 0.75rem 0.5rem 1rem;
  }

  .sidebar-header .site-title {
    font-size: 1.1rem;
  }

  .sidebar-tab {
    font-size: 0.8rem;
  }
}

@media (min-width: 768px) {
  .main-content {
    padding: 1.5rem 1.5rem 2rem;
  }
}

@media (min-width: 1024px) {
  .tab-panels {
    max-width: 960px;
  }

}
