/* =====================================================================
   ONE UI · Sistema de diseño de Mistitec ONE
   Lo comparten el portal y todas las aplicaciones embebidas.
   Tema: data-theme="light|dark" en <html>; sin atributo sigue al sistema.
   ===================================================================== */

:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(29, 95, 209, .06), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --surface-3: #eef0f4;
    --hover: rgba(15, 23, 42, .045);
    --border: #e5e7ec;
    --border-strong: #d3d7df;
    --text: #0f1729;
    --text-2: #4b5468;
    --text-3: #8a92a3;
    --brand: #004a99;
    --brand-2: #1e88e5;
    --brand-hover: #003b7a;
    --brand-soft: rgba(0, 74, 153, .09);
    --brand-ink: #ffffff;
    --ring: 0 0 0 3px rgba(29, 95, 209, .18);

    /* Estados (fijos): siempre acompañados de icono + texto */
    --good: #0ca30c;      --good-ink: #0b7a0b;   --good-soft: rgba(12, 163, 12, .10);
    --warn: #fab219;      --warn-ink: #9a6200;   --warn-soft: rgba(250, 178, 25, .16);
    --serious: #ec835a;   --serious-ink: #b2481f;
    --crit: #d03b3b;      --crit-ink: #b42323;   --crit-soft: rgba(208, 59, 59, .10);
    --violet-ink: #5243c2; --violet-soft: rgba(98, 80, 214, .10);

    /* Series de gráficos (paleta validada CVD) */
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --grid: #eceef2;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 12px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 40px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
    --ease: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0b0d12;
        --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(57, 135, 229, .10), transparent 60%);
        --surface: #12151c;
        --surface-2: #161a22;
        --surface-3: #1d222c;
        --hover: rgba(255, 255, 255, .05);
        --border: #232835;
        --border-strong: #2f3646;
        --text: #eef1f6;
        --text-2: #aab2c2;
        --text-3: #6f7889;
        --brand: #3b82f6;
        --brand-hover: #5a96f8;
        --brand-soft: rgba(59, 130, 246, .14);
        --ring: 0 0 0 3px rgba(59, 130, 246, .28);
        --good-ink: #3fcf3f; --good-soft: rgba(12, 163, 12, .16);
        --warn-ink: #fbc24a; --warn-soft: rgba(250, 178, 25, .14);
        --serious-ink: #f29b78;
        --crit-ink: #f07272; --crit-soft: rgba(208, 59, 59, .18);
        --violet-ink: #a59bf0; --violet-soft: rgba(144, 133, 233, .16);
        --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
        --grid: #1f2430;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .3);
        --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b0d12;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(57, 135, 229, .10), transparent 60%);
    --surface: #12151c;
    --surface-2: #161a22;
    --surface-3: #1d222c;
    --hover: rgba(255, 255, 255, .05);
    --border: #232835;
    --border-strong: #2f3646;
    --text: #eef1f6;
    --text-2: #aab2c2;
    --text-3: #6f7889;
    --brand: #3b82f6;
    --brand-hover: #5a96f8;
    --brand-soft: rgba(59, 130, 246, .14);
    --ring: 0 0 0 3px rgba(59, 130, 246, .28);
    --good-ink: #3fcf3f; --good-soft: rgba(12, 163, 12, .16);
    --warn-ink: #fbc24a; --warn-soft: rgba(250, 178, 25, .14);
    --serious-ink: #f29b78;
    --crit-ink: #f07272; --crit-soft: rgba(208, 59, 59, .18);
    --violet-ink: #a59bf0; --violet-soft: rgba(144, 133, 233, .16);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --grid: #1f2430;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
}

/* ------------------------------ Base ------------------------------ */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg-grad), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font: 14px/1.5 var(--font);
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    -webkit-font-smoothing: antialiased;
    transition: background-color .2s, color .2s;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 650; letter-spacing: -.015em; color: var(--text); }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: .92em; }
::selection { background: var(--brand-soft); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.tnum { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------ Botones ------------------------------ */

.btn {
    --h: 36px;
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: var(--h); padding: 0 14px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
    font-weight: 550; font-size: 13.5px; white-space: nowrap;
    cursor: pointer; user-select: none;
    box-shadow: var(--shadow-sm);
    transition: background .15s, border-color .15s, color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn i { font-size: 15px; line-height: 1; }
.btn-primary { background: var(--brand); border-color: transparent; color: var(--brand-ink); box-shadow: 0 1px 2px rgba(0, 74, 153, .3), inset 0 1px 0 rgba(255, 255, 255, .15); }
.btn-primary:hover { background: var(--brand-hover); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); color: var(--text); border-color: transparent; }
.btn-danger { color: var(--crit-ink); }
.btn-danger:hover { background: var(--crit-soft); border-color: transparent; }
.btn-danger-solid { background: var(--crit); color: #fff; border-color: transparent; }
.btn-danger-solid:hover { background: #b93030; border-color: transparent; }
.btn-sm { --h: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { --h: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn-icon { width: var(--h); padding: 0; }
.btn-block { width: 100%; }

/* ------------------------------ Formularios ------------------------------ */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.fields { display: grid; gap: 14px; }
.fields-2 { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields-3 { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

.input, .select, .textarea {
    width: 100%; height: 38px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 13.5px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 32px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='%238a92a3'%3E%3Cpath d='M4.4 6.2a.75.75 0 0 1 1.06 0L8 8.74l2.54-2.54a.75.75 0 1 1 1.06 1.06L8.53 10.33a.75.75 0 0 1-1.06 0L4.4 7.26a.75.75 0 0 1 0-1.06Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input-sm, .select.input-sm { height: 32px; font-size: 13px; }
input[type="color"].input { padding: 3px; width: 46px; cursor: pointer; }
input[type="range"] { accent-color: var(--brand); width: 100%; }
input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; cursor: pointer; }

.search { position: relative; display: flex; align-items: center; }
.search > i { position: absolute; left: 11px; color: var(--text-3); font-size: 14px; pointer-events: none; }
.search .input { padding-left: 33px; }

/* ------------------------------ Superficies ------------------------------ */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card-head h3 i { color: var(--text-3); }
.card-body { padding: 18px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

/* ------------------------------ Badges ------------------------------ */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    height: 22px; padding: 0 8px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
}
.badge i { font-size: 11px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-good { background: var(--good-soft); color: var(--good-ink); }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge-crit { background: var(--crit-soft); color: var(--crit-ink); }
.badge-violet { background: var(--violet-soft); color: var(--violet-ink); }
.badge-outline { background: transparent; border: 1px solid var(--border); }
.badge-square { border-radius: 6px; }

.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.tag .sw { width: 8px; height: 8px; border-radius: 3px; flex: none; }

.kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
    border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
    font: 600 11px var(--font); color: var(--text-3); background: var(--surface); }

/* ------------------------------ Avatares ------------------------------ */

.avatar { --size: 30px; width: var(--size); height: var(--size); flex: none; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: calc(var(--size) * .38); font-weight: 650; color: #fff; letter-spacing: .02em;
    background: var(--brand); box-shadow: 0 0 0 2px var(--surface); }
.avatar-sm { --size: 24px; }
.avatar-lg { --size: 40px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; }

.icon-tile { --size: 36px; width: var(--size); height: var(--size); flex: none; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center; font-size: calc(var(--size) * .48);
    color: var(--tile, var(--brand)); background: color-mix(in srgb, var(--tile, var(--brand)) 13%, transparent);
    border: 1px solid color-mix(in srgb, var(--tile, var(--brand)) 18%, transparent); }
.icon-tile-lg { --size: 46px; border-radius: 13px; }
.icon-tile-sm { --size: 28px; border-radius: 8px; }

/* ------------------------------ Tablas ------------------------------ */

.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { position: sticky; top: 0; z-index: 1; text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-3); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-3); }

/* ------------------------------ Switch ------------------------------ */

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: var(--border-strong); cursor: pointer; transition: background .18s; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s var(--ease); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }
.switch input:focus-visible + span { box-shadow: var(--ring); }

/* ------------------------------ Segmented / Tabs ------------------------------ */

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); }
.seg button { white-space: nowrap; height: 28px; padding: 0 11px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: background .15s, color .15s; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs button { position: relative; height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--text-2); font-weight: 550; font-size: 13.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); }
.tabs button.active::after { content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--brand); }
.tabs .count { font-size: 11px; padding: 0 6px; border-radius: 10px; background: var(--surface-3); color: var(--text-3); }

/* ------------------------------ Progreso ------------------------------ */

.progress { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 6px; background: var(--brand); transition: width .5s var(--ease); }
.progress.good > span { background: var(--good); }
.progress.warn > span { background: var(--warn); }
.progress.crit > span { background: var(--crit); }

.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.health::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.health.verde { color: var(--good-ink); }
.health.ambar { color: var(--warn-ink); }
.health.rojo { color: var(--crit-ink); }

/* ------------------------------ Modal & Drawer ------------------------------ */

.overlay { position: fixed; inset: 0; z-index: 900; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px;
    background: rgba(8, 12, 20, .45); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .18s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.modal { width: 100%; max-width: 560px; max-height: 84vh; display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    transform: translateY(8px) scale(.985); transition: transform .22s var(--ease); }
.overlay.open .modal { transform: none; }
.modal-lg { max-width: 760px; }
.modal-sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; }
.modal-head h3 { font-size: 16px; }
.modal-head p { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.modal-body { padding: 4px 20px 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.drawer-overlay { align-items: stretch; justify-content: flex-end; padding: 0; }
.drawer { width: min(720px, 100vw); height: 100%; display: flex; flex-direction: column; background: var(--surface);
    border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: translateX(24px); transition: transform .25s var(--ease); }
.overlay.open .drawer { transform: none; }

/* ------------------------------ Toast ------------------------------ */

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 1200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px; padding: 11px 14px; border-radius: 10px;
    background: var(--text); color: var(--bg); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); pointer-events: auto;
    animation: toastIn .28s var(--ease); }
.toast i { font-size: 16px; }
.toast.ok i { color: #4ade80; }
.toast.err i { color: #f87171; }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ------------------------------ Estados vacíos / carga ------------------------------ */

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 44px 20px; text-align: center; color: var(--text-3); }
.empty > i { font-size: 28px; margin-bottom: 6px; color: var(--text-3); opacity: .7; }
.empty strong { color: var(--text); font-weight: 600; }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spin { animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade-in { animation: fadeIn .3s var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }

/* ------------------------------ Tooltip flotante ------------------------------ */

.one-tip { position: fixed; z-index: 1300; pointer-events: none; padding: 8px 10px; border-radius: 8px; min-width: 120px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 12px; line-height: 1.45;
    opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s; }
.one-tip.show { opacity: 1; transform: none; }
.one-tip b { font-weight: 650; }
.one-tip .tip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.one-tip .tip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.one-tip .sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

@media (max-width: 720px) {
    .fields-2, .fields-3 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
