/* =====================================================================
   BALANCE GROUP · COMPONENTES DE APLICACIÓN (shell, navegación, formularios)
   ---------------------------------------------------------------------
   Complementa a _base.css (tokens + cards + gráficos). Se inyecta en las
   pantallas de sistema (shell, login, listados, ABM). Todo usa los tokens
   de _base.css, así el tema oscuro y los cambios de marca se heredan.
   ===================================================================== */

/* ---------- 1. SHELL: sidebar fija + topbar + contenido ---------- */
.app { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }
.app.is-collapsed { grid-template-columns: 72px minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
  box-shadow: 1px 0 0 rgba(10,10,11,.02), 12px 0 32px -24px rgba(10,10,11,.12);
}
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sidebar__brand .bg-brand__mark { width: 36px; height: 36px; border-radius: 10px; font-size: 13px; }
.sidebar__brand b { display: block; font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.sidebar__brand small { display: block; color: var(--muted); font-size: 11.5px; }

.nav__group { font-size: 10.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav__item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--ink-2); font-size: 13.5px; font-weight: 500; text-decoration: none; position: relative;
  transition: background-color .15s, color .15s;
}
.nav__item svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.nav__item:hover { background: var(--surface-3); color: var(--ink); }
.nav__item.is-active { background: var(--accent-wash); color: var(--ink); font-weight: 600; }
.nav__item.is-active svg { opacity: 1; color: var(--accent); }
/* Marcador naranja a la izquierda del ítem activo */
.nav__item.is-active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--accent-2), var(--accent-deep));
}
.nav__badge { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); }
.nav__badge--accent { background: linear-gradient(135deg, var(--accent-2), var(--accent-deep)); color: #fff; }
.sidebar__foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }

/* Usuario (pie del sidebar y topbar) */
.user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.user:hover { background: var(--surface-3); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--s3-hi), var(--s3-lo)); color: #fff; font-weight: 650; font-size: 12.5px;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border);
}
.user b { display: block; font-size: 13px; font-weight: 600; line-height: 1.2; }
.user small { color: var(--muted); font-size: 11.5px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 62px;
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__search { flex: 1; max-width: 460px; position: relative; }
.topbar__search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.topbar__search input { padding-left: 34px; }
.topbar__spacer { flex: 1; }
.icon-btn {
  position: relative; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn .dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }

.content { padding: 24px 24px 56px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 2px 0 0; font-size: 26px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

/* Rejillas de contenido */
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* Móvil: el sidebar se convierte en cajón (drawer) */
.scrim { display: none; position: fixed; inset: 0; background: rgba(10,10,11,.4); z-index: 29; }
@media (max-width: 920px) {
  .app, .app.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; width: 272px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-pop); }
  .app.is-open .sidebar { transform: none; }
  .app.is-open .scrim { display: block; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px 16px 48px; }
}

/* ---------- 2. FORMULARIOS ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field .error { font-size: 11.5px; color: var(--crit-ink); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-size: 13.5px; line-height: 1.4;
  box-shadow: 0 1px 2px rgba(10,10,11,.03) inset;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.input[aria-invalid="true"] { border-color: var(--crit); box-shadow: 0 0 0 3px rgba(220,38,38,.10); }
.select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236e6e76' stroke-width='2'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
.textarea { min-height: 96px; resize: vertical; }
.input-group { display: flex; }
.input-group .input { border-radius: 10px 0 0 10px; }
.input-group .addon { display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 10px 10px 0; background: var(--surface-3); color: var(--muted); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }

/* Interruptor (toggle) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 38px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(10,10,11,.25); transition: transform .15s; }
.switch input:checked + i { background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Checkbox / radio con acento */
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- 3. BOTONES (extensión de .bg-btn) ---------- */
.bg-btn--ghost { border-color: transparent; background: transparent; box-shadow: none; }
.bg-btn--ghost:hover { background: var(--surface-3); }
.bg-btn--danger { border-color: transparent; background: var(--crit); color: #fff; font-weight: 600; }
.bg-btn--danger:hover { background: var(--crit-ink); }
.bg-btn--lg { padding: 10px 16px; font-size: 14px; border-radius: 11px; }
.bg-btn--sm { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.bg-btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 4. TABLAS DE DATOS (extensión de .bg-table) ---------- */
.table-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.table-tools .input { width: 260px; max-width: 100%; }
.table-wrap { overflow: auto; }
.table-wrap .bg-table { font-size: 13px; }
.table-wrap .bg-table th { background: var(--surface-2); }
.table-wrap .bg-table td { white-space: nowrap; }
.bg-table th.sortable { cursor: pointer; user-select: none; }
.bg-table th.sortable::after { content: " ↕"; color: var(--border-strong); }
.bg-table th.sorted-asc::after { content: " ↑"; color: var(--accent); }
.bg-table th.sorted-desc::after { content: " ↓"; color: var(--accent); }
.bg-table tr.is-selected td { background: var(--accent-wash); }
.cell-main { display: flex; align-items: center; gap: 10px; }
.cell-main b { display: block; font-weight: 600; }
.cell-main small { display: block; color: var(--muted); font-size: 11.5px; }
.row-actions { display: inline-flex; gap: 4px; opacity: 0; transition: opacity .15s; }
tr:hover .row-actions { opacity: 1; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.pager__pages { display: inline-flex; gap: 4px; }
.pager__pages button { min-width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 12.5px; }
.pager__pages button:hover { background: var(--surface-3); }
.pager__pages button[aria-current="page"] { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #fff; font-weight: 600; box-shadow: var(--shadow-accent); }

/* Mini barra de progreso en celda */
.cell-bar { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.cell-bar .bg-meter { flex: 1; height: 6px; }
.cell-bar b { font-variant-numeric: tabular-nums; font-size: 12px; min-width: 36px; text-align: right; }

/* ---------- 5. TABS, MODAL, TOAST, VACÍOS ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 20px; overflow-x: auto; scrollbar-width: none; }
.tabs button { white-space: nowrap; }
.tabs button { border: 0; background: transparent; padding: 12px 14px; font-size: 13.5px; font-weight: 500; color: var(--muted); cursor: pointer; position: relative; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--accent-deep), var(--accent-2)); }

.modal-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(10,10,11,.45); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-scrim.is-open { display: flex; }
.modal { width: min(560px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop); border: 1px solid var(--border); overflow: hidden; animation: bg-fade .18s ease both; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 14px; border-bottom: 1px solid var(--border); }
.modal__head h3 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.015em; }
.modal__body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; background: var(--surface-2); border-top: 1px solid var(--border); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 360px; padding: 11px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-pop); font-size: 13px; animation: bg-fade .2s ease both; }
.toast i { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--s-other); }
.toast--good i { background: var(--good); } .toast--crit i { background: var(--crit); } .toast--warn i { background: var(--warn); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty__icon { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent-wash), var(--s2-wash)); color: var(--accent); }
.empty__icon svg { width: 26px; height: 26px; }
.empty h4 { margin: 0 0 4px; color: var(--ink); font-size: 15px; font-weight: 600; }
.empty p { margin: 0 0 14px; font-size: 13px; }

/* Esqueleto de carga (shimmer) */
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 8px; min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); animation: bg-shimmer 1.4s infinite; }
@keyframes bg-shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } }

/* ---------- 6. LOGIN (pantalla partida) ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login__brand {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 44px;
  background: #0a0a0b; color: #fff;
}
.login__brand::before { content: ""; position: absolute; inset: 0; background:
  radial-gradient(640px 420px at 20% 10%, rgba(242,107,29,.55), transparent 60%),
  radial-gradient(520px 420px at 90% 90%, rgba(22,153,108,.35), transparent 60%); }
.login__brand > * { position: relative; }
.login__brand h2 { color: #fff; font-size: 38px; font-weight: 700; letter-spacing: -0.035em; line-height: 1.08; margin: 0 0 12px; max-width: 480px; }
.login__brand p { color: rgba(255,255,255,.72); max-width: 440px; font-size: 15px; }
.login__form { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.login__card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 860px) { .login { grid-template-columns: minmax(0, 1fr); } .login__brand { min-height: 260px; padding: 28px; } .login__brand h2 { font-size: 28px; } }
