    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    /* Columnas ordenables */
    th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
    th.sortable:hover { background: rgba(26,58,92,.08); }
    .sort-icon { font-size: 11px; opacity: .6; margin-left: 3px; }

    :root {
      --primary:    #1a3a5c;
      --primary-dk: #0f2540;
      --accent:     #e8a020;
      --bg:         #f0f4f8;
      --surface:    #ffffff;
      --border:     #d1dce8;
      --text:       #1a2535;
      --muted:      #6b7a8d;
      --error:      #dc3545;
      --success:    #198754;
      --radius:     12px;
      --shadow:     0 4px 24px rgba(0,0,0,.10);
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: var(--bg);
      min-height: 100vh;
    }

    /* ══ LOGIN ══ */
    #page-login {
      width: 100%; min-height: 100vh;
      display: flex; align-items: center; justify-content: center;
      background: linear-gradient(135deg, var(--primary-dk) 0%, var(--primary) 60%, #1e4d7a 100%);
      padding: 24px;
    }

    .login-card {
      background: var(--surface); border-radius: var(--radius);
      box-shadow: var(--shadow); padding: 48px 40px;
      width: 100%; max-width: 420px;
    }

    .login-logo { text-align: center; margin-bottom: 32px; }
    .login-logo .logo-icon {
      width: 72px; height: 72px; background: var(--primary);
      border-radius: 18px; display: inline-flex;
      align-items: center; justify-content: center;
      font-size: 32px; margin-bottom: 14px;
    }
    .login-logo h1 { font-size: 22px; font-weight: 700; color: var(--primary); letter-spacing: -.3px; }
    .login-logo p  { font-size: 13px; color: var(--muted); margin-top: 4px; }

    .form-group { margin-bottom: 20px; }
    .form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
    .input-wrap { position: relative; }
    .input-wrap input, .input-wrap textarea, .input-wrap select {
      width: 100%; padding: 12px 16px;
      border: 1.5px solid var(--border); border-radius: 8px;
      font-size: 15px; color: var(--text); background: #f8fafc;
      transition: border-color .2s, box-shadow .2s; outline: none;
      font-family: inherit;
    }
    .input-wrap textarea { resize: vertical; min-height: 90px; }
    .input-wrap input:focus, .input-wrap textarea:focus, .input-wrap select:focus {
      border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,58,92,.12); background: #fff;
    }
    .input-wrap .toggle-pass {
      position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
      background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; padding: 0;
    }

    .btn-primary {
      width: 100%; padding: 14px; background: var(--primary);
      color: #fff; border: none; border-radius: 8px;
      font-size: 15px; font-weight: 600; cursor: pointer;
      transition: background .2s, transform .1s; margin-top: 8px;
    }
    .btn-primary:hover  { background: var(--primary-dk); }
    .btn-primary:active { transform: scale(.98); }
    .btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }

    .alert {
      padding: 12px 16px; border-radius: 8px; font-size: 13px;
      font-weight: 500; margin-bottom: 20px; display: none;
    }
    .alert.error   { background: #fef2f2; color: var(--error);   border: 1px solid #fecaca; }
    .alert.success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
    .alert.show    { display: block; }

    .spinner {
      display: inline-block; width: 16px; height: 16px;
      border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
      border-radius: 50%; animation: spin .7s linear infinite;
      vertical-align: middle; margin-right: 8px;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* ══ DASHBOARD ══ */
    #page-dashboard { display: none; flex-direction: column; min-height: 100vh; }

    .topbar {
      background: var(--primary); color: #fff; padding: 0 24px;
      height: 60px; display: flex; align-items: center; justify-content: space-between;
      box-shadow: 0 2px 8px rgba(0,0,0,.2); position: sticky; top: 0; z-index: 100;
    }
    .topbar-brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
    .badge-admin {
      background: var(--accent); color: var(--primary-dk);
      font-size: 10px; font-weight: 700; padding: 2px 8px;
      border-radius: 20px; letter-spacing: .5px; text-transform: uppercase;
    }
    .topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
    .avatar {
      width: 34px; height: 34px; background: var(--accent); border-radius: 50%;
      display: flex; align-items: center; justify-content: center;
      font-weight: 700; font-size: 14px; color: var(--primary-dk); flex-shrink: 0;
    }
    .btn-logout {
      background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
      color: #fff; padding: 6px 14px; border-radius: 6px; font-size: 13px;
      cursor: pointer; transition: background .2s;
    }
    .btn-logout:hover { background: rgba(255,255,255,.25); }

    /* ══ LAYOUT PRINCIPAL ══ */
    .dash-layout { display: flex; flex: 1; }

    .sidebar {
      width: 220px; background: var(--surface);
      border-right: 1px solid var(--border);
      padding: 20px 0; flex-shrink: 0;
      min-height: calc(100vh - 60px);
    }
    .sidebar-item {
      display: flex; align-items: center; gap: 10px;
      padding: 12px 20px; font-size: 14px; font-weight: 500;
      color: var(--muted); cursor: pointer;
      transition: background .15s, color .15s;
      border-left: 3px solid transparent;
    }
    .sidebar-item:hover { background: var(--bg); color: var(--text); }
    .sidebar-item.active {
      background: #eef3f9; color: var(--primary);
      border-left-color: var(--primary); font-weight: 600;
    }
    .sidebar-item .si-icon { font-size: 18px; width: 22px; text-align: center; }

    .main-content { flex: 1; padding: 28px 28px; overflow-y: auto; }

    /* ══ SECCIONES ══ */
    .section { display: none; }
    .section.active { display: block; }

    .section-header {
      display: flex; align-items: center; justify-content: space-between;
      margin-bottom: 24px;
    }
    .section-header h2 { font-size: 20px; font-weight: 700; color: var(--text); }

    .btn-new {
      background: var(--primary); color: #fff;
      border: none; border-radius: 8px;
      padding: 10px 20px; font-size: 14px; font-weight: 600;
      cursor: pointer; transition: background .2s;
      display: flex; align-items: center; gap: 6px;
    }
    .btn-new:hover { background: var(--primary-dk); }

    .btn-subreport {
      padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600;
      cursor: pointer; border: 1.5px solid var(--border);
      background: var(--surface); color: var(--muted);
      transition: background .15s, color .15s, border-color .15s;
    }
    .btn-subreport:hover { background: var(--bg); color: var(--text); }
    .btn-subreport.active { background: var(--primary); color: #fff; border-color: var(--primary); }

    /* ══ TABLA ══ */
    .table-wrap {
      background: var(--surface); border-radius: var(--radius);
      border: 1px solid var(--border); overflow: hidden;
    }
    table { width: 100%; border-collapse: collapse; }
    thead { background: #f5f8fc; }
    th {
      padding: 12px 16px; text-align: left;
      font-size: 11px; font-weight: 700; color: var(--muted);
      text-transform: uppercase; letter-spacing: .6px;
      border-bottom: 1px solid var(--border);
    }
    td {
      padding: 14px 16px; font-size: 14px; color: var(--text);
      border-bottom: 1px solid #f0f4f8; vertical-align: middle;
    }
    tr:last-child td { border-bottom: none; }
    tr:hover td { background: #fafcff; }

    .badge-status {
      display: inline-flex; align-items: center; gap: 5px;
      padding: 4px 10px; border-radius: 20px;
      font-size: 12px; font-weight: 600;
    }
    .badge-status.activo   { background: #dcfce7; color: #166534; }
    .badge-status.inactivo { background: #fee2e2; color: #991b1b; }

    .td-actions { display: flex; gap: 8px; }
    .btn-action {
      padding: 6px 12px; border-radius: 6px; font-size: 12px;
      font-weight: 600; cursor: pointer; border: none; transition: opacity .2s;
    }
    .btn-action:hover { opacity: .8; }
    .btn-edit   { background: #eff6ff; color: #1d4ed8; }
    .btn-toggle { background: #f0fdf4; color: #15803d; }
    .btn-toggle.desactivar { background: #fef2f2; color: #b91c1c; }

    .empty-state {
      text-align: center; padding: 48px 24px;
      color: var(--muted); font-size: 14px;
    }
    .empty-state .es-icon { font-size: 40px; margin-bottom: 12px; }

    /* ══ MODAL ══ */
    .modal-overlay {
      position: fixed; inset: 0; background: rgba(0,0,0,.45);
      display: none; align-items: center; justify-content: center;
      z-index: 200; padding: 20px;
    }
    .modal-overlay.open { display: flex; }
    .modal {
      background: var(--surface); border-radius: var(--radius);
      box-shadow: 0 8px 40px rgba(0,0,0,.2);
      width: 100%; max-width: 540px;
      max-height: 90vh; overflow-y: auto;
    }
    .modal-header {
      padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
      display: flex; align-items: center; justify-content: space-between;
    }
    .modal-header h3 { font-size: 17px; font-weight: 700; color: var(--text); }
    .modal-close {
      background: none; border: none; font-size: 22px;
      color: var(--muted); cursor: pointer; line-height: 1;
    }
    .modal-close:hover { color: var(--text); }
    .modal-body { padding: 24px; }
    .modal-footer {
      padding: 16px 24px; border-top: 1px solid var(--border);
      display: flex; justify-content: flex-end; gap: 10px;
    }
    .btn-cancel {
      padding: 10px 20px; border-radius: 8px; font-size: 14px;
      font-weight: 600; cursor: pointer;
      background: var(--bg); color: var(--text);
      border: 1.5px solid var(--border); transition: background .2s;
    }
    .btn-cancel:hover { background: var(--border); }
    .btn-save {
      padding: 10px 24px; border-radius: 8px; font-size: 14px;
      font-weight: 600; cursor: pointer; border: none;
      background: var(--primary); color: #fff; transition: background .2s;
    }
    .btn-save:hover { background: var(--primary-dk); }
    .btn-save:disabled { opacity: .6; cursor: not-allowed; }

    .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

    .toast {
      position: fixed; bottom: 24px; right: 24px;
      background: var(--text); color: #fff;
      padding: 12px 20px; border-radius: 8px;
      font-size: 14px; font-weight: 500;
      box-shadow: var(--shadow); z-index: 300;
      transform: translateY(80px); opacity: 0;
      transition: transform .3s, opacity .3s;
    }
    .toast.show { transform: translateY(0); opacity: 1; }
    .toast.success { background: var(--success); }
    .toast.error   { background: var(--error); }

    /* ══ HOME ══ */
    .welcome-banner {
      background: linear-gradient(135deg, var(--primary) 0%, #1e4d7a 100%);
      color: #fff; border-radius: var(--radius);
      padding: 28px 32px; margin-bottom: 28px;
    }
    .welcome-banner h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
    .welcome-banner p  { font-size: 14px; opacity: .8; }

    .modules-grid {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px;
    }
    .module-card {
      background: var(--surface); border: 1.5px solid var(--border);
      border-radius: var(--radius); padding: 24px 20px; text-align: center;
      cursor: pointer; transition: box-shadow .2s, transform .15s, border-color .2s;
    }
    .module-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--primary); }
    .module-card .icon { font-size: 36px; margin-bottom: 12px; }
    .module-card h3 { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
    .module-card p  { font-size: 12px; color: var(--muted); }
    .module-card.soon { opacity: .45; cursor: default; }
    .module-card.soon:hover { transform: none; box-shadow: none; border-color: var(--border); }

    /* ══ INVENTARIO TABS ══ */
    .inv-tab {
      padding: 8px 18px; border: 1px solid var(--border); background: var(--surface);
      border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
      color: var(--text); transition: all .2s;
    }
    .inv-tab:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
    .inv-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

    /* ══ REPORTES ══ */
    .report-controls {
      background: var(--surface); border: 1px solid var(--border);
      border-radius: var(--radius); padding: 20px 24px;
      margin-bottom: 24px;
      display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
    }
    .report-controls .form-group { margin-bottom: 0; min-width: 140px; }
    .report-controls .form-group label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; display: block; }
    .report-controls select, .report-controls input[type=number] {
      padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
      font-size: 14px; color: var(--text); background: #f8fafc;
      outline: none; font-family: inherit; width: 100%;
    }
    .report-controls select:focus, .report-controls input:focus {
      border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,58,92,.12);
    }
    .btn-buscar {
      padding: 10px 24px; background: var(--primary); color: #fff;
      border: none; border-radius: 8px; font-size: 14px; font-weight: 600;
      cursor: pointer; transition: background .2s; white-space: nowrap;
    }
    .btn-buscar:hover { background: var(--primary-dk); }
    .btn-buscar:disabled { opacity: .6; cursor: not-allowed; }

    .btn-export {
      padding: 10px 20px; background: #16a34a; color: #fff;
      border: none; border-radius: 8px; font-size: 14px; font-weight: 600;
      cursor: pointer; transition: background .2s; white-space: nowrap;
    }
    .btn-export:hover { background: #15803d; }

    .report-summary {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
      gap: 16px; margin-bottom: 24px;
    }
    .summary-card {
      background: var(--surface); border: 1px solid var(--border);
      border-radius: var(--radius); padding: 20px;
      text-align: center;
    }
    .summary-card .sc-num {
      font-size: 32px; font-weight: 800; color: var(--primary); line-height: 1;
    }
    .summary-card .sc-label {
      font-size: 12px; color: var(--muted); margin-top: 6px; font-weight: 500;
    }
    .summary-card.gold .sc-num { color: #b45309; }
    .summary-card.green .sc-num { color: #15803d; }

    .group-header {
      display: flex; align-items: center; gap: 10px;
      padding: 14px 16px;
      background: #f5f8fc; border-bottom: 1px solid var(--border);
    }
    .group-header h4 { font-size: 14px; font-weight: 700; color: var(--text); }
    .group-badge {
      display: inline-flex; align-items: center;
      padding: 3px 10px; border-radius: 20px;
      font-size: 11px; font-weight: 700;
    }
    .group-badge.parcial { background: #fef3c7; color: #92400e; }
    .group-badge.pleno   { background: #dcfce7; color: #166534; }

    .pts-bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 160px; }
    .pts-bar {
      flex: 1; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden;
    }
    .pts-bar-fill { height: 100%; border-radius: 3px; transition: width .4s; }
    .pts-bar-fill.parcial { background: #f59e0b; }
    .pts-bar-fill.pleno   { background: #22c55e; }
    .pts-num { font-size: 13px; font-weight: 700; white-space: nowrap; }
    .pts-num.parcial { color: #92400e; }
    .pts-num.pleno   { color: #166534; }

    /* ══ GANANCIAS REGS ══ */
    .badge-reg {
      display: inline-flex; align-items: center; gap: 4px;
      padding: 3px 10px; border-radius: 20px;
      font-size: 11px; font-weight: 700; white-space: nowrap;
    }
    .badge-reg.por-pagar  { background: #fef9c3; color: #854d0e; }
    .badge-reg.deposito   { background: #dcfce7; color: #166534; }
    .badge-reg.voucher    { background: #ede9fe; color: #5b21b6; }
    .badge-reg.retenida   { background: #fee2e2; color: #991b1b; }
    .badge-reg.desconocido{ background: #f1f5f9; color: #64748b; }

    .filter-tabs {
      display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
    }
    .filter-tab {
      padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
      cursor: pointer; border: 1.5px solid var(--border);
      background: var(--surface); color: var(--muted);
      transition: all .15s;
    }
    .filter-tab:hover { border-color: var(--primary); color: var(--primary); }
    .filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

    /* ══ DASHBOARD HOME ══ */
    .dash-header {
      margin-bottom: 28px;
    }
    .dash-header h2 {
      font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 4px;
    }
    .dash-header p { font-size: 14px; color: var(--muted); }

    .kpi-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 16px;
      margin-bottom: 28px;
    }
    .kpi-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 20px 22px;
      position: relative;
      overflow: hidden;
      transition: box-shadow .2s;
    }
    .kpi-card:hover { box-shadow: var(--shadow); }
    .kpi-card .kpi-icon {
      font-size: 28px;
      margin-bottom: 10px;
      display: block;
    }
    .kpi-card .kpi-label {
      font-size: 11px; font-weight: 700; color: var(--muted);
      text-transform: uppercase; letter-spacing: .6px;
      margin-bottom: 6px;
    }
    .kpi-card .kpi-value {
      font-size: 28px; font-weight: 800; color: var(--primary);
      line-height: 1; margin-bottom: 8px;
    }
    .kpi-card .kpi-compare {
      font-size: 12px; font-weight: 600;
      display: flex; align-items: center; gap: 4px;
    }
    .kpi-card .kpi-compare.up   { color: #15803d; }
    .kpi-card .kpi-compare.down { color: #b91c1c; }
    .kpi-card .kpi-compare.neutral { color: var(--muted); }
    .kpi-card.accent-gold .kpi-value { color: #b45309; }
    .kpi-card.accent-green .kpi-value { color: #15803d; }
    .kpi-card.accent-purple .kpi-value { color: #6d28d9; }
    .kpi-card.accent-red .kpi-value { color: #b91c1c; }
    .kpi-card .kpi-bar-wrap {
      margin-top: 10px;
      height: 4px; background: #e5e7eb; border-radius: 2px; overflow: hidden;
    }
    .kpi-card .kpi-bar-fill {
      height: 100%; border-radius: 2px;
      background: var(--primary);
      transition: width .6s ease;
    }

    .charts-grid {
      display: grid;
      grid-template-columns: 2fr 1fr;
      gap: 20px;
      margin-bottom: 28px;
    }
    .chart-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 20px 22px;
    }
    .chart-card h3 {
      font-size: 14px; font-weight: 700; color: var(--text);
      margin-bottom: 4px;
    }
    .chart-card .chart-sub {
      font-size: 12px; color: var(--muted); margin-bottom: 16px;
    }
    .chart-container { position: relative; }

    .regalias-row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 20px;
      margin-bottom: 28px;
    }
    .reg-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 20px 22px;
    }
    .reg-card h3 { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
    .reg-stat {
      display: flex; align-items: center; justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid #f0f4f8;
    }
    .reg-stat:last-child { border-bottom: none; }
    .reg-stat .rs-label { font-size: 13px; color: var(--muted); }
    .reg-stat .rs-value { font-size: 16px; font-weight: 700; }
    .reg-stat .rs-value.green  { color: #15803d; }
    .reg-stat .rs-value.orange { color: #b45309; }
    .reg-stat .rs-value.blue   { color: var(--primary); }

    .dash-loading {
      display: flex; align-items: center; justify-content: center;
      gap: 10px; padding: 60px 0;
      color: var(--muted); font-size: 14px;
    }
    .dash-loading .spinner { border-color: rgba(26,58,92,.2); border-top-color: var(--primary); }

    @media (max-width: 900px) {
      .charts-grid { grid-template-columns: 1fr; }
      .regalias-row { grid-template-columns: 1fr; }
    }

    /* ══ HAMBURGUESA / DRAWER MÓVIL ══ */
    .btn-hamburger {
      display: none;
      background: none; border: none; cursor: pointer;
      color: #fff; font-size: 22px; padding: 6px 8px;
      line-height: 1; margin-right: 4px;
    }

    /* Overlay oscuro detrás del drawer */
    .sidebar-overlay {
      display: none;
      position: fixed; inset: 0;
      background: rgba(0,0,0,.45);
      z-index: 150;
    }
    .sidebar-overlay.open { display: block; }

    /* Responsive */

    @media (max-width: 768px) {
      .login-card { padding: 36px 24px; }

      /* Ocultar sidebar por defecto en móvil */
      .sidebar {
        position: fixed;
        top: 60px; left: 0;
        height: calc(100vh - 60px);
        width: 260px;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        box-shadow: 4px 0 20px rgba(0,0,0,.18);
        overflow-y: auto;
        min-height: unset;
      }
      .sidebar.open { transform: translateX(0); }

      /* Mostrar botón hamburguesa */
      .btn-hamburger { display: flex; align-items: center; }

      .main-content { padding: 20px 16px; }
      .welcome-banner { padding: 20px; }
      .topbar-user span { display: none; }
      .form-row { grid-template-columns: 1fr; }
      th:nth-child(3), td:nth-child(3),
      th:nth-child(4), td:nth-child(4) { display: none; }
    }

    /* ══════════════════════════════════════════════ */
    /*  TEMA CENTRO DE DISTRIBUCIÓN                  */
    /* ══════════════════════════════════════════════ */
    body.role-centro {
      --primary:    #0d5f4a;
      --primary-dk: #083d30;
      --accent:     #2196f3;
      --bg:         #f0f7f5;
      --border:     #b8d8cf;
    }

    body.role-centro .sidebar {
      background: linear-gradient(180deg, #0d5f4a 0%, #083d30 100%);
    }

    body.role-centro .topbar {
      background: linear-gradient(135deg, #0d5f4a, #0a4f3e);
    }

    body.role-centro .login-card {
      border-top: 4px solid #0d5f4a;
    }

    body.role-centro .user-avatar {
      background: #2196f3;
    }

    body.role-centro .sidebar-item.active,
    body.role-centro .sidebar-item:hover {
      background: rgba(255,255,255,.15);
    }

    /* Badge indicador de rol centro */
    .role-badge-centro {
      display: inline-block;
      background: #2196f3;
      color: #fff;
      font-size: 10px;
      font-weight: 700;
      padding: 2px 8px;
      border-radius: 10px;
      margin-left: 8px;
      letter-spacing: .5px;
      text-transform: uppercase;
    }
