/* ==========================================================================
   MentorClass Prospector — Gestión Comercial y Licitaciones
   Sistema visual propio. Sin dependencias externas. CSP: sin estilos inline.
   ========================================================================== */

:root {
  /* Marca (uso discreto) */
  --brand-navy: #0f1d3a;
  --brand-navy-2: #16264a;
  --brand-navy-3: #1f3260;
  --brand-orange: #e85d04;

  /* Neutros */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #dde1e7;
  --border-strong: #c3c9d3;
  --text: #1a2130;
  --text-2: #4a5466;
  --text-3: #626c7e;
  --text-inverse: #ffffff;

  /* Acción e interacción */
  --primary: #1f47b8;
  --primary-hover: #183a98;
  --primary-soft: #e7edfb;
  --focus: #2563eb;
  --link: #1d4ed8;

  /* Semántica (texto oscuro sobre fondo suave: contraste AA) */
  --success: #147a3a; --success-bg: #e6f6ec; --success-border: #b7e3c6;
  --warning: #8a5a00; --warning-bg: #fdf3d8; --warning-border: #f1d58a;
  --danger: #b42318;  --danger-bg: #fdecea;  --danger-border: #f5c2bd;
  --info: #1d4ed8;    --info-bg: #e8effd;    --info-border: #bfd2f8;
  --neutral: #475467; --neutral-bg: #eef0f4; --neutral-border: #d5dae2;
  --purple: #5b21b6;  --purple-bg: #f1ebfd;  --purple-border: #d6c6f7;
  --teal: #0f6b62;    --teal-bg: #e3f5f2;    --teal-border: #b3e1da;

  /* Tipografía y espacios */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 24px;
  --radius: 8px; --radius-sm: 6px; --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --sidebar-w: 248px;
  --topbar-h: 56px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: 1.5;
  color: var(--text); background: var(--bg);
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--text); }
h1 { font-size: var(--fs-2xl); font-weight: 650; }
h2 { font-size: var(--fs-xl); font-weight: 620; }
h3 { font-size: var(--fs-lg); font-weight: 620; }
h4 { font-size: var(--fs-md); font-weight: 620; }
p { margin: 0 0 1em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: var(--fs-xs); }
code, pre { font-family: var(--font-mono); font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
img, svg { vertical-align: middle; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
::selection { background: #cddcfb; }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; }
.icon-sm { width: 14px; height: 14px; flex: none; }
.icon-lg { width: 22px; height: 22px; flex: none; }

.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 1000; padding: 8px 12px;
  background: var(--surface); color: var(--text); border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; box-shadow: var(--shadow-lg); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--brand-navy); color: #c9d2e3; display: flex; flex-direction: column;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; border-bottom: 1px solid var(--brand-navy-3); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--brand-navy-3); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .5px;
  box-shadow: inset 0 -3px 0 var(--brand-orange);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { color: #fff; font-size: 14px; font-weight: 650; line-height: 1.2; }
.brand-text small { color: #9fb0cf; font-size: 11.5px; line-height: 1.3; }
.nav { list-style: none; margin: 0; padding: 10px 8px; }
.nav-section { padding: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: #8193b5; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 1px 0; border-radius: var(--radius-sm);
  color: #c9d2e3; font-size: 13.5px; position: relative;
}
.nav-link:hover { background: var(--brand-navy-2); color: #fff; text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--brand-navy-3); color: #fff; font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand-orange);
}
.nav-link .badge-count { margin-left: auto; }
.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--brand-navy-3); font-size: 11.5px; color: #8193b5; }

.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-search { flex: 1; max-width: 560px; position: relative; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar .sidebar-toggle { display: none; }
.content { padding: 20px 24px 40px; flex: 1; outline: none; }
.content-narrow { max-width: 920px; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h1 { margin: 0; }
.page-header .subtitle { color: var(--text-3); margin-top: 2px; font-size: var(--fs-sm); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.breadcrumb { display: flex; gap: 6px; align-items: center; font-size: var(--fs-sm); color: var(--text-3); margin-bottom: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap;
  text-decoration: none; transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: #aab2c0; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn[aria-current="page"], .btn-group .btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); border-color: #b9c8f2; z-index: 1; }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */
.form { max-width: 880px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.form-section > h2, .form-section > h3 { font-size: var(--fs-lg); margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.field .required::after { content: " *"; color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; font: inherit; font-size: var(--fs-md); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.select { padding-right: 28px; }
.input:hover, .select:hover, .textarea:hover { border-color: #9aa3b2; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; }
.field-error { color: var(--danger); font-size: var(--fs-xs); font-weight: 600; display: flex; gap: 4px; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-size: var(--fs-md); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.input-group { display: flex; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; height: auto; }

/* ---------- Filters / toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px;
}
.toolbar .field { min-width: 150px; }
.toolbar .field.grow { flex: 1; min-width: 220px; }
.toolbar .field label { font-size: var(--fs-xs); color: var(--text-2); }
.toolbar .input, .toolbar .select { min-height: 34px; padding: 5px 9px; font-size: var(--fs-sm); }
.toolbar .actions { display: flex; gap: 6px; }
.result-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 2px 8px; color: var(--text-3); font-size: var(--fs-sm); flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 650; color: var(--text-2); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; z-index: 1; }
.table tbody tr:hover { background: #fafbfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .cell-title { font-weight: 600; color: var(--text); }
.table .cell-sub { color: var(--text-3); font-size: var(--fs-xs); }
.table-compact th, .table-compact td { padding: 6px 10px; }
.sort-link { color: inherit; display: inline-flex; gap: 4px; align-items: center; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; line-height: 18px; border: 1px solid transparent; white-space: nowrap;
}
.badge-success { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.badge-warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.badge-danger  { color: var(--danger);  background: var(--danger-bg);  border-color: var(--danger-border); }
.badge-info    { color: var(--info);    background: var(--info-bg);    border-color: var(--info-border); }
.badge-neutral { color: var(--neutral); background: var(--neutral-bg); border-color: var(--neutral-border); }
.badge-purple  { color: var(--purple);  background: var(--purple-bg);  border-color: var(--purple-border); }
.badge-teal    { color: var(--teal);    background: var(--teal-bg);    border-color: var(--teal-border); }
.badge-count { min-width: 20px; justify-content: center; padding: 0 6px; background: #b34700; color: #fff; border: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-success { background: var(--success); } .dot-warning { background: #c28400; } .dot-danger { background: var(--danger); } .dot-neutral { background: #8b95a7; } .dot-info { background: var(--info); }

/* ---------- Cards / panels / KPIs ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-header h2, .panel-header h3 { margin: 0; font-size: var(--fs-md); }
.panel-body { padding: 14px 16px; }
.panel-body.flush { padding: 0; }
.panel-footer { padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi .kpi-label { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; }
.kpi .kpi-value { font-size: 22px; font-weight: 680; font-variant-numeric: tabular-nums; color: var(--text); }
.kpi .kpi-sub { font-size: var(--fs-xs); color: var(--text-3); }
.kpi a { color: inherit; }
.kpi.kpi-alert { border-color: var(--danger-border); }
.kpi.kpi-alert .kpi-value { color: var(--danger); }

/* ---------- Definition lists (fichas) ---------- */
.dl { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: var(--fs-sm); }
.dl dt { color: var(--text-3); font-weight: 600; }
.dl dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.muted { color: var(--text-3); }
.text-sm { font-size: var(--fs-sm); } .text-xs { font-size: var(--fs-xs); }
.text-danger { color: var(--danger); } .text-success { color: var(--success); } .text-warning { color: var(--warning); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; display: inline-block; vertical-align: bottom; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mt-2 { margin-top: 16px; } .mb-2 { margin-bottom: 16px; }

/* ---------- Alerts / flash ---------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid; margin-bottom: 12px; font-size: var(--fs-sm);
}
.alert .icon { margin-top: 1px; }
.alert-body { flex: 1; }
.alert-close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; padding: 0 2px; opacity: .75; }
.alert-close:hover { opacity: 1; }
.alert-success { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.alert-error   { color: var(--danger);  background: var(--danger-bg);  border-color: var(--danger-border); }
.alert-warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.alert-info    { color: var(--info);    background: var(--info-bg);    border-color: var(--info-border); }
.alert-body strong { color: inherit; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 12px; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; background: var(--surface-3); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab .badge { font-size: 10.5px; line-height: 16px; padding: 0 6px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.pagination a, .pagination span {
  min-width: 32px; height: 32px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: var(--fs-sm);
}
.pagination a:hover { background: var(--surface-3); text-decoration: none; }
.pagination [aria-current="page"] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 650; }
.pagination .gap { border: 0; background: none; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 36px 20px; color: var(--text-2); }
.empty .icon-lg { width: 36px; height: 36px; color: #9aa4b6; margin-bottom: 8px; }
.empty h3 { font-size: var(--fs-lg); margin-bottom: 4px; }
.empty p { margin: 0 auto 12px; max-width: 460px; color: var(--text-3); font-size: var(--fs-sm); }

/* ---------- Menus (details/summary) ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 50; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu-item {
  display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 0; background: none; font: inherit; font-size: var(--fs-sm); color: var(--text); text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-3); text-decoration: none; }
.menu-header { padding: 8px 10px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-header strong { display: block; font-size: var(--fs-sm); }
.menu-header span { font-size: var(--fs-xs); color: var(--text-3); }
.user-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.user-chip:hover { background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand-navy); color: #fff; font-size: 12px; font-weight: 700; flex: none; }
.user-chip .name { font-size: var(--fs-sm); font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Dialog ---------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.modal::backdrop { background: rgba(15, 29, 58, .45); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: var(--fs-lg); margin: 0; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.progress.success > span { background: var(--success); } .progress.warning > span { background: #c28400; } .progress.danger > span { background: var(--danger); }
progress.bar { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
progress.bar::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress.bar::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
progress.bar.success::-webkit-progress-value { background: var(--success); } progress.bar.success::-moz-progress-bar { background: var(--success); }
progress.bar.warning::-webkit-progress-value { background: #c28400; } progress.bar.warning::-moz-progress-bar { background: #c28400; }
progress.bar.danger::-webkit-progress-value { background: var(--danger); } progress.bar.danger::-moz-progress-bar { background: var(--danger); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: var(--fs-sm); }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--text-3); font-size: var(--fs-xs); }

/* ---------- Auth pages ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #0f1d3a 0%, #16264a 55%, #1f3260 100%); }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 28px 28px 22px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 42px; height: 42px; font-size: 15px; background: var(--brand-navy); }
.auth-brand strong { display: block; font-size: 17px; color: var(--text); }
.auth-brand span { font-size: var(--fs-sm); color: var(--text-3); }
.auth-card h1 { font-size: var(--fs-lg); margin-bottom: 14px; }
.auth-card .field { margin-bottom: 12px; }
.auth-footer { margin-top: 18px; font-size: var(--fs-xs); color: var(--text-3); text-align: center; }

/* ---------- Error pages ---------- */
.error-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.error-card { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; text-align: center; }
.error-code { font-size: 40px; font-weight: 750; color: var(--brand-navy); margin: 0; }
.error-card p { color: var(--text-2); }
.error-detail { text-align: left; background: var(--surface-3); padding: 10px; border-radius: var(--radius-sm); font-size: var(--fs-xs); overflow-x: auto; }

/* ---------- Module tiles (Inicio) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.tile:hover { border-color: #b9c8f2; box-shadow: var(--shadow-sm); text-decoration: none; }
.tile .icon-lg { color: var(--primary); }
.tile strong { display: block; font-size: var(--fs-md); }
.tile span { font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- CRM ---------- */
.mt-1 { margin-top: 6px; }
.input-narrow { width: 80px; }
.chip { display: inline-flex; align-items: center; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); line-height: 20px; white-space: nowrap; }
.method { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.method + .method { margin-top: 4px; }
.method-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.method-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.method-row .field { min-width: 140px; }
.method-row .field.grow { flex: 1; min-width: 200px; }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.note { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.note-pinned { border-color: var(--info-border); background: var(--info-bg); }
.note-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: var(--fs-xs); margin-bottom: 4px; }
.note-body { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.note-edit { margin-top: 6px; font-size: var(--fs-sm); }
.note-edit summary { cursor: pointer; color: var(--link); font-size: var(--fs-xs); }
.note-edit[open] { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Oportunidades ---------- */
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.row-current td { background: var(--info-bg); }
.action-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.table tfoot th, .table tfoot td { position: static; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; }
.table tfoot th { text-align: right; }
.table td .select { min-width: 120px; }
.form-grid .span-2 { grid-column: span 2; }
.record-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; align-items: start; margin-bottom: 16px; }
.record-title h1 { margin: 0 0 6px; }
.record-facts { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 4px 0 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.record-facts dt { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; }
.record-facts dd { margin: 2px 0 0; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset legend { padding: 0; margin-bottom: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.fieldset .row { gap: 20px; }
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; scrollbar-width: thin; }
.board-column { flex: 0 0 272px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 240px); }
.board-column.is-over { border-color: var(--primary); background: var(--primary-soft); }
.board-column-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.board-column-header h2 { margin: 0; font-size: var(--fs-sm); }
.board-cards { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 48px; }
.board-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.board-card[draggable="true"] { cursor: grab; }
.board-card.is-dragging { opacity: .5; }
.board-card-title { font-weight: 600; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.board-card-meta { font-size: var(--fs-xs); color: var(--text-2); display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.board-move { display: flex; gap: 6px; margin-top: 4px; }
.board-move .select { min-height: 28px; padding: 2px 6px; font-size: var(--fs-xs); flex: 1; min-width: 0; }
.board-more, .board-empty { font-size: var(--fs-xs); padding: 0 12px 10px; margin: 0; }

/* ---------- Calendario ---------- */
.cal-nav { margin-bottom: 12px; }
.cal-title { margin: 0; font-size: var(--fs-lg); }
.cal-month { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-row + .cal-row { border-top: 1px solid var(--border); }
.cal-cell { position: relative; min-height: 112px; padding: 4px 6px; border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-cell:first-child { border-left: 0; }
.cal-head .cal-cell { min-height: 0; padding: 6px 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); background: var(--surface-2); }
.cal-cell.is-outside { background: var(--surface-2); }
.cal-cell.is-outside .cal-day { color: var(--text-3); }
.cal-day { align-self: flex-end; font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); padding: 1px 7px; border-radius: 999px; }
.cal-cell.is-today .cal-day { background: var(--primary); color: #fff; }
.cal-event { position: relative; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; padding: 2px 6px; font-size: var(--fs-xs); color: var(--text); background: var(--info-bg); border-left: 3px solid var(--info); border-radius: var(--radius-sm); }
.cal-event:hover { text-decoration: none; filter: brightness(.97); }
.cal-event.is-critical { background: var(--danger-bg); border-left-color: var(--danger); }
.cal-event.is-closed { opacity: .7; }
.cal-event-time { color: var(--text-2); font-variant-numeric: tabular-nums; }
.cal-event-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-week-day .cal-event-title, .cal-agenda-day .cal-event-title { white-space: normal; }
.cal-month .cal-event-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }
.cal-month .cal-tag { flex-basis: 100%; }
.cal-event-sub { flex-basis: 100%; color: var(--text-2); }
.cal-tag { font-size: 10px; font-weight: 700; letter-spacing: .02em; color: var(--danger); text-transform: uppercase; }
.cal-more { font-size: var(--fs-xs); }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-week-day { min-width: 0; min-height: 160px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cal-week-day.is-today { border-color: var(--primary); }
.cal-week-day h3, .cal-agenda-day h3 { margin: 0; font-size: var(--fs-sm); }
.cal-agenda { display: flex; flex-direction: column; gap: 12px; }
.cal-agenda-day { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cal-agenda-mobile { display: none; }
.menu-panel-form { width: 300px; padding: 12px; display: flex; flex-direction: column; gap: 10px; right: 0; left: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
  .hide-md { display: none; }
  .cal-week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; visibility: hidden; }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); visibility: visible; }
  .app-main { margin-left: 0; }
  .topbar .sidebar-toggle { display: inline-grid; }
  .content { padding: 16px; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 29, 58, .35); z-index: 35; }
}
@media (max-width: 768px) {
  .cal-month { display: none; }
  .cal-agenda-mobile { display: flex; }
  .cal-week { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .form-grid, .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .record-header { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
  .user-chip .name { display: none; }
  .topbar { padding: 0 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .pagination { display: none !important; }
  .app-main { margin: 0; }
  body { background: #fff; }
}

/* ---------- Búsqueda global ---------- */
.topbar-search form { position: relative; }
.topbar-search .input { padding-left: 34px; min-height: 36px; }
.topbar-search .topbar-search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.quick-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(15, 23, 42, .16); max-height: min(70vh, 520px); overflow-y: auto; padding: 6px 0; }
.quick-results h3 { margin: 6px 12px 2px; font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .4px; display: flex; justify-content: space-between; gap: 8px; }
.quick-results a { display: block; padding: 6px 12px; color: var(--text); text-decoration: none; }
.quick-results a:hover, .quick-results a:focus { background: var(--surface-2); outline: none; }
.quick-results a:focus-visible { box-shadow: inset 3px 0 0 var(--primary); }
.quick-results .q-title { display: block; font-size: var(--fs-sm); font-weight: 600; overflow-wrap: anywhere; }
.quick-results .q-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); overflow-wrap: anywhere; }
.quick-results .q-more { font-size: var(--fs-xs); color: var(--link); text-transform: none; letter-spacing: 0; }
.quick-results .q-empty { padding: 8px 12px; font-size: var(--fs-sm); color: var(--text-3); }
.quick-results .q-all { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; font-size: var(--fs-sm); color: var(--link); }
.search-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.result-list li { overflow-wrap: anywhere; }
.result-title { font-weight: 600; }

/* ---------- Inicio ---------- */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented a { padding: 7px 14px; font-size: var(--fs-sm); color: var(--text-2); }
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a[aria-current="page"] { background: var(--primary); color: #fff; font-weight: 600; }
.kpi .kpi-link { display: flex; flex-direction: column; gap: 2px; text-decoration: none; }
.kpi .kpi-link:hover .kpi-label, .kpi .kpi-link:focus-visible .kpi-label { color: var(--link); text-decoration: underline; }
.attention { display: flex; flex-direction: column; }
.attention-group { padding: 12px 16px; border-top: 1px solid var(--border); }
.attention-group:first-child { border-top: 0; }
.attention-group h3 { margin: 0; font-size: var(--fs-sm); display: flex; align-items: center; gap: 8px; }
.attention-rule { margin: 2px 0 8px; font-size: var(--fs-xs); color: var(--text-3); }
.attention-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.attention-list li { display: flex; gap: 8px; align-items: flex-start; overflow-wrap: anywhere; }
.attention-list .attention-icon { flex: none; margin-top: 3px; color: var(--text-3); }
.attention-list li.is-urgent .attention-icon { color: var(--danger); }
.attention-list a { font-weight: 600; font-size: var(--fs-sm); }

/* ---------- Reportes e importación ---------- */
.report-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.report-list { list-style: none; margin: 0; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.report-list a { font-weight: 600; }
.row-errors { margin: 4px 0 0; padding-left: 18px; font-size: var(--fs-xs); color: var(--danger); }
.table tbody th { position: static; background: transparent; color: var(--text); font-size: inherit; font-weight: 600; text-transform: none; letter-spacing: 0; white-space: normal; z-index: auto; }

/* Panel plegable (formularios de alta secundarios) */
.panel-collapsible > summary { cursor: pointer; list-style: none; }
.panel-collapsible > summary::-webkit-details-marker { display: none; }
.panel-collapsible > summary h2 { display: flex; align-items: center; gap: 6px; color: var(--link); }
.panel-collapsible:not([open]) > summary { border-bottom: 0; }
