/* Portal InStyle Group · estilos. Sin dependencias externas (la CSP solo permite 'self'). */
:root {
  color-scheme: light;
  --page: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --navy: #202c4b;
  --navy-2: #2b3a62;
  --on-navy: #e8ecf6;
  --on-navy-muted: #a9b4d0;
  --brand: #f26522;
  --focus: #2a78d6;
  --link: #1c5cab;
  /* Tiendas: paleta categórica validada (el color sigue a la tienda). */
  --store-cabostyle: #2a78d6;
  --store-hoven: #1baf7a;
  --store-fitters: #eb6834;
  /* Gráficas */
  --chart-primary: #202c4b;
  --chart-previous: #9aa1ad;
  --chart-grid: #e6e8ec;
  --chart-axis: #c5c9d0;
  /* Estados (siempre con texto o ícono) */
  --good: #006300;
  --bad: #b42318;
  --ok-bg: #e7f6e7; --ok-fg: #0b5a0b;
  --pending-bg: #fff4d6; --pending-fg: #7a4b00;
  --error-bg: #fde8e6; --error-fg: #9b1c12;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0f1218;
    --surface: #181c25;
    --surface-2: #1e232e;
    --text: #f0f2f6;
    --text-2: #c4c9d4;
    --muted: #949cab;
    --border: #2a303c;
    --border-strong: #3a4150;
    --navy: #141a2b;
    --navy-2: #222b45;
    --link: #86b6ef;
    --store-cabostyle: #3987e5;
    --store-hoven: #199e70;
    --store-fitters: #d95926;
    --chart-primary: #c9d2ea;
    --chart-previous: #6b7384;
    --chart-grid: #262c38;
    --chart-axis: #3a4150;
    --good: #5fd35f;
    --bad: #ff8a80;
    --ok-bg: #12301a; --ok-fg: #8fe29a;
    --pending-bg: #3a2c08; --pending-fg: #ffd77a;
    --error-bg: #3d1513; --error-fg: #ffb3ab;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--link); }
h1, h2, h3 { line-height: 1.25; margin: 0; text-wrap: balance; }
h1 { font-size: 1.35rem; font-weight: 600; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: .75rem; }
h3 { font-size: .95rem; font-weight: 600; margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
p { margin: 0 0 .75rem; }
code { font-size: .85em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 50; }
.skip:focus { left: .5rem; top: .5rem; }
.muted { color: var(--muted); }
.mt { margin-top: 1.25rem; }
.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- estructura ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--navy); color: var(--on-navy); padding: 1rem .75rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; padding: .25rem .5rem; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: .9rem; letter-spacing: .02em; flex: none; }
.brand-name { display: block; font-weight: 600; line-height: 1.15; }
.brand-sub { display: block; font-size: .78rem; color: var(--on-navy-muted); }
.sidebar nav { flex: 1; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--on-navy-muted); padding: .9rem .6rem .3rem; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a { display: block; padding: .45rem .6rem; border-radius: 7px; color: var(--on-navy); text-decoration: none; font-size: .93rem; }
.sidebar nav a:hover { background: var(--navy-2); }
.sidebar nav a.active { background: var(--navy-2); font-weight: 600; box-shadow: inset 3px 0 0 var(--brand); }
.user-box { border-top: 1px solid var(--navy-2); padding: .75rem .6rem 0; font-size: .85rem; }
.user-name { font-weight: 600; overflow-wrap: anywhere; }
.user-role { color: var(--on-navy-muted); }
.user-actions { display: flex; gap: .9rem; margin-top: .4rem; align-items: center; flex-wrap: wrap; }
.user-actions a, .linklike { color: var(--on-navy); font: inherit; background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }

.main-col { min-width: 0; padding: 1rem 1.5rem 2rem; }
.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .9rem; }
.topbar h1 { margin-right: auto; }
.menu-btn { display: none; }
.store-switch, .presets, .seg { display: flex; flex-wrap: wrap; gap: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: .2rem; }
.store-switch a, .presets a, .seg a { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem; border-radius: 7px; color: var(--text-2); text-decoration: none; font-size: .88rem; white-space: nowrap; }
.store-switch a:hover, .presets a:hover, .seg a:hover { background: var(--surface-2); }
.store-switch a.on, .presets a.on, .seg a.on { background: var(--navy); color: #fff; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: .4rem; flex: none; vertical-align: baseline; }
.store-switch .dot { margin-right: 0; }
.dot-cabostyle { background: var(--store-cabostyle); }
.dot-hoven { background: var(--store-hoven); }
.dot-fitters { background: var(--store-fitters); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-bottom: 1rem; }
.custom-range { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem; font-size: .85rem; color: var(--text-2); }
.custom-range label { display: flex; align-items: center; gap: .35rem; }
.period-note { flex-basis: 100%; margin: 0; font-size: .85rem; color: var(--text-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.foot { margin-top: 2rem; font-size: .8rem; color: var(--muted); }
main:focus { outline: none; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.kpi-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: .82rem; color: var(--text-2); }
.kpi-value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; margin: .15rem 0; overflow-wrap: anywhere; }
.kpi-grid-secondary .kpi-value { font-size: 1.25rem; }
.kpi-delta { font-size: .8rem; }
.kpi-hint { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.delta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta-good { color: var(--good); }
.delta-bad { color: var(--bad); }
.delta-flat, .delta-none { color: var(--muted); }
.delta-vs { color: var(--muted); font-weight: 400; white-space: normal; }
td .delta-vs { display: none; }

.table-wrap { overflow-x: auto; margin: 0 -.25rem; padding: 0 .25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th { font-weight: 600; color: var(--text-2); font-size: .8rem; white-space: nowrap; background: var(--surface-2); }
.table th.n, .table td.n { text-align: right; }
.table tbody tr:last-child > * { border-bottom: 0; }
.table tbody th { font-weight: 500; }
.table-breakdown td { text-align: right; font-variant-numeric: tabular-nums; }
.table-breakdown tr.total > * { font-weight: 600; border-top: 1px solid var(--border-strong); }
.table-breakdown tr.aside > * { color: var(--text-2); border-top: 1px dashed var(--border-strong); }
.stat-list { list-style: none; padding: 0; margin: 0 0 .75rem; }
.stat-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.stat-list li:last-child { border-bottom: 0; }
.stat-list strong { font-variant-numeric: tabular-nums; }
.hint, .field-hint, .updated { font-size: .8rem; color: var(--muted); }
.field-hint { display: block; font-weight: 400; }
.updated { margin-bottom: .75rem; }
.err-text { color: var(--error-fg); font-size: .82rem; overflow-wrap: anywhere; }

.badge, .signal { display: inline-block; font-size: .74rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; white-space: nowrap; }
.badge-ok, .signal-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-pending, .signal-warning { background: var(--pending-bg); color: var(--pending-fg); }
.badge-error, .signal-critical { background: var(--error-bg); color: var(--error-fg); }
.notice, .flash { border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .9rem; font-size: .9rem; border: 1px solid transparent; }
.notice-pending { background: var(--pending-bg); color: var(--pending-fg); }
.notice-error { background: var(--error-bg); color: var(--error-fg); }
.notice a { color: inherit; }
.flash { background: var(--surface); border-color: var(--border-strong); border-left: 4px solid var(--navy-2); overflow-wrap: anywhere; }
.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem 1.5rem; text-align: center; margin-bottom: 1rem; }
.empty p { color: var(--text-2); max-width: 60ch; margin-inline: auto; }
.callout { border-left: 4px solid var(--brand); }
.callout ul, .prose ul { margin: 0 0 .75rem; padding-left: 1.2rem; }
.callout li, .prose li { margin-bottom: .35rem; }
.prose { max-width: 90ch; }
.defs { display: grid; grid-template-columns: minmax(140px, 200px) 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.defs dt { font-weight: 600; }
.defs dd { margin: 0; color: var(--text-2); }
.meta-list { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: .2rem .75rem; font-size: .84rem; margin: 0 0 .9rem; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; overflow-wrap: break-word; }
.pending-list { list-style: none; padding: 0; margin: 0 0 .75rem; }
.pending-list li { padding: .3rem 0; }

/* ---------- formularios ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-small { padding: .3rem .65rem; font-size: .82rem; }
.btn-danger { color: var(--error-fg); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.stack { display: grid; gap: .7rem; }
.stack label { display: grid; gap: .25rem; font-size: .86rem; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: .45rem .6rem; width: 100%; min-width: 0; }
.custom-range input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin: 0; }
legend { font-size: .86rem; font-weight: 600; padding: 0 .3rem; }
.stack label.check, label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
label.check input { width: auto; }
form.inline { display: inline; }
.row-edit summary { cursor: pointer; color: var(--link); font-size: .86rem; }
.row-edit[open] { margin-bottom: .5rem; }
.user-form { max-width: 520px; margin-top: .6rem; }
.conn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; }
.conn { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.conn-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0 .6rem; }

/* ---------- gráficas ---------- */
.chart { margin: 0; position: relative; }
.chart-title { font-size: 1.05rem; font-weight: 600; margin-bottom: .5rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .82rem; color: var(--text-2); margin-bottom: .35rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.chart-key { width: 16px; height: 0; border-top: 2px solid currentColor; display: inline-block; }
.chart-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-plot text { font: 11px var(--font); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-plot .bar-label { font-size: 12px; fill: var(--text-2); }
.chart-plot .bar-value { font-size: 12px; fill: var(--text); font-weight: 600; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: .45rem .6rem; font-size: .8rem; box-shadow: 0 4px 12px rgba(16, 24, 40, .14); z-index: 5; min-width: 130px; max-width: 260px; }
.chart-tip[hidden] { display: none; }
.chart-tip-head { color: var(--muted); margin-bottom: .2rem; }
.chart-tip-row { display: flex; align-items: center; gap: .45rem; }
.chart-tip-row strong { margin-left: auto; padding-left: .75rem; font-variant-numeric: tabular-nums; color: var(--text); }
.chart-tip-row span { color: var(--text-2); }
.chart-empty { color: var(--muted); padding: 1.5rem 0; }
.chart details { margin-top: .5rem; font-size: .82rem; }
.chart details summary { cursor: pointer; color: var(--link); }
.chart details .table { margin-top: .4rem; }

/* ---------- asistente ---------- */
.assistant { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1rem; align-items: start; }
.conv-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.conv-list ul { list-style: none; margin: .75rem 0 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.conv-list a { display: block; padding: .45rem .5rem; border-radius: 7px; text-decoration: none; color: var(--text); }
.conv-list a:hover, .conv-list a.active { background: var(--surface-2); }
.conv-list a.active { box-shadow: inset 3px 0 0 var(--brand); }
.conv-title { display: block; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-date { display: block; font-size: .74rem; color: var(--muted); }
.chat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; min-width: 0; }
.chat-head h2 { margin-bottom: .25rem; }
.chat-log { display: grid; gap: .9rem; margin: 1rem 0; min-height: 200px; max-height: 62vh; overflow-y: auto; padding-right: .25rem; }
.msg { max-width: 78ch; }
.msg-user { justify-self: end; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px 12px 2px 12px; padding: .55rem .8rem; }
.msg-who { font-size: .74rem; color: var(--muted); margin-bottom: .15rem; }
.msg-body { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-body.md { white-space: normal; }
.msg-body.md p, .msg-body.md ul, .msg-body.md ol { margin: 0 0 .6rem; }
.msg-body.md ul, .msg-body.md ol { padding-left: 1.2rem; }
.msg-body.md h3, .msg-body.md h4 { font-size: .95rem; margin: .8rem 0 .35rem; display: block; }
.msg-status { font-size: .84rem; color: var(--text-2); display: grid; gap: .15rem; }
.msg-status .working::after { content: "…"; }
.msg-error .msg-body { color: var(--error-fg); }
.chat-form { display: flex; gap: .6rem; align-items: end; }
.chat-form textarea { resize: vertical; min-height: 2.8rem; }
.suggest { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font: inherit; font-size: .84rem; text-align: left; padding: .4rem .7rem; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; }
.chip:hover { background: var(--surface-2); }
.suggest-static { text-align: left; display: inline-block; color: var(--text-2); padding-left: 1.2rem; }

/* ---------- acceso ---------- */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; width: min(400px, 100%); box-shadow: 0 8px 30px rgba(16, 24, 40, .08); }
.auth-card h1 { margin: 1.25rem 0 1rem; }
.brand-auth { color: var(--text); padding: 0; }
.brand-auth .brand-sub { color: var(--muted); }
.auth-foot { font-size: .78rem; color: var(--muted); margin: 1rem 0 0; }
.error-code { font-size: 2.5rem; font-weight: 700; color: var(--muted); margin: 0; }

/* ---------- adaptable ---------- */
@media (max-width: 1100px) {
  .kpi-grid, .kpi-grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  .menu-btn { display: inline-flex; font: inherit; font-weight: 600; padding: .4rem .7rem; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
  .main-col { padding: .75rem 1rem 2rem; }
  .topbar h1 { margin-right: 0; flex: 1; }
  .store-switch { flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .presets { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; }
  .assistant { grid-template-columns: minmax(0, 1fr); }
  .conv-list ul { max-height: 160px; }
  .defs { grid-template-columns: minmax(0, 1fr); }
  .defs dd { margin-bottom: .5rem; }
  .chat-log { max-height: 55vh; }
}
@media (max-width: 480px) {
  .kpi-value { font-size: 1.3rem; }
  .card { padding: .9rem; }
  .chat-form { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media print {
  .sidebar, .topbar .store-switch, .filters .presets, .custom-range, .menu-btn, .chat-form { display: none !important; }
  .shell { display: block; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
