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

:root {
    --primary:      #1a56db;
    --primary-dk:   #1240a8;
    --sidebar-bg:   #0f172a;
    --sidebar-w:    220px;
    --sidebar-wc:   54px;   /* collapsed width */
    --surface:      #f8fafc;
    --border:       #e2e8f0;
    --text:         #1e293b;
    --muted:        #64748b;
    --danger:       #dc2626;
    --success:      #16a34a;
    --radius:       6px;
    --shadow:       0 1px 3px rgba(0,0,0,.10);
    --tabbar-h:     36px;
    --trans:        .22s ease;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
}

/* ════════════════════════════════════════
   SHELL — contenedor principal
════════════════════════════════════════ */
.shell-body {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: row;
}

/* ── Sidebar ── */
.shell-sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,.07);
    transition: width var(--trans);
    overflow: hidden;
}
.shell-body.collapsed .shell-sidebar {
    width: var(--sidebar-wc);
}

/* encabezado del sidebar */
.sidebar-head {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .85rem .75rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}
.sidebar-logo {
    width: 28px; height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    display: grid; place-items: center;
    font-weight: 800; font-size: .78rem;
    flex-shrink: 0;
}
.sidebar-name {
    color: #fff;
    font-weight: 700;
    font-size: .9rem;
    white-space: nowrap;
}
.sidebar-collapser {
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    padding: .2rem;
    border-radius: var(--radius);
    display: grid; place-items: center;
    flex-shrink: 0;
    transition: color .15s, transform var(--trans);
}
.sidebar-collapser svg { width: 16px; height: 16px; }
.sidebar-collapser:hover { color: #94a3b8; }
.shell-body.collapsed .sidebar-collapser { transform: rotate(180deg); }

/* nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .4rem 0;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

/* ítem directo */
.snav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .75rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: .875rem;
    cursor: pointer;
    border-left: 2px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    transition: background .12s, color .12s, border-color .12s;
}
.snav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.snav-item.active {
    background: rgba(26,86,219,.2);
    color: #93c5fd;
    border-left-color: var(--primary);
}

/* grupo acordeón */
.snav-group-btn {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .75rem;
    width: 100%;
    background: none;
    border: none;
    border-left: 2px solid transparent;
    color: #94a3b8;
    font-size: .875rem;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    transition: background .12s, color .12s;
}
.snav-group-btn:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }

.snav-icon {
    width: 17px; height: 17px;
    flex-shrink: 0;
    opacity: .65;
    transition: opacity .15s;
}
.snav-item:hover .snav-icon,
.snav-item.active .snav-icon,
.snav-group-btn:hover .snav-icon,
.snav-group.open .snav-group-btn .snav-icon { opacity: 1; }

.snav-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--trans), max-width var(--trans);
}
.snav-caret {
    width: 14px; height: 14px;
    flex-shrink: 0;
    opacity: .5;
    transition: transform .2s, opacity var(--trans);
}
.snav-group.open .snav-caret { transform: rotate(180deg); }

/* sub-ítems */
.snav-group-items {
    display: none;
    flex-direction: column;
    background: rgba(0,0,0,.18);
}
.snav-group.open .snav-group-items { display: flex; }

.snav-subitem {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .42rem .75rem .42rem 2.4rem;
    color: #64748b;
    text-decoration: none;
    font-size: .845rem;
    cursor: pointer;
    border-left: 2px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    transition: background .12s, color .12s;
}
.snav-subitem svg { width: 14px; height: 14px; flex-shrink: 0; opacity: .55; }
.snav-subitem:hover { background: rgba(255,255,255,.05); color: #94a3b8; }
.snav-subitem.active { color: #93c5fd; border-left-color: var(--primary); }
.snav-subitem.snav-disabled { opacity: .42; cursor: not-allowed; pointer-events: none; }

/* sidebar colapsado: ocultar textos y sub-ítems */
.shell-body.collapsed .snav-text,
.shell-body.collapsed .snav-caret { opacity: 0; max-width: 0; pointer-events: none; }
.shell-body.collapsed .snav-group-items { display: none !important; }
.shell-body.collapsed .snav-subitem { padding-left: .75rem; }

/* pie del sidebar */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .7rem .75rem;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-username {
    flex: 1;
    color: #64748b;
    font-size: .8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-logout {
    display: grid; place-items: center;
    color: #475569;
    text-decoration: none;
    padding: .2rem;
    border-radius: var(--radius);
    flex-shrink: 0;
    transition: color .15s;
}
.sidebar-logout svg { width: 16px; height: 16px; }
.sidebar-logout:hover { color: #f87171; background: none; }

/* ── Área principal derecha ── */
.shell-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    min-width: 0;
}

/* ── Barra de pestañas ── */
.shell-tabbar {
    height: var(--tabbar-h);
    background: #1e293b;
    display: flex;
    align-items: flex-end;
    gap: 1px;
    padding: 0 .5rem;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.shell-tabbar::-webkit-scrollbar { display: none; }

.tab {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: 0 .85rem;
    height: 30px;
    background: #2d3f55;
    color: #94a3b8;
    font-size: .82rem;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    flex-shrink: 0;
    transition: background .12s, color .12s;
    max-width: 180px;
}
.tab-icon { font-size: .95rem; line-height: 1; flex-shrink: 0; }
.tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { background: #3b5068; color: #cbd5e1; }
.tab.active { background: var(--surface); color: var(--text); font-weight: 600; }

.tab-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: .9rem;
    line-height: 1;
    padding: 0 .1rem;
    flex-shrink: 0;
    opacity: .55;
    transition: opacity .12s;
}
.tab-close:hover { opacity: 1; }

/* ── Iframes ── */
.shell-frames {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--surface);
}
.shell-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: none;
}
.shell-frame.active { display: block; }

/* ════════════════════════════════════════
   EMBED — páginas dentro de iframes
════════════════════════════════════════ */
.embed-wrap {
    padding: 1.5rem;
    min-height: 100%;
    background: var(--surface);
}

/* ════════════════════════════════════════
   LOGIN
════════════════════════════════════════ */
.content-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
}
.login-wrapper {
    background: #fff;
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-wrapper h2 { margin-bottom: .35rem; font-size: 1.4rem; }
.login-wrapper p.subtitle { color: var(--muted); font-size: .875rem; margin-bottom: 1.75rem; }

/* ════════════════════════════════════════
   COMPONENTES
════════════════════════════════════════ */

/* Formularios */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block; font-size: .82rem; font-weight: 600;
    margin-bottom: .35rem; color: var(--muted);
    text-transform: uppercase; letter-spacing: .3px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: .55rem .75rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .95rem; color: var(--text); background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* Botones */
button, .btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .6rem 1.25rem; background: var(--primary);
    color: #fff; border: none; border-radius: var(--radius);
    font-size: .9rem; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: background .15s; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--primary-dk); }
.btn-secondary { background: var(--muted); }
.btn-secondary:hover { background: #475569; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

/* Alertas */
.alert-error {
    background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
    padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem;
}
.alert-success {
    background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--success);
    padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-size: .9rem;
}

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.25rem; margin-top: 1rem; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.card h3 { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: .75rem; }
.card-value { font-size: 1.75rem; font-weight: 700; }

/* Tablas */
.table-wrapper { overflow-x: auto; margin-top: .5rem; }
table { width: 100%; border-collapse: collapse; background: #fff; box-shadow: var(--shadow); border-radius: var(--radius); overflow: hidden; }
thead { background: #1e293b; color: #fff; }
thead th { padding: .75rem 1rem; text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: .7rem 1rem; font-size: .9rem; }
tbody tr:hover { background: #f8fafc; }

/* Form card */
.form-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; max-width: 720px; box-shadow: var(--shadow); }

/* Encabezado de página */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: .75rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; }

/* Badges */
.badge { display: inline-block; padding: .2rem .65rem; border-radius: 99px; font-size: .75rem; font-weight: 600; letter-spacing: .2px; }
.badge-ok     { background: #dcfce7; color: #15803d; }
.badge-off    { background: #f1f5f9; color: #64748b; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #ffedd5; color: #c2410c; }

/* Divisor */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ════════════════════════════════════════
   INGRESOS / EGRESOS
════════════════════════════════════════ */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.filter-chip { padding: .3rem .85rem; border-radius: 99px; font-size: .82rem; font-weight: 600; text-decoration: none; background: #f1f5f9; color: var(--muted); transition: background .15s, color .15s; }
.filter-chip:hover { background: var(--border); }
.filter-chip.active { background: var(--primary); color: #fff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.calc-preview { display: flex; gap: 2rem; background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.calc-row { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }
.calc-row strong { font-size: 1.1rem; color: var(--text); }
.wallet-value { color: var(--success) !important; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.detail-card h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 1rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
dl { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; align-items: baseline; }
dt { font-size: .82rem; color: var(--muted); font-weight: 600; }
dd { font-size: .9rem; }
.num-lg { font-size: 1.4rem; font-weight: 700; }
.num-md { font-size: 1.1rem; font-weight: 600; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted   { color: var(--muted); font-size: .85rem; }
.docs-row { display: flex; gap: 2rem; flex-wrap: wrap; }
.doc-item { display: flex; flex-direction: column; gap: .5rem; }
.doc-label { font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.action-bar { display: flex; gap: 1rem; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.wallet-banner { margin-top: .5rem; padding: .6rem 1rem; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: var(--radius); font-size: .9rem; color: #15803d; }
.hint { display: block; font-size: .8rem; margin-top: .3rem; }
.hint-error { color: var(--danger); }
.hint-ok    { color: var(--success); }

/* ════════════════════════════════════════
   DASHBOARD
════════════════════════════════════════ */
.dash-welcome { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: .5rem; font-size: 1rem; color: var(--text); }
.dash-date { font-size: .85rem; color: var(--muted); }
.alerts-block { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.5rem; }
.dash-alert { padding: .65rem 1rem; border-radius: var(--radius); font-size: .875rem; display: flex; align-items: center; gap: .6rem; }
.dash-alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.dash-alert-danger  { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.dash-grid { display: grid; gap: 1.25rem; }
.dash-grid-4 { grid-template-columns: repeat(4, 1fr); }
.dash-grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .dash-grid-4 { grid-template-columns: repeat(2, 1fr); } .dash-grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .dash-grid-4, .dash-grid-3 { grid-template-columns: 1fr; } }
.stat-card { border-radius: var(--radius); padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .3rem; box-shadow: var(--shadow); border: 1px solid transparent; }
.stat-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; opacity: .75; }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat-sub   { font-size: .78rem; opacity: .7; }
.stat-sub a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.stat-blue    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.stat-green   { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.stat-orange  { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.stat-neutral { background: #fff; color: var(--text); border-color: var(--border); }
.dash-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.dash-section-header h2 { font-size: 1rem; font-weight: 700; }

/* ════════════════════════════════════════
   SORT TABLE
════════════════════════════════════════ */
.th-sort { cursor:pointer; user-select:none; white-space:nowrap; }
.th-sort::after { content:' ↕'; opacity:.3; font-size:.72em; }
.th-asc::after  { content:' ↑'; opacity:1; color:var(--primary); }
.th-desc::after { content:' ↓'; opacity:1; color:var(--primary); }
.th-sort:hover  { background:rgba(0,0,0,.03); }
.table-count    { font-size:.8rem; color:var(--muted); margin-bottom:.4rem; text-align:right; }
