/* =========================================================
   Cuentas360 · Panel — estilos base
   Tema claro/oscuro vía [data-theme] en <html>, con fallback a
   prefers-color-scheme cuando el usuario no eligió nada aún.
   ========================================================= */

:root {
    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-contrast: #ffffff;

    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --info: #0284c7;
    --info-bg: #e0f2fe;
    --neutral: #6b7280;
    --neutral-bg: #f1f5f9;

    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-alt: #f1f2f6;
    --border: #e4e6ec;
    --text: #1c1e26;
    --text-muted: #6b7280;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14151c;
        --surface: #1c1e28;
        --surface-alt: #23252f;
        --border: #2d2f3b;
        --text: #eceef4;
        --text-muted: #9aa0ae;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .25);

        --success-bg: rgba(22, 163, 74, .18);
        --warning-bg: rgba(217, 119, 6, .18);
        --danger-bg: rgba(220, 38, 38, .18);
        --info-bg: rgba(2, 132, 199, .18);
        --neutral-bg: rgba(107, 114, 128, .22);
    }
}

:root[data-theme="dark"] {
    --bg: #14151c;
    --surface: #1c1e28;
    --surface-alt: #23252f;
    --border: #2d2f3b;
    --text: #eceef4;
    --text-muted: #9aa0ae;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .25);

    --success-bg: rgba(22, 163, 74, .18);
    --warning-bg: rgba(217, 119, 6, .18);
    --danger-bg: rgba(220, 38, 38, .18);
    --info-bg: rgba(2, 132, 199, .18);
    --neutral-bg: rgba(107, 114, 128, .22);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 4px; line-height: 1.25; }
p { margin: 0 0 12px; color: var(--text-muted); }
img { max-width: 100%; }

/* ---------- Layout genérico ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }
.narrow { max-width: 480px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 236px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
    padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar-brand { padding: 4px 12px 20px; font-weight: 700; font-size: 17px; }
.sidebar-brand span { color: var(--brand); }
.sidebar a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
    color: var(--text); font-weight: 500; font-size: 14px;
}
.sidebar a:hover { background: var(--surface-alt); text-decoration: none; }
.sidebar a.active { background: var(--brand); color: var(--brand-contrast); }
.sidebar-footer { margin-top: auto; padding: 12px; font-size: 12px; color: var(--text-muted); }

.mobile-nav-toggle { display: none; }

@media (max-width: 860px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; transform: translateX(-100%);
        transition: transform .2s ease; z-index: 40; box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-nav-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
        background: var(--surface); cursor: pointer; color: var(--text);
    }
    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30;
    }
    .sidebar-backdrop.open { display: block; }
}

/* ---------- Tema toggle ---------- */
.theme-toggle {
    display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
    background: var(--surface-alt); color: var(--text); border-radius: 999px; padding: 6px 12px;
    cursor: pointer; font-size: 13px; font-weight: 500;
}
.theme-toggle:hover { border-color: var(--brand); }

/* ---------- Tarjetas ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- KPI ---------- */
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 14px;
    border: 1px solid transparent; cursor: pointer; line-height: 1;
}
.btn-primary { background: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: var(--brand-hover); text-decoration: none; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=tel], select, textarea {
    width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: var(--surface-alt); }
td.wrap { white-space: normal; }

/* ---------- Barra de progreso ---------- */
.progress-wrap { min-width: 140px; }
.progress-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.progress-track { height: 8px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; }
.progress-success { background: var(--success); }
.progress-warning { background: var(--warning); }
.progress-danger { background: var(--danger); }
.progress-count { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Alertas / flash ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }

/* ---------- Página pública (auth, planes) ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 460px; }
.auth-logo { text-align: center; margin-bottom: 20px; font-weight: 700; font-size: 20px; }
.auth-logo span { color: var(--brand); }
.auth-footer-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }

.plans-header { text-align: center; max-width: 640px; margin: 0 auto 32px; }
.plan-card { display: flex; flex-direction: column; text-align: center; position: relative; }
.plan-card.featured { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.plan-price { font-size: 30px; font-weight: 700; margin: 12px 0 4px; }
.plan-price small { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.plan-features { list-style: none; padding: 0; margin: 16px 0; text-align: left; font-size: 13.5px; }
.plan-features li { padding: 6px 0; display: flex; gap: 8px; align-items: center; }
.plan-features li.inactive { color: var(--text-muted); text-decoration: line-through; }
.credit-packs { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.credit-pack { flex: 1; min-width: 160px; text-align: center; }

/* ---------- Utilidades ---------- */
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- Modal de confirmación ---------- */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
    align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 420px; width: 100%; box-shadow: var(--shadow); }
