:root {
  --sidebar-bg: #10233f;
  --sidebar-fg: #cbd7e7;
  --sidebar-active: #1f4f82;
  --page-bg: #f3f6fa;
  --panel-bg: #ffffff;
  --border: #dfe6ef;
  --text: #172033;
  --muted: #66758c;
  --accent: #165d9c;
  --success: #1f8a4c;
  --warning: #b7791f;
  --danger: #c0392b;
  --info: #2470b3;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--page-bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.app-sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: #1f4f82; color: #7cc4ff; font-weight: 700; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--sidebar-fg); font-size: 12px; }

.app-nav { display: grid; gap: 4px; }
.app-nav a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-fg); padding: 10px 12px; border-radius: 8px; }
.app-nav a:hover, .app-nav a.active { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-icon { display: inline-block; width: 18px; text-align: center; opacity: .85; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.user-chip { background: rgba(255,255,255,.08); padding: 6px 10px; border-radius: 6px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer small { color: #8ea0ba; }

.app-main { padding: 24px 32px 48px; min-width: 0; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 24px; font-weight: 600; }
.page-subtitle { margin: 6px 0 0; color: var(--muted); }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.panel { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; margin-bottom: 18px; box-shadow: 0 4px 16px rgba(23, 48, 79, .04); }
.panel h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.panel h3 { margin: 18px 0 8px; font-size: 14px; font-weight: 600; }
.dashboard-host { padding: 8px; overflow: visible; }
.chat-host { height: calc(100vh - 420px); min-height: 420px; padding: 8px; }
.assistant-chat { height: 100%; }
.report-host { height: calc(100vh - 300px); min-height: 520px; padding: 8px; }
.report-host > div { height: 100%; }
.panel-danger { border-color: #f0c4bd; }
.panel-danger h2 { color: var(--danger); }
.warning { color: var(--warning); }
.danger { color: var(--danger); }
.two-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi-value { font-size: 26px; font-weight: 600; color: var(--accent); }
.kpi-success { color: var(--success); }
.kpi-warning { color: var(--warning); }
.kpi-danger { color: var(--danger); }
.kpi-info { color: var(--info); }
.kpi-title { color: var(--muted); font-size: 13px; }
.kpi-hint { color: var(--muted); font-size: 12px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-success { background: #e3f5ea; color: var(--success); }
.badge-warning { background: #fff3dc; color: var(--warning); }
.badge-danger { background: #fde5e2; color: var(--danger); }
.badge-info { background: #e2effb; color: var(--info); }
.badge-neutral { background: #eef1f5; color: #4d5b70; }

.meter { position: relative; height: 18px; background: #eef1f5; border-radius: 9px; overflow: hidden; min-width: 90px; }
.meter-wide { min-width: 120px; }
.meter-fill { height: 100%; border-radius: 9px; }
.meter-success { background: #3fbf7a; }
.meter-info { background: #4a90d9; }
.meter-warning { background: #e6a23c; }
.meter-danger { background: #e5695a; }
.meter-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: #1c2b3d; }

/* En bloque: si fuera flex, cada trozo de texto suelto y cada <strong> o <a> se convertiría en un
   ítem y el aviso se leería en columnas. Sólo los que llevan botón de cerrar necesitan la fila. */
.message { display: block; padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.message:has(> .message-close) { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.message-info { background: #e2effb; border-color: #c4dcf4; color: #1b4b7a; }
.message-success { background: #e3f5ea; border-color: #bfe6cf; color: #145c33; }
.message-warning { background: #fff3dc; border-color: #f2ddb0; color: #7a5010; }
.message-error { background: #fde5e2; border-color: #f4c2bc; color: #8a2419; }
.message-close { background: transparent; border: 0; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; }

/* Tarjetas de credenciales de Modelos de IA: una por proveedor, en columna. */
.key-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.key-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--page-bg); }
.key-card > strong { font-size: 15px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; margin-bottom: 12px; }
.form-grid label, label.w-100 { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #33415a; }
.mapping-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 18px; margin: 12px 0 16px; }
.mapping-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #33415a; }
.w-100 { width: 100%; }
.file-input { padding: 6px 0; }
.hint { color: var(--muted); margin: 6px 0 12px; }
.ok { color: var(--success); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.link { font-weight: 500; }
.action-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.btn-link { display: inline-flex; align-items: center; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--accent); font-weight: 500; }
.btn-link:hover { background: #f3f6fa; text-decoration: none; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar-spacer { flex: 1; }
.toolbar-combo { min-width: 220px; }
.toolbar-text { min-width: 280px; }
.toolbar-date { min-width: 150px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
.table-compact th, .table-compact td { padding: 5px 8px; font-size: 12px; white-space: nowrap; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.row-current td { background: #f4f9ff; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bars li { display: grid; grid-template-columns: 200px 1fr 50px; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; background: #eef1f5; border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, #4a90d9, #165d9c); border-radius: 6px; }
.bar-value { text-align: right; font-weight: 600; }

.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: #33415a; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .02em; padding-top: 3px; }
.facts dd { margin: 0; }

.decision-panel { display: grid; gap: 18px; }
.decision-title { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.decision-title h3 { margin: 0; font-size: 18px; }
.decision-panel h4 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.proposal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 18px; }
.proposal-grid .label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.proposal-grid strong { display: block; }
.reason { background: #f7f9fc; border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 6px; margin: 12px 0 6px; }
.evidence { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.evidence-cited { border-color: #b9d5f3; background: #f6faff; }
.evidence-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.evidence p { margin: 4px 0; }
.action-details { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.action-details summary { cursor: pointer; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { border-left: 2px solid var(--border); padding-left: 12px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: static; height: auto; }
  .app-main { padding: 16px; }
  .bars li { grid-template-columns: 120px 1fr 40px; }
}

/* Acceso */
.blank-shell { min-height: 100vh; display: flex; }
.login-page { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: var(--page-bg); padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel-bg); border: 1px solid var(--border); border-radius: 14px; padding: 28px 26px; box-shadow: 0 10px 30px rgba(23,48,79,.08); display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-brand .brand-mark { background: var(--accent); color: #fff; }
.login-brand strong { display: block; font-size: 15px; }
.login-brand small { color: var(--muted); font-size: 12px; }
.login-message { margin: 0; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #33415a; }
.login-field input { padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; }
.login-field input:focus { outline: 2px solid rgba(22,93,156,.35); border-color: var(--accent); }
.login-button { margin-top: 4px; padding: 10px 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }
.login-button:hover { background: #12507f; }
.login-help { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.login-footer { color: var(--muted); font-size: 12px; }

/* Pie de la barra lateral */
.user-role { color: #8ea0ba; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.user-actions { display: flex; align-items: center; gap: 10px; }
.user-actions form { margin: 0; }
.user-link { color: #9fb6d4; font-size: 12px; background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit; }
.user-link:hover { color: #fff; text-decoration: underline; }
