:root {
    /* Material light palette */
    --bg: #eceff1;            /* blue grey 50/100 */
    --surface: #ffffff;
    --surface-2: #f5f7fa;
    --primary: #1976d2;       /* blue 700 */
    --primary-dark: #115293;
    --primary-light: #e3f2fd; /* blue 50 */
    --accent: #00897b;        /* teal 600 */
    --text: rgba(0, 0, 0, .87);
    --text-2: rgba(0, 0, 0, .6);
    --text-3: rgba(0, 0, 0, .38);
    --divider: rgba(0, 0, 0, .12);
    --error: #d32f2f;
    --error-bg: #fdecea;
    --ok: #2e7d32;
    --ok-bg: #edf7ed;
    --radius: 12px;
    --radius-sm: 8px;
    /* Material elevation shadows */
    --e1: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .06);
    --e2: 0 3px 6px rgba(0, 0, 0, .10), 0 2px 4px rgba(0, 0, 0, .08);
    --e4: 0 10px 20px rgba(0, 0, 0, .12), 0 3px 6px rgba(0, 0, 0, .08);
    --e8: 0 16px 32px rgba(0, 0, 0, .16), 0 6px 12px rgba(0, 0, 0, .10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

a { color: var(--primary); }

/* =========================================================
   BOTONES (Material)
   ========================================================= */
.btn,
button[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .6rem 1.1rem;
    min-height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 500;
    letter-spacing: .04em;
    text-transform: uppercase;
    font-size: .875rem;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: box-shadow .2s ease, background-color .2s ease;
}

.btn-primary,
.card button[type="submit"] {
    color: #fff;
    background: var(--primary);
    box-shadow: var(--e2);
}

.btn-primary:hover,
.card button[type="submit"]:hover {
    background: var(--primary-dark);
    box-shadow: var(--e4);
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    box-shadow: none;
    padding: .5rem .8rem;
}

.btn-ghost:hover { background: rgba(25, 118, 210, .08); }

/* =========================================================
   LOGIN / TARJETAS DE FORMULARIO
   ========================================================= */
body.auth {
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background:
        linear-gradient(180deg, #e3f2fd, #eceff1);
}

.card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: clamp(1.5rem, 4vw, 2.25rem);
    box-shadow: var(--e8);
}

.card h1 {
    margin: 0 0 .25rem;
    font-size: 1.5rem;
    font-weight: 500;
    text-align: center;
}

.subtitle {
    margin: 0 0 1.5rem;
    text-align: center;
    color: var(--text-2);
}

.brand-badge {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    display: grid;
    place-items: center;
    font-size: 1.6rem;
    border-radius: 50%;
    color: #fff;
    background: var(--primary);
    box-shadow: var(--e4);
}

label {
    display: block;
    margin: 1.2rem 0 .4rem;
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-2);
}

.hint { font-weight: 400; color: var(--text-3); font-size: .8rem; }

input {
    width: 100%;
    padding: .75rem .85rem;
    background: var(--surface-2);
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input::placeholder { color: var(--text-3); }

input:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, .15);
}

.card button[type="submit"] { width: 100%; margin-top: 1.6rem; }

/* Campo de contraseña con botón "ver" */
.pw-field { position: relative; }
.pw-field input { padding-right: 3rem; }

.pw-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 2.9rem;
    min-height: 0;
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    text-transform: none;
    letter-spacing: 0;
}

.pw-toggle:hover { background: rgba(0, 0, 0, .04); }

/* Alertas */
.alert {
    padding: .75rem .95rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    margin-bottom: 1rem;
    border-left: 4px solid transparent;
}

.alert.error { background: var(--error-bg); color: var(--error); border-left-color: var(--error); }
.alert.success { background: var(--ok-bg); color: var(--ok); border-left-color: var(--ok); }

/* =========================================================
   TOPBAR (Material app bar)
   ========================================================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding: .75rem clamp(1rem, 4vw, 2rem);
    background: var(--primary);
    color: #fff;
    box-shadow: var(--e4);
}

.brand { font-weight: 500; font-size: 1.15rem; letter-spacing: .01em; }

.topbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.topbar .btn-ghost { color: #fff; }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .16); }

.user {
    color: #fff;
    font-size: .85rem;
    padding: .35rem .7rem;
    background: rgba(255, 255, 255, .18);
    border-radius: 999px;
}

form.inline { margin: 0; display: inline; }

/* =========================================================
   CONTENIDO
   ========================================================= */
.content {
    max-width: 1240px;
    margin: 0 auto;
    padding: clamp(1.25rem, 4vw, 2rem);
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-head h1 { margin: 0; font-size: clamp(1.35rem, 4vw, 1.75rem); font-weight: 500; }
.muted { color: var(--text-2); margin: .25rem 0 0; }

.count-pill {
    align-self: center;
    padding: .45rem .9rem;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Estado vacío */
.empty {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--e1);
    color: var(--text-2);
}

.empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* =========================================================
   TABLA DE CLIENTES (Material data table)
   ========================================================= */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--e2);
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

table.data th,
table.data td {
    padding: .7rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--divider);
    vertical-align: middle;
}

table.data thead th {
    color: var(--text-2);
    font-weight: 500;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Fechas compactas, sin cortarse */
table.data td[data-label="Fecha de pago"],
table.data td[data-label="Próximo pago"],
table.data td[data-label="Creado"],
table.data td[data-label="Vence"] {
    white-space: nowrap;
}

table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: rgba(25, 118, 210, .04); }
table.data tbody tr:last-child td { border-bottom: none; }

/* Estado de pago: color de fila */
tr.estado-hoy td      { background: #e7f6e9; }
tr.estado-vencido td  { background: #fff6da; }
tr.estado-critico td  { background: #fdecec; }

tr.estado-hoy td:first-child     { box-shadow: inset 4px 0 0 var(--ok); }
tr.estado-vencido td:first-child { box-shadow: inset 4px 0 0 #f9a825; }
tr.estado-critico td:first-child { box-shadow: inset 4px 0 0 var(--error); }

tr.estado-hoy:hover td     { background: #ddf1e0; }
tr.estado-vencido:hover td { background: #fdefc7; }
tr.estado-critico:hover td { background: #fbe0e0; }

.strong { font-weight: 500; }
.dash { color: var(--text-3); }

/* Columna Cliente (nombre + celular + editar) */
.cli { display: flex; align-items: center; gap: .5rem; }
.cli-info { display: flex; flex-direction: column; line-height: 1.3; }
.cli-name { font-weight: 500; }
.cli-phone { font-size: .8rem; color: var(--text-2); white-space: nowrap; }

.edit-link {
    text-decoration: none;
    font-size: 1rem;
    padding: .2rem .35rem;
    border-radius: 6px;
    line-height: 1;
}
.edit-link:hover { background: rgba(0, 0, 0, .06); }

/* Checkbox "mantener sesión abierta" */
label.check {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 1.1rem 0 0;
    font-weight: 400;
    color: var(--text-2);
    cursor: pointer;
}
label.check input { width: auto; margin: 0; }

.url {
    display: inline-block;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.next-pay {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 6px;
    background: rgba(0, 137, 123, .12);
    color: var(--accent);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.token {
    display: inline-block;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    font-family: "Roboto Mono", ui-monospace, "Consolas", monospace;
    font-size: .82rem;
    padding: .2rem .45rem;
    background: var(--surface-2);
    border: 1px solid var(--divider);
    border-radius: 6px;
    color: var(--text-2);
}

.copy-token {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.copy-token:hover { border-color: var(--primary); color: var(--primary); }
.copy-token:active { transform: translateY(1px); }
.copy-token:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.copy-token.copied {
    background: var(--ok-bg);
    color: var(--ok);
    border-color: var(--ok);
}

.vence {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 6px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.vence.is-valid { background: var(--ok-bg); color: var(--ok); }
.vence.is-expired { background: var(--error-bg); color: var(--error); }

/* Badges de plan (chips Material) */
.badge {
    display: inline-block;
    padding: .3rem .65rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge.plan-2 { background: var(--primary-light); color: var(--primary-dark); }
.badge.plan-3 { background: #f3e5f5; color: #6a1b9a; }

/* =========================================================
   RESPONSIVE: tabla -> tarjetas en pantallas chicas
   ========================================================= */
@media (max-width: 720px) {
    .table-wrap { overflow: visible; background: transparent; box-shadow: none; }

    table.data thead { display: none; }

    table.data,
    table.data tbody,
    table.data tr,
    table.data td { display: block; width: 100%; }

    table.data tr {
        background: var(--surface);
        border-radius: var(--radius);
        padding: .35rem .25rem;
        margin-bottom: .9rem;
        box-shadow: var(--e2);
    }

    table.data td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: .65rem .9rem;
        border-bottom: 1px solid var(--divider);
        text-align: right;
    }

    table.data tr td:last-child { border-bottom: none; }

    table.data td::before {
        content: attr(data-label);
        color: var(--text-2);
        font-size: .75rem;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: .04em;
        text-align: left;
        flex: 0 0 auto;
    }

    .url,
    .token { max-width: 58vw; }
}

@media (max-width: 480px) {
    .topbar { justify-content: center; }
    .topbar-right { width: 100%; justify-content: center; }
    .brand { width: 100%; text-align: center; }
}
