:root {
  --bg: #f4f5fb; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e7e9f3;
  --brand: #6d28d9; --brand-2: #4f46e5; --brand-soft: #f3efff; --navy: #17153b;
  --ok: #059669; --ok-soft: #e7f8f1; --warn: #d97706; --warn-soft: #fff6e6; --bad: #dc2626; --bad-soft: #fdeeee;
  --info: #2563eb; --info-soft: #eaf1ff; --gray-soft: #f1f3f8;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,64,.05), 0 8px 24px -12px rgba(16,24,64,.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }

/* Estructura */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: linear-gradient(180deg, #1b1846 0%, #121033 100%); color: #c9cbf0; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; font-weight: 700; font-size: 16px; }
.logo .mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #8b5cf6, #4f46e5); display: grid; place-items: center; box-shadow: 0 6px 18px -6px #8b5cf6; }
.logo small { display: block; font-weight: 500; color: #8f92c9; font-size: 11px; }
.nav-sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #6e71a8; padding: 16px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: #c9cbf0; font-weight: 500; margin: 1px 0; }
.nav a svg { width: 18px; height: 18px; opacity: .85; flex: none; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.on { background: linear-gradient(90deg, rgba(139,92,246,.35), rgba(99,102,241,.12)); color: #fff; box-shadow: inset 3px 0 0 #a78bfa; }
.nav .pill { margin-left: auto; background: #f59e0b; color: #1b1846; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; }
.side-foot { margin-top: auto; padding: 12px; font-size: 12px; color: #8f92c9; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot a { color: #c4b5fd; }

.main { padding: 26px 34px 60px; max-width: 1320px; width: 100%; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.top h1 { font-size: 25px; }
.top .sub { color: var(--muted); margin-top: 3px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Hero del tablero */
.hero { background: radial-gradient(1200px 300px at 100% 0%, rgba(139,92,246,.45), transparent 60%), linear-gradient(120deg, #1e1b4b, #312e81 60%, #4c1d95); color: #fff; border-radius: 20px; padding: 26px 30px; margin-bottom: 22px; position: relative; overflow: hidden; box-shadow: 0 20px 40px -24px #4c1d95; }
.hero h1 { font-size: 26px; }
.hero p { color: #d6d3ff; margin: 6px 0 0; }
.hero .hero-stats { display: flex; gap: 34px; margin-top: 20px; flex-wrap: wrap; }
.hero .hero-stats div b { display: block; font-size: 24px; font-weight: 700; }
.hero .hero-stats div span { color: #c4c1f5; font-size: 12.5px; }
.hero::after { content: ""; position: absolute; right: -60px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%; border: 40px solid rgba(255,255,255,.05); }

/* Tarjetas */
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g21 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .g3, .g4, .g21 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .app { grid-template-columns: 1fr; } .side { position: static; height: auto; } .g2, .g3, .g4, .g21 { grid-template-columns: 1fr; } .main { padding: 18px; } }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; gap: 10px; }
.card-h h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-h .muted { font-size: 12.5px; }
.card-b { padding: 16px 20px 20px; }
.card-b.flush { padding: 10px 0 6px; }

.kpi { padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; }
.kpi .ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.kpi .ico svg { width: 21px; height: 21px; }
.kpi .val { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; }
.kpi .det { font-size: 12px; margin-top: 3px; }
.t-violet { background: var(--brand-soft); color: var(--brand); }
.t-green { background: var(--ok-soft); color: var(--ok); }
.t-amber { background: var(--warn-soft); color: var(--warn); }
.t-blue { background: var(--info-soft); color: var(--info); }
.t-red { background: var(--bad-soft); color: var(--bad); }

/* Embudo de cotizaciones */
.funnel { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.funnel a { display: block; padding: 14px; border-radius: 12px; background: var(--gray-soft); color: var(--ink); position: relative; }
.funnel a:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.funnel b { font-size: 22px; display: block; }
.funnel span { font-size: 12px; color: var(--muted); }
.funnel small { display: block; font-size: 12px; margin-top: 4px; font-weight: 600; }
.funnel .bar { position: absolute; left: 0; bottom: 0; height: 4px; border-radius: 0 0 12px 12px; }
@media (max-width: 1100px) { .funnel { grid-template-columns: repeat(3, 1fr); } }

/* Tablas */
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 20px; border-bottom: 1px solid var(--line); background: #fafbfe; }
table.t td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr:hover td { background: #fbfaff; }
table.t .r, .r { text-align: right; }
table.t .num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.who { display: flex; align-items: center; gap: 10px; }
.av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty svg { width: 38px; height: 38px; opacity: .4; display: block; margin: 0 auto 8px; }

/* Insignias de estado */
.b { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-borrador, .b-sin-detalle, .b-pausado { background: var(--gray-soft); color: #475569; }
.b-enviada, .b-emitida, .b-nuevo { background: var(--info-soft); color: var(--info); }
.b-aprobada, .b-activo, .b-listo { background: var(--brand-soft); color: var(--brand); }
.b-facturada, .b-por-asignar, .b-pendiente { background: var(--warn-soft); color: var(--warn); }
.b-pagada, .b-pagado { background: var(--ok-soft); color: var(--ok); }
.b-rechazada, .b-error, .b-vencida, .b-terminado { background: var(--bad-soft); color: var(--bad); }

/* Botones y formularios */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: #cfd3e6; background: #fafbff; }
.btn svg { width: 16px; height: 16px; }
.btn-p { background: linear-gradient(135deg, #7c3aed, #4f46e5); color: #fff; border-color: transparent; box-shadow: 0 6px 16px -8px #6d28d9; }
.btn-p:hover { background: linear-gradient(135deg, #6d28d9, #4338ca); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn-ok:hover { background: #047857; color: #fff; }
.btn-bad { color: var(--bad); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-big { padding: 12px 20px; font-size: 15px; border-radius: 12px; }
form.inline { display: inline; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 12px; border: 1px solid #d9dcea; border-radius: 10px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: #a78bfa; box-shadow: 0 0 0 3px rgba(139,92,246,.18); }
textarea { min-height: 84px; resize: vertical; }
.f { margin-bottom: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }

.items td { padding: 6px 8px !important; }
.items input { padding: 7px 9px; }
.tot { margin-left: auto; width: 300px; }
.tot div { display: flex; justify-content: space-between; padding: 5px 0; }
.tot .big { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; color: var(--brand); }

/* Avisos */
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 500; display: flex; gap: 10px; align-items: center; }
.flash.ok { background: var(--ok-soft); color: #065f46; border: 1px solid #b7ebd5; }
.flash.err { background: var(--bad-soft); color: #991b1b; border: 1px solid #f6c6c6; }
.flash.info { background: var(--info-soft); color: #1e40af; border: 1px solid #c7d7fe; }
.callout { background: linear-gradient(120deg, #faf7ff, #f2f4ff); border: 1px dashed #c4b5fd; border-radius: 14px; padding: 16px 18px; }

/* Línea de tiempo */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

/* Pasos del flujo de licencias */
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; counter-reset: s; }
.steps div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 12px 46px; position: relative; font-size: 12.5px; color: var(--muted); }
.steps div b { display: block; color: var(--ink); font-size: 13.5px; }
.steps div::before { counter-increment: s; content: counter(s); position: absolute; left: 12px; top: 13px; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; display: grid; place-items: center; font-size: 12px; }
.steps div.done::before { background: var(--ok); color: #fff; content: "✓"; }
@media (max-width: 900px) { .steps { grid-template-columns: 1fr 1fr; } }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--line); color: var(--ink); font-weight: 500; font-size: 13px; }
.tabs a.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tabs a:hover { text-decoration: none; }
.tabs a span { opacity: .6; margin-left: 4px; }

.progress { height: 8px; background: var(--gray-soft); border-radius: 8px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, #8b5cf6, #4f46e5); border-radius: 8px; }
.proj { border-left: 4px solid var(--brand); }
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(900px 500px at 80% 10%, rgba(139,92,246,.5), transparent 60%), linear-gradient(135deg, #17153b, #312e81); }
.login .card { width: 380px; padding: 30px; }
details summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.card-h h3 svg { width: 18px; height: 18px; color: var(--brand); flex: none; }
.top h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.side { min-height: 100vh; height: auto; max-height: 100vh; overflow-y: auto; }
.card-b.flush { overflow-x: auto; }
.items td:first-child, .items th:first-child { padding-left: 20px !important; }
summary svg, .callout > b svg { width: 16px; height: 16px; vertical-align: -3px; }
.flash svg { width: 18px; height: 18px; flex: none; } .callout b svg, .card-h h3 .ico svg { width: 16px; height: 16px; }

table.reglas { min-width: 1280px; }
table.reglas select[name=tipo] { min-width: 210px; }
table.reglas select[name=signo] { min-width: 118px; }
table.reglas input[name=concepto] { min-width: 220px; }
table.reglas select[name=cliente_id] { min-width: 150px; }
