:root {
  --brand: #0e6f6a;
  --brand-2: #0b5a56;
  --brand-3: #083f3c;
  --brand-soft: #e2f0ef;
  --accent: #f2a936;
  --ink: #1d2433;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f5f8;
  --card: #ffffff;
  --ok: #1f7a4d;   --ok-bg: #e6f4ec;
  --warn: #9a5b00; --warn-bg: #fdf2dc;
  --bad: #b42318;  --bad-bg: #fdecea;
  --info: #175cd3; --info-bg: #e8f0fd;
  --grey-bg: #eef0f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Montserrat', Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-hero { position: relative; overflow: hidden; background: linear-gradient(150deg, #0e6f6a 0%, #0b5a56 45%, #083f3c 100%); color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; }
.login-hero::before { content: ''; position: absolute; inset: -20%; background-image: radial-gradient(circle at 22% 28%, rgba(242,169,54,.22) 0, transparent 38%), radial-gradient(circle at 78% 12%, rgba(255,255,255,.14) 0, transparent 42%), repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 2px, transparent 2px 22px); }
.login-hero .hero-logo { margin-bottom: auto; }
.login-hero > * { position: relative; }
.login-hero h2 { font-size: 2rem; font-weight: 600; max-width: 460px; }
.login-hero p { max-width: 460px; opacity: .9; }
.login-panel { padding: 48px clamp(20px, 5vw, 72px); display: flex; flex-direction: column; justify-content: center; background: #fff; }
.logo-lockup { display: inline-flex; align-items: center; gap: calc(var(--lh) * .28); }
.logo-name { font-size: calc(var(--lh) * .62); font-weight: 700; letter-spacing: -.02em; }
.login-panel .logo-lockup { margin-bottom: 8px; }
.sidebar .brand .logo-lockup { margin-bottom: 2px; }
.doc-head .logo-lockup { margin-bottom: 4px; }
.login-panel h1 { margin: 18px 0 4px; }
.user-group { margin-top: 22px; }
.user-group h3 { text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; color: var(--muted); margin-bottom: 8px; }
.user-pick { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.user-pick:hover { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.user-pick[disabled] { opacity: .55; cursor: not-allowed; box-shadow: none; border-color: var(--line); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none; }
.demo-note { margin-top: 20px; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }
.mfa-box { max-width: 380px; }
.otp { letter-spacing: .5em; font-size: 1.5rem; text-align: center; font-weight: 600; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand-3); color: #cfd6ea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { background: #fff; padding: 16px 18px; border-bottom: 3px solid var(--brand); }

.sidebar .brand > span { display: block; margin-top: 4px; font-size: .64rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.nav { padding: 12px 10px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfd6ea; padding: 9px 12px; border-radius: 8px; font-size: .9rem; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: #fff; color: var(--brand); font-weight: 600; }
.nav a .badge { margin-left: auto; background: #f04438; color: #fff; border-radius: 999px; font-size: .7rem; padding: 1px 7px; font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav-sep { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: #7d89ad; padding: 14px 12px 4px; }
.sidebar .foot { padding: 12px 16px; font-size: .72rem; color: #7d89ad; border-top: 1px solid rgba(255,255,255,.08); }

.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.topbar .menu-btn { display: none; }
.topbar .spacer { flex: 1; }
.role-chip { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 4px 10px; border-radius: 999px; }
.role-empresa { background: var(--brand); color: #fff; }
.role-comercial { background: #e0f2fe; color: #075985; }
.role-cliente { background: #fef3c7; color: #92400e; }
.who { display: flex; align-items: center; gap: 10px; }
.who .small { line-height: 1.1; }
.main { min-width: 0; }
.content { padding: 24px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 16px; }
.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)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 1.55rem; font-weight: 700; color: var(--brand); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .86rem; white-space: nowrap; }
.btn:hover { border-color: #c5cad3; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f5c2bd; }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .78rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.grey { background: var(--grey-bg); color: #475467; }
.pill.brand { background: var(--brand-soft); color: var(--brand); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fc; }
tfoot td { font-weight: 600; background: #fafbfc; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .78rem; font-weight: 600; color: #344054; }
.input, select.input, textarea.input { border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 11px; background: #fff; width: 100%; }
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.input.xs { padding: 5px 8px; width: 80px; text-align: right; }
.input.over { border-color: var(--bad); background: var(--bad-bg); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 200px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: .8rem; cursor: pointer; font-weight: 500; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* catálogo */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.product { overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; }
.product:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16,24,40,.1); }
.product .ph { aspect-ratio: 1; background: #f2f3f5; position: relative; }
.product .ph canvas { width: 100%; height: 100%; display: block; }
.product .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.product .ref { font-size: .72rem; color: var(--muted); font-weight: 600; letter-spacing: .03em; }
.product .name { font-size: .88rem; font-weight: 600; }
.product .price { margin-top: auto; padding-top: 6px; display: flex; justify-content: space-between; align-items: baseline; }
.product .price b { color: var(--brand); }
.families { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.family { cursor: pointer; border-radius: var(--radius); overflow: hidden; position: relative; aspect-ratio: 5/4; border: 2px solid transparent; display: flex; align-items: flex-end; padding: 10px; color: #fff;
  background: linear-gradient(155deg, hsl(var(--h) 46% 34%) 0%, hsl(var(--h) 52% 22%) 100%); transition: transform .15s, box-shadow .15s; }
.family::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(120deg, rgba(255,255,255,.07) 0 2px, transparent 2px 16px); }
.family:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,24,40,.16); }
.family-name { position: relative; font-size: .8rem; font-weight: 600; line-height: 1.2; text-shadow: 0 1px 3px rgba(0,0,0,.25); }
.family.on { border-color: var(--brand-3); box-shadow: 0 0 0 3px var(--brand-soft); }
.family .count { position: absolute; top: 6px; right: 6px; z-index: 1; background: rgba(0,0,0,.3); color: #fff; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.protected { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* modal y toasts */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.sm { width: min(460px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; }
.product-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.product-detail canvas { width: 100%; border-radius: 10px; background: #f2f3f5; display: block; }
.attrs { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .86rem; margin: 12px 0; }
.attrs dt { color: var(--muted); }
.attrs dd { margin: 0; font-weight: 500; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: .86rem; box-shadow: 0 8px 20px rgba(0,0,0,.2); max-width: 380px; animation: tin .2s ease-out; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

.callout { border-radius: var(--radius); padding: 12px 14px; font-size: .86rem; display: flex; gap: 10px; align-items: flex-start; }
.callout.warn { background: var(--warn-bg); color: #6b4000; }
.callout.info { background: var(--info-bg); color: #123f8f; }
.callout.bad { background: var(--bad-bg); color: #7a1a12; }
.callout.ok { background: var(--ok-bg); color: #14532d; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: .84rem; }
.timeline li { padding: 0 0 12px 18px; position: relative; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline li:last-child { border-color: transparent; }
.steps { display: flex; gap: 0; margin: 4px 0 8px; }
.steps div { flex: 1; text-align: center; font-size: .72rem; font-weight: 600; color: var(--muted); padding-top: 22px; position: relative; }
.steps div::before { content: ''; position: absolute; top: 6px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #d0d5dd; z-index: 1; }
.steps div::after { content: ''; position: absolute; top: 11px; left: -50%; width: 100%; height: 2px; background: #d0d5dd; }
.steps div:first-child::after { display: none; }
.steps div.done { color: var(--brand); }
.steps div.done::before, .steps div.done::after { background: var(--brand); }

/* gráficos */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding: 10px 4px 0; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar { width: 100%; max-width: 46px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; position: relative; }
.bars .bar.cur { background: #7b8bc0; }
.bars .v { font-size: .72rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.bars .l { font-size: .74rem; color: var(--muted); }
.hbars .row { display: grid; grid-template-columns: 130px 1fr 90px; gap: 10px; align-items: center; font-size: .84rem; margin: 9px 0; }
.hbars .track { background: var(--grey-bg); border-radius: 6px; height: 12px; overflow: hidden; }
.hbars .fill { height: 100%; background: var(--brand); border-radius: 6px; }

.totals { margin-left: auto; width: min(340px, 100%); font-size: .9rem; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { border-top: 2px solid var(--brand); margin-top: 6px; padding-top: 10px; font-size: 1.1rem; font-weight: 700; color: var(--brand); }
.totals .internal { color: var(--muted); font-size: .8rem; border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.demo-banner { background: #fff8e6; color: #7a5200; font-size: .76rem; text-align: center; padding: 5px 10px; border-bottom: 1px solid #f3e2b8; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; font-size: .86rem; }
.check-grid label { display: flex; gap: 8px; align-items: center; }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: none; }

/* documento imprimible */
.doc { background: #fff; max-width: 860px; margin: 0 auto; padding: 44px 48px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--brand); padding-bottom: 18px; margin-bottom: 22px; }


@media print {
  .sidebar, .topbar, .no-print, .demo-banner, .toasts { display: none !important; }
  .app { display: block; } .content { padding: 0; } body { background: #fff; }
  .doc { box-shadow: none; border: none; padding: 0; }
}

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-2-1, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; } .login-hero { min-height: 220px; padding: 24px; } .login-hero h2 { font-size: 1.3rem; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { padding: 0 16px; } .topbar .menu-btn { display: inline-flex; }
  .who .small { display: none; }
  .topbar { gap: 8px; } .topbar select.input { max-width: 150px !important; padding: 6px 8px; font-size: .8rem; }
  .families { grid-auto-flow: column; grid-template-columns: none !important; grid-auto-columns: 92px; overflow-x: auto; padding-bottom: 6px; }
  .content { padding: 16px; }
  .g2, .form-grid, .product-detail { grid-template-columns: 1fr; }
  .products { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .families { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .hbars .row { grid-template-columns: 90px 1fr 80px; }
  .doc { padding: 20px; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr 1fr; } .kpi .value { font-size: 1.2rem; } .who, .role-chip { display: none; } }
