:root {
    color-scheme: light dark;
    --bg: #f4f7fb;
    --surface: rgba(255, 255, 255, 0.84);
    --surface-strong: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: rgba(148, 163, 184, 0.22);
    --shadow: 0 22px 50px rgba(15, 23, 42, 0.08);
    --primary: #111827;
    --secondary: #2563eb;
    --accent: #f59e0b;
    --radius: 22px;
}

html[data-theme='dark'] {
    --bg: #08111f;
    --surface: rgba(15, 23, 42, 0.78);
    --surface-strong: #0f172a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.14);
    --shadow: 0 22px 50px rgba(0, 0, 0, 0.35);
}

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.14), transparent 28%),
        radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.12), transparent 24%),
        var(--bg);
    color: var(--text);
    font-family: 'Avenir Next', 'Helvetica Neue', sans-serif;
}

a { color: inherit; text-decoration: none; }

.app-frame {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.62));
    border-right: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

html[data-theme='dark'] .sidebar {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.86), rgba(15, 23, 42, 0.72));
}

.brand-block {
    display: flex;
    gap: 14px;
    align-items: center;
}

.brand-block.compact { margin-bottom: 24px; }

.brand-mark {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    display: grid;
    place-items: center;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.brand-mark img { width: 100%; height: 100%; object-fit: cover; }

.brand-block h1, .topbar h2, .hero-card h3, .panel h3, .panel h4, .auth-card h2 { margin: 0; }

.brand-block p, .muted, .eyebrow { margin: 0; color: var(--muted); }

.side-nav { display: grid; gap: 8px; }

.side-nav a {
    padding: 14px 16px;
    border-radius: 16px;
    background: transparent;
    color: var(--text);
    border: 1px solid transparent;
    transition: 0.2s ease;
}

.side-nav a:hover { background: rgba(37, 99, 235, 0.09); border-color: rgba(37, 99, 235, 0.18); }

.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }

.theme-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
    border-radius: 18px;
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid var(--border);
}

.theme-option {
    height: 44px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
}

.theme-option.is-active {
    background: var(--surface-strong);
    color: var(--text);
    box-shadow: var(--shadow);
}

.content {
    padding: 24px;
    display: grid;
    gap: 20px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.hero-card, .panel, .auth-card, .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.hero-card, .panel, .auth-card { border-radius: var(--radius); }

.hero-card {
    padding: 28px;
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
}

.compact-hero { justify-content: flex-start; }

.hero-metrics { display: grid; grid-auto-flow: column; gap: 14px; }
.hero-metrics div { min-width: 110px; padding: 14px 16px; border-radius: 18px; background: rgba(37, 99, 235, 0.1); }
.hero-metrics strong { display: block; font-size: 1.3rem; }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }

.stat-card {
    padding: 18px;
    border-radius: 20px;
    display: grid;
    gap: 8px;
}

.stat-card strong { font-size: 1.8rem; }
.stat-card-accent { background: linear-gradient(135deg, rgba(37, 99, 235, 0.16), rgba(245, 158, 11, 0.12)); }

.content-grid { display: grid; gap: 20px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.panel { padding: 22px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.9rem; }

.table-like { display: grid; gap: 10px; }
.table-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 8px; font-weight: 600; }
input, select, textarea {
    width: 100%;
    box-sizing: border-box;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    padding: 12px 14px;
    font: inherit;
}

input[type='color'] { padding: 6px; min-height: 52px; }

.btn, .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 12px 16px;
    cursor: pointer;
    font: inherit;
    transition: 0.2s ease;
}

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border-color: transparent; }
.btn-secondary { background: rgba(37, 99, 235, 0.12); }
.btn-ghost, .icon-btn { background: transparent; color: var(--text); }
.btn:hover, .icon-btn:hover { transform: translateY(-1px); }

.chip {
    display: inline-flex;
    padding: 5px 10px;
    margin-right: 6px;
    margin-bottom: 6px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.12);
}

.alert {
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.55);
}

.alert-danger { background: rgba(239, 68, 68, 0.12); }
.alert-success { background: rgba(34, 197, 94, 0.12); }

.toast-stack {
    position: fixed;
    right: 20px;
    top: 20px;
    display: grid;
    gap: 10px;
    z-index: 60;
    width: min(92vw, 360px);
}

.toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.88));
    color: var(--text);
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-left-width: 6px;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.18);
    animation: toast-in 0.2s ease-out;
}

html[data-theme='dark'] .toast {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.9));
    border-color: rgba(148, 163, 184, 0.22);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.4);
}

.toast-success { border-left: 5px solid #22c55e; }
.toast-error, .toast-danger { border-left: 5px solid #ef4444; }
.toast-warning { border-left: 5px solid #f59e0b; }

.toast-icon {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    background: rgba(37, 99, 235, 0.12);
    font-weight: 700;
}

.toast.is-hiding { opacity: 0; transform: translateY(8px); transition: 0.18s ease; }

.toast-close {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.2rem;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 460px);
    padding: 28px;
}

.stack p { margin: 0; }

.sidebar-open .sidebar { transform: translateX(0); }

@media (max-width: 1024px) {
    .app-frame { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(86vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 30;
    }
    .content { padding: 18px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-cols { grid-template-columns: 1fr; }
    .hero-card { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .hero-metrics { grid-auto-flow: row; }
    .topbar { align-items: flex-start; }

    .toast-stack {
        left: 12px;
        right: 12px;
        top: 12px;
        width: auto;
    }

    .toast {
        padding: 14px 16px;
        border-radius: 18px;
    }

    .table-wrap {
        overflow: visible;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
        width: 100%;
    }

    thead {
        position: absolute;
        left: -9999px;
        top: -9999px;
    }

    tr {
        margin-bottom: 12px;
        padding: 12px 14px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: var(--surface);
        box-shadow: var(--shadow);
    }

    td {
        border: 0;
        padding: 8px 0;
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 600;
        flex: 0 0 44%;
    }

    td[data-label="Acciones"] {
        justify-content: flex-end;
    }

    td[data-label="Acciones"]::before {
        display: none;
    }

    .hero-card,
    .panel,
    .auth-card {
        padding: 18px;
    }

    .panel h3,
    .panel h4 {
        font-size: 1.05rem;
    }

    .sidebar-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}