/*
 * NextShift · Componentes base (estilo Apple HIG). Los valores salen de tema.css (cargar antes).
 * Sin colores ni medidas sueltas: solo variables del tema.
 */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--bg-grouped);
    color: var(--label);
    font-size: var(--fs-body);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: var(--sys-blue); text-decoration: none; }
a:hover { opacity: .8; }
h1, h2, h3 { margin: 0 0 var(--sp-1); color: var(--label); font-family: var(--font-display); letter-spacing: -.01em; }
h1 { font-size: var(--fs-large-title); font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: var(--fs-headline); font-weight: 600; }
h3 { font-size: var(--fs-body); font-weight: 600; }
p { margin: 0 0 var(--sp-2); color: var(--label-2); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }
::selection { background: var(--tint-blue); }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------------------------------------------------------------- Barra superior translúcida */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    background: var(--chrome); color: var(--label);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-bottom: .5px solid var(--chrome-border);
    padding: 0 var(--sp-5); min-height: 56px;
    position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; flex: 1 1 auto; }
.brand { display: flex; align-items: center; gap: var(--sp-2); color: var(--label); flex-shrink: 0; min-height: var(--tap); }
.brand-text b { display: block; font-size: var(--fs-body); font-weight: 700; }
.brand-text span { display: block; font-size: var(--fs-caption2); color: var(--label-2); font-weight: 500; }
.navlinks { display: flex; gap: var(--sp-1); min-width: 0; }
.navlink {
    display: flex; align-items: center; gap: 6px; padding: 0 var(--sp-3); min-height: 36px; white-space: nowrap;
    color: var(--label-2); font-size: var(--fs-subhead); font-weight: 500; border-radius: var(--r-btn);
    transition: background .15s ease, color .15s ease;
}
.navlink svg { width: 20px; height: 20px; flex-shrink: 0; }
/* Íconos SF: puntos rellenos; al activar la sección la forma principal se rellena suave (como la barra de pestañas de iOS) */
.ic .dot { fill: currentColor; stroke: none; }
.ic .rel { fill: transparent; transition: fill .2s ease; }
.navlink.active .ic .rel { fill: currentColor; fill-opacity: .2; }
.navlink:hover .ic .rel { fill: currentColor; fill-opacity: .08; }
.topbar-right .btn-ghost .ic { width: 20px; height: 20px; }
.navlink:hover { color: var(--label); background: var(--fill); opacity: 1; }
.navlink.active { color: var(--sys-blue); background: var(--tint-blue); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }
.user-pill { display: flex; align-items: center; gap: var(--sp-2); color: var(--label-2); font-size: var(--fs-footnote); min-height: var(--tap); }
.user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--sys-blue);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: var(--fs-footnote); color: var(--on-accent);
}

/* ---------------------------------------------------------------- Página */
.page { flex: 1; max-width: 1400px; width: 100%; margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-8); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: var(--sp-5); flex-wrap: wrap; gap: var(--sp-3); }
.page-head p { max-width: 900px; }

/* ---------------------------------------------------------------- Tarjetas (grupos) */
.card { background: var(--bg-elevated); border-radius: var(--r-card); box-shadow: var(--shadow-1); padding: var(--sp-4) var(--sp-5); }
.card + .card { margin-top: var(--sp-5); }
.card > h2:first-child { margin-bottom: var(--sp-2); }

/* Lista agrupada tipo Ajustes de iPhone:
   <div class="glist-title">Título</div><div class="glist"><div class="glist-row">…</div></div> */
/* ancho de lectura cómodo, como Ajustes */
.glist, .glist-title, .glist-foot, .glist-actions { max-width: 980px; }
.glist-title { font-size: var(--fs-footnote); color: var(--label-2); text-transform: uppercase; letter-spacing: .02em; margin: var(--sp-6) var(--sp-4) var(--sp-2); }
.glist-title:first-child { margin-top: 0; }
.glist { background: var(--bg-elevated); border-radius: var(--r-card); box-shadow: var(--shadow-1); overflow: hidden; }
.glist-row {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
    min-height: var(--tap); padding: var(--sp-2) var(--sp-4); position: relative;
}
.glist-row + .glist-row::before { content: ''; position: absolute; top: 0; left: var(--sp-4); right: 0; border-top: .5px solid var(--separator); }
.glist-label { flex: 1 1 auto; min-width: 0; }
.glist-label b { display: block; font-weight: 400; color: var(--label); font-size: var(--fs-body); }
.glist-label small { display: block; color: var(--label-2); font-size: var(--fs-footnote); line-height: 1.35; margin-top: 2px; }
.glist-value { flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-2); }
.glist-value .input { width: 140px; text-align: right; }
.glist-value .input.input-ancho { width: 300px; text-align: left; }
.glist-foot { font-size: var(--fs-footnote); color: var(--label-2); margin: var(--sp-2) var(--sp-4) 0; }
.glist-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-4); }
.glist-text { padding: var(--sp-3) var(--sp-4); }
.glist-text li { margin-bottom: var(--sp-2); }

/* ---------------------------------------------------------------- Indicadores (KPI) */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
a.kpi-card { text-decoration: none; display: block; color: inherit; }
.kpi-card { background: var(--bg-elevated); border-radius: var(--r-card); padding: var(--sp-4); box-shadow: var(--shadow-1); transition: transform .15s ease, box-shadow .15s ease; }
a.kpi-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); opacity: 1; }
.kpi-label { font-size: var(--fs-footnote); color: var(--label-2); font-weight: 500; margin-bottom: var(--sp-1); }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--label); font-family: var(--font-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: var(--fs-caption); color: var(--label-2); margin-top: 2px; }
.kpi-card.red .kpi-value { color: var(--sys-red); }
.kpi-card.yellow .kpi-value { color: var(--sys-orange); }
.kpi-card.green .kpi-value { color: var(--sys-green); }
.kpi-card.blue .kpi-value { color: var(--sys-blue); }

/* ---------------------------------------------------------------- Botones */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--tap); padding: 0 var(--sp-4); border-radius: var(--r-btn);
    font-family: var(--font-sans); font-size: var(--fs-body); font-weight: 600; line-height: 1;
    border: 0; cursor: pointer; white-space: nowrap; text-decoration: none;
    transition: background .15s ease, opacity .15s ease, transform .05s ease;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .4; cursor: default; }
.btn-primary { background: var(--sys-blue); color: var(--on-accent); }
.btn-primary:hover { background: var(--sys-blue); opacity: .88; color: var(--on-accent); }
.btn-outline { background: var(--fill); color: var(--sys-blue); }
.btn-outline:hover { background: var(--fill-strong); opacity: 1; }
.btn-ghost { background: transparent; color: var(--sys-blue); }
.btn-ghost:hover { background: var(--fill); opacity: 1; }
.btn-danger { background: var(--tint-red); color: var(--sys-red-text); }
.btn-danger:hover { background: var(--sys-red); color: var(--on-accent); opacity: 1; }
.btn-sm { min-height: var(--tap-compact); padding: 0 var(--sp-3); font-size: var(--fs-footnote); }
.btn-block { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--sys-blue); font-size: var(--fs-footnote); cursor: pointer; font-family: inherit; min-height: var(--tap-compact); }
.linkbtn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- Formularios */
.field { margin-bottom: var(--sp-4); }
.field-label { display: block; font-size: var(--fs-footnote); font-weight: 500; color: var(--label-2); margin-bottom: 6px; }
.field-hint { font-size: var(--fs-caption); color: var(--label-2); margin-top: var(--sp-1); line-height: 1.35; }
.input, select.input, textarea.input {
    width: 100%; min-height: var(--tap); padding: 0 var(--sp-3);
    border: .5px solid var(--separator-opaque); border-radius: var(--r-btn);
    font-size: var(--fs-body); font-family: var(--font-sans); background: var(--bg-elevated); color: var(--label);
    transition: border-color .15s ease, box-shadow .15s ease;
}
textarea.input { padding: var(--sp-2) var(--sp-3); min-height: 88px; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 32px;
    background-image: linear-gradient(45deg, transparent 50%, var(--label-2) 50%), linear-gradient(135deg, var(--label-2) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input::placeholder { color: var(--label-3); }
.input:focus { outline: none; border-color: var(--sys-blue); box-shadow: var(--focus-ring); }
.input[disabled] { background: var(--fill); color: var(--label-2); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--sys-blue); vertical-align: middle; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 var(--sp-5); }
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end; margin-bottom: var(--sp-4); }
.filter-bar .field { margin-bottom: 0; min-width: 160px; }

/* ---------------------------------------------------------------- Pestañas como control segmentado */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: var(--fill); border-radius: var(--r-btn); margin-bottom: var(--sp-5); }
.tab { display: inline-flex; align-items: center; min-height: 32px; padding: 0 var(--sp-4); font-size: var(--fs-footnote); font-weight: 500; color: var(--label); border-radius: 7px; }
.tab:hover { opacity: 1; background: var(--fill); }
.tab.active { background: var(--seg-on); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }

/* ---------------------------------------------------------------- Tablas */
.table-wrap { overflow-x: auto; border-radius: var(--r-card); background: var(--bg-elevated); box-shadow: 0 0 0 .5px var(--separator); }
.card .table-wrap { box-shadow: none; border: .5px solid var(--separator); border-radius: var(--r-btn); }

/* ---------------------------------------------------------------- Indicadores pequeños (badges) */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px var(--sp-2); border-radius: var(--r-pill); font-size: var(--fs-caption); font-weight: 600; white-space: nowrap; }
.badge-red { background: var(--tint-red); color: var(--sys-red-text); }
.badge-yellow { background: var(--tint-orange); color: var(--sys-orange-text); }
.badge-green { background: var(--tint-green); color: var(--sys-green-text); }
.badge-blue { background: var(--tint-blue); color: var(--sys-blue-text); }
.badge-gray { background: var(--fill); color: var(--label-2); }

/* ---------------------------------------------------------------- Ingreso */
.login-screen { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg-grouped); min-height: 100vh; padding: var(--sp-4); }
.login-card { background: var(--bg-elevated); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: var(--sp-8); width: 100%; max-width: 380px; overflow: hidden; }
.login-card h1 { font-size: var(--fs-title2); text-align: center; }
.login-card p { text-align: center; font-size: var(--fs-subhead); margin-bottom: var(--sp-5); }
.login-logo { display: block; max-width: 220px; height: auto; margin: 0 auto var(--sp-4); }
.login-foot { text-align: center; font-size: var(--fs-footnote); color: var(--label-2); margin-top: var(--sp-4); }
.login-olvide { display: block; text-align: right; font-size: var(--fs-footnote); margin: calc(-1 * var(--sp-2)) 0 var(--sp-4); }

/* ---------------------------------------------------------------- Avisos */
.alert { display: flex; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-card); font-size: var(--fs-subhead); margin-bottom: var(--sp-4); line-height: 1.4; }
.alert > svg { flex-shrink: 0; margin-top: 1px; }
.alert-red { background: var(--tint-red); color: var(--sys-red-text); }
.alert-green { background: var(--tint-green); color: var(--sys-green-text); }
.alert-yellow { background: var(--tint-orange); color: var(--sys-orange-text); }
.alert-gray { background: var(--fill); color: var(--label); }
.toast-wrap { position: fixed; top: 72px; right: var(--sp-5); z-index: 50; }
.toast {
    display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop); font-size: var(--fs-subhead); font-weight: 500; max-width: 440px;
    background: var(--chrome); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.toast.success { color: var(--sys-green-text); }
.toast.error { color: var(--sys-red-text); }

.muted { color: var(--label-2); }
.mt-0 { margin-top: 0; }
.footer-note { text-align: center; padding: var(--sp-4); font-size: var(--fs-caption); color: var(--label-2); }

/* ---------------------------------------------------------------- Mostrar / ocultar contraseña (ver-clave.js) */
.pw-wrap { position: relative; display: block; }
.pw-wrap > .input { width: 100%; padding-right: var(--tap); }
.filter-bar .pw-wrap, td .pw-wrap { display: inline-block; }
.pw-ojo { position: absolute; right: 0; top: 50%; transform: translateY(-50%); background: none; border: 0; width: var(--tap); height: var(--tap); cursor: pointer; color: var(--label-2); line-height: 0; border-radius: var(--r-btn); display: flex; align-items: center; justify-content: center; }
.pw-ojo:hover { color: var(--label); }
td .pw-ojo { width: var(--tap-compact); height: var(--tap-compact); }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 700px) { .hide-sm { display: none; } }
@media (max-width: 640px) {
    .page { padding: var(--sp-4) var(--sp-4) var(--sp-8); }
    h1 { font-size: 24px; }
    .kpi-value { font-size: 24px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .field { min-width: 0; }
    .filter-bar .btn { width: 100%; }
    .card { padding: var(--sp-4); border-radius: var(--r-card); }
    .glist-row { flex-wrap: wrap; }
    .glist-value { width: 100%; }
    .glist-value .input, .glist-value .input.input-ancho { width: 100%; text-align: left; }
}
/* En pantallas táctiles todo control tiene 44 px (también los compactos de las tablas). */
@media (pointer: coarse) {
    :root { --tap-compact: var(--tap); }
}

/* ---------------------------------------------------------------- Impresión */
@media print {
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    body { background: #fff !important; color: #000 !important; }
    .topbar, .btn, .filter-bar, .no-print { display: none !important; }
    .page { max-width: 100%; padding: 0; margin: 0; }
    .table-wrap { overflow: visible !important; box-shadow: none; }
    .card, .kpi-card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
    a[href] { text-decoration: none; color: inherit; }
}
@page { margin: 12mm; }
