/* Scutia · Sistema de diseño Lumina */
:root {
  --primary: #14ff5d;
  --primary-hover: #0fe653;
  --primary-ink: #006e22;
  --primary-soft: rgba(20, 255, 93, .12);
  --obsidian: #082115;
  --ink: #191c1d;
  --ink-2: #3b4b39;
  --muted: #5b6b60;
  --muted-2: #8a978d;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --surface-3: #f3f4f5;
  --border: #e6e8ea;
  --border-2: #d9dcde;
  --secondary-soft: #cae7d3;
  --blue: #2952ff;
  --blue-soft: #e8ecff;
  --danger: #ba1a1a;
  --danger-soft: #ffdad6;
  --warning: #9a5b00;
  --warning-soft: #fff1d6;
  --radius: 8px;
  --radius-lg: 16px;
  --shadow-2: 0 4px 12px rgba(8, 33, 21, .04);
  --shadow-3: 0 8px 24px rgba(8, 33, 21, .08);
  --font-head: 'Manrope', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font-body); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--surface-2); -webkit-font-smoothing: antialiased; }
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--obsidian); margin: 0; letter-spacing: -.01em; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
code, .mono { font-family: var(--font-mono); font-size: 12px; }
.label-caps { font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Marca */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--obsidian); font-family: var(--font-head); font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand.on-dark { color: #fff; }

/* Shell */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 22px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 8px; }
.tenant-chip { margin: 0 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.tenant-chip .name { font-weight: 600; color: var(--obsidian); font-size: 13px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-title { padding: 0 12px 6px; }
.nav a, .nav span.soon { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius); color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-3); text-decoration: none; }
.nav a.active { background: var(--secondary-soft); color: var(--primary-ink); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav span.soon { color: var(--muted-2); cursor: default; }
.nav span.soon .tag { margin-left: auto; font-family: var(--font-mono); font-size: 10px; padding: 2px 7px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.sidebar-foot { margin-top: auto; padding: 0 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.topbar .crumbs b { color: var(--obsidian); font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--obsidian); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-head); font-weight: 700; font-size: 13px; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.user-menu .who { text-align: right; line-height: 1.2; }
.user-menu .who b { display: block; font-size: 13px; color: var(--obsidian); }
.user-menu .who span { font-size: 11px; color: var(--muted); }
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: var(--radius); border: 1px solid transparent; font-family: var(--font-body); font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none !important; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: var(--obsidian); font-weight: 700; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--obsidian); border-color: var(--border-2); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--obsidian); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.kpi { padding: 18px 20px; }
.kpi .value { font-family: var(--font-head); font-size: 32px; font-weight: 800; letter-spacing: -.02em; color: var(--obsidian); line-height: 1.1; margin-top: 8px; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.kpi.blue { border-top: 3px solid var(--blue); }
.kpi.warn { border-top: 3px solid #f0a020; }
.kpi.dark { border-top: 3px solid var(--obsidian); }

.insight { border: 1px solid rgba(20, 255, 93, .35); box-shadow: inset 0 0 0 1px rgba(20, 255, 93, .12); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; box-shadow: 0 0 0 0 rgba(20, 255, 93, .6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(20, 255, 93, .55); } 70% { box-shadow: 0 0 0 8px rgba(20, 255, 93, 0); } 100% { box-shadow: 0 0 0 0 rgba(20, 255, 93, 0); } }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; background: var(--surface-3); color: var(--obsidian); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.success { background: rgba(20, 255, 93, .14); color: var(--primary-ink); }
.chip.muted { background: var(--surface-3); color: var(--muted); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.cell-user { display: flex; align-items: center; gap: 12px; }
.cell-user b { display: block; color: var(--obsidian); font-weight: 600; }
.cell-user span { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label, .field .label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input, textarea.input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--surface); font-family: var(--font-body); font-size: 14px; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
textarea.input { height: auto; min-height: 96px; padding: 10px 12px; }
.input:focus { outline: none; border-color: var(--obsidian); box-shadow: 0 0 0 3px rgba(20, 255, 93, .22); }
.field.has-error .input { border-color: var(--danger); }
.field .error { color: var(--danger); font-size: 12px; margin-top: 6px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 6px; }
.check-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.check:hover { background: var(--surface-2); }
.check input { margin-top: 3px; accent-color: var(--primary-ink); }
.check b { display: block; font-size: 13px; color: var(--obsidian); }
.check span { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.toolbar .input { height: 36px; max-width: 320px; }
.toolbar select.input { max-width: 180px; }

/* Alertas */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 13px; }
.alert-success { background: rgba(20, 255, 93, .12); color: var(--primary-ink); border: 1px solid rgba(20, 255, 93, .35); }
.alert-error { background: var(--danger-soft); color: #93000a; border: 1px solid #ffb4ab; }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }
.list .meta { color: var(--muted); font-size: 12px; }

/* Roadmap de etapa */
.stages { display: flex; flex-direction: column; gap: 10px; }
.stage { display: flex; gap: 12px; align-items: center; }
.stage .n { width: 28px; height: 28px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--muted); flex: none; }
.stage.done .n { background: var(--obsidian); color: var(--primary); }
.stage.now .n { background: var(--primary); color: var(--obsidian); }
.stage b { display: block; font-size: 13px; color: var(--obsidian); }
.stage span { font-size: 12px; color: var(--muted); }

/* Paginación */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.pager .links { display: flex; gap: 6px; }

/* Acceso */
.auth { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; background: var(--surface); }
.auth-aside { background: var(--obsidian); color: #fff; padding: 48px 56px; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.auth-aside::before { content: ""; position: absolute; width: 760px; height: 760px; right: -280px; top: -260px; border-radius: 50%; background: radial-gradient(circle, rgba(20, 255, 93, .28), rgba(20, 255, 93, 0) 62%); }
.auth-aside::after { content: ""; position: absolute; inset: 0; opacity: .05; background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px); background-size: 56px 56px; }
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside h1 { color: #fff; font-size: 40px; line-height: 1.08; margin-top: auto; max-width: 480px; }
.auth-aside h1 em { font-style: normal; color: var(--primary); }
.auth-aside p { color: #c8d4cc; font-size: 16px; margin-top: 16px; max-width: 460px; }
.auth-aside .points { display: flex; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
.auth-aside .points span { border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px; padding: 6px 14px; font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #dfeae3; }
.auth-aside .foot { margin-top: 48px; font-family: var(--font-mono); font-size: 11px; color: #9fb0a5; letter-spacing: .1em; text-transform: uppercase; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-form .box { width: 100%; max-width: 380px; }
.auth-form h2 { font-size: 26px; font-weight: 800; }
.auth-form .sub { color: var(--muted); margin: 6px 0 28px; }
.auth-form .field { margin-bottom: 16px; }
.auth-mobile-brand { display: none; margin-bottom: 40px; }
.auth-form .legal { margin-top: 24px; font-size: 12px; color: var(--muted-2); text-align: center; }

/* Error */
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-page .box { text-align: center; max-width: 440px; }
.error-page .code { font-family: var(--font-head); font-weight: 800; font-size: 88px; color: var(--obsidian); letter-spacing: -.04em; line-height: 1; }
.error-page .code span { color: var(--primary); }
.error-page p { color: var(--muted); margin: 14px 0 24px; }

/* ── Etapa 1.1 · Núcleo comercial ───────────────────────────── */
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.table tr.is-off td, .rows li.is-off { opacity: .55; }
.cell-main b { display: block; color: var(--obsidian); font-weight: 600; }
.cell-main span { color: var(--muted); font-size: 12px; }
.cell-main a { color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip.warning { background: var(--warning-soft); color: var(--warning); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.stack-sm .field { width: 100%; margin: 0; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.page-head .actions { align-items: center; flex-wrap: wrap; }
.page-head .actions form { margin: 0; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.crumb-back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumb-back svg { width: 14px; height: 14px; }
.card-head h3 { display: flex; align-items: center; gap: 8px; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-family: var(--font-mono); font-size: 11px; font-weight: 600; }
.card-foot.hint { color: var(--warning); background: var(--warning-soft); font-size: 12px; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.alert-info { background: var(--blue-soft); color: var(--blue); border: 1px solid #c7d1ff; }
.alert-info a { color: inherit; font-weight: 600; }

/* Listas de filas (sucursales, contactos, renovaciones) */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: flex-start; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: none; }
.row-icon { flex: none; width: 34px; height: 34px; border-radius: var(--radius); background: var(--surface-3); color: var(--obsidian); display: inline-flex; align-items: center; justify-content: center; }
.row-icon svg { width: 18px; height: 18px; }
.row-icon.warn { background: var(--warning-soft); color: var(--warning); }
.row-main { flex: 1; min-width: 0; }
.row-main > b { color: var(--obsidian); font-weight: 600; }
.row-main > span:not(.chip) { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.row-main .meta { font-size: 12px; color: var(--muted-2); }
.rows .actions form { margin: 0; }

/* Datos clave-valor */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; padding: 16px 20px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--obsidian); font-weight: 500; overflow-wrap: anywhere; }

/* Formularios dentro de tarjetas */
.inline-form { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
.inline-form .label-caps { margin-bottom: 12px; }
.inline-form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.field.checks { display: flex; flex-direction: column; gap: 8px; justify-content: flex-end; }
.check.inline { padding: 10px 12px; background: var(--surface); }
.field .check { display: flex; margin-bottom: 0; font-weight: 400; }
.field.checks { display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; }
.row-main > .chip { margin-left: 6px; vertical-align: 1px; }
.nowrap, .table a.mono, .table td.mono { white-space: nowrap; }
.check-list.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check-list.compact .check { padding: 10px 12px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.note-compose { display: grid; grid-template-columns: 130px 1fr; gap: 8px; }
.note-compose textarea, .note-compose .field, .note-compose button { grid-column: 1 / -1; }
.note-compose button { justify-self: end; }
.input.is-invalid { border-color: var(--danger); }
.lines-table td { vertical-align: top; padding: 10px 8px; }
.lines-table td:first-child { padding-left: 20px; }
.lines-table .input { height: 36px; min-width: 0; }
.lines-table .error { color: var(--danger); font-size: 11px; margin-top: 4px; }
.lines-table td:nth-child(1) { min-width: 160px; } .lines-table td:nth-child(2) { min-width: 200px; }
.lines-table td:nth-child(4) { width: 130px; }
.freq { display: flex; align-items: center; gap: 6px; }
.freq input { width: 58px; flex: none; }
.freq select { min-width: 132px; flex: 1; }
.lines-table td:nth-child(3) { min-width: 210px; }
.freq span { color: var(--muted); }
.btn.icon-only { width: 32px; padding: 0; }
.estimate { font-size: 13px; color: var(--muted); }
.estimate b { color: var(--obsidian); font-family: var(--font-head); font-size: 16px; }
.group-row td { background: var(--surface-2); font-weight: 600; font-size: 13px; color: var(--obsidian); padding-top: 10px; padding-bottom: 10px; }
.group-row svg { width: 15px; height: 15px; vertical-align: -2px; }

/* Historial */
.timeline { list-style: none; margin: 0; padding: 8px 20px 16px; }
.timeline li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
.tl-icon { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); display: inline-flex; align-items: center; justify-content: center; color: var(--obsidian); }
.tl-icon svg { width: 14px; height: 14px; }
.tl-head { font-size: 12px; color: var(--muted); }
.tl-head b { color: var(--obsidian); }
.timeline p { margin: 4px 0 0; font-size: 13px; color: var(--ink); white-space: normal; }

/* Pestañas */
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 14px 10px 12px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.tabs a:hover { color: var(--obsidian); }
.tabs a.active { color: var(--obsidian); border-bottom-color: var(--primary); }

@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .table-wrap > .table { min-width: 620px; }
  .table-wrap > .table.lines-table { min-width: 980px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-mobile-brand { display: block; }
  .form-grid, .form-grid.cols-3, .check-list, .check-list.compact, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
