@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&display=swap');

:root {
    /* Paleta oficial MERA */
    --mera-green: #024D25;
    --mera-green-mid: #1B6A3B;
    --secondary-green: #55882B;
    --accent-green: #93C01F;
    --mera-blue: #81CFF4;
    --aqua: #8CBCC4;
    --mera-blue-dark: #3E9BD1;

    --fondo-card: #ffffff;
    --texto: #21332A;
    --texto-suave: #6B7A68;
    /* Colores de estado sobre fondo claro */
    --error: #B3392F;
    --error-bg: #FDEEED;
    --error-border: #F2B8B2;
    --ok: #55882B;
    --info: #2C7BB0;
}

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

body {
    font-family: 'Montserrat', sans-serif;
    background: #eef1e9;
    color: var(--texto);
    min-height: 100vh;
}

/* Layout base: dos columnas en desktop */
.container {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    min-height: 100vh;
    width: 100%;
}

/* ===== Panel visual (marca) ===== */
.visual-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 56px 64px;
    position: relative;
    overflow: hidden;
    /* MERA GRADIENT */
    background:
        radial-gradient(1150px 500px at 88% -5%, rgba(129, 207, 244, 0.32), transparent 55%),
        radial-gradient(900px 520px at 0% 108%, rgba(147, 192, 31, 0.22), transparent 55%),
        linear-gradient(168deg, var(--mera-green) 0%, var(--mera-green-mid) 48%, var(--secondary-green) 100%);
}

.visual-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.brand-mark {
    color: #fff;
    line-height: 0.74;
}

.brand-mark span {
    display: block;
    font-size: clamp(40px, 4.2vw, 64px);
    font-weight: 800;
    letter-spacing: -0.08em;
}

.brand-mark small {
    display: block;
    margin-left: 8px;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: rgba(255, 255, 255, 0.8);
}

.visual-lema {
    color: rgba(255, 255, 255, 0.92);
    font-size: 18px;
    line-height: 1.55;
    margin-top: 36px;
    max-width: 400px;
}

.visual-footer {
    position: absolute;
    bottom: 28px;
    left: 64px;
    right: 64px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
}

/* ===== Panel de formulario (acceso) ===== */
.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 32px;
    background: #f4f7f1;
}

.auth-card {
    width: 100%;
    max-width: 470px;
    min-width: 0;
    background: var(--fondo-card);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(2, 77, 37, 0.12);
    padding: 40px 38px;
}

h1 {
    font-size: clamp(22px, 2.2vw, 28px);
    line-height: 1.25;
    font-weight: 800;
    color: var(--texto);
    margin-bottom: 8px;
}

.subtitle {
    font-size: 13px;
    color: var(--texto-suave);
    margin-bottom: 24px;
}

.step {
    display: none;
}

.step.active {
    display: block;
}

label {
    display: block;
    font-size: 13px;
    color: var(--texto-suave);
    margin: 0 0 7px;
}

input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d7ded4;
    border-radius: 10px;
    background: #fff;
    color: var(--texto);
    font: inherit;
    font-size: 14px;
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
    margin-bottom: 16px;
}

input:focus {
    border-color: var(--mera-blue);
    box-shadow: 0 0 0 3px rgba(129, 207, 244, 0.35);
}

input:read-only {
    background: #eef2ec;
    color: #5c6a5e;
    cursor: not-allowed;
    box-shadow: none;
}

input::placeholder {
    color: #9aa89b;
}

#nombre {
    text-transform: uppercase;
}

#nombre::placeholder {
    text-transform: none;
}

button {
    width: 100%;
    padding: 12px 18px;
    border: none;
    border-radius: 24px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--mera-blue);
    color: var(--mera-green);
}

.btn-primary:hover {
    background: #a6e3f9;
}

.btn-primary:disabled {
    background: #dfe5db;
    color: #9aa89b;
    cursor: not-allowed;
}

.btn-secondary {
    background: #eff4ec;
    color: #44604a;
}

.btn-secondary:hover {
    background: #e3ebe0;
}

.btn-secondary:disabled {
    background: #eff4ec;
    color: #b7c2b4;
    cursor: not-allowed;
}

.btn-secondary:disabled:hover {
    background: #eff4ec;
}

.message {
    padding: 12px;
    border-radius: 10px;
    margin-top: 16px;
    font-size: 14px;
    border: 1px solid transparent;
    display: none;
}

.message.success {
    display: block;
    background: #eff7e3;
    border-color: #c8dc9a;
    color: #3f6520;
}

.message.error {
    display: block;
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error);
}

.message.info {
    display: block;
    background: #eef7fd;
    border-color: #b9dcf3;
    color: var(--info);
}

.message.warning {
    display: block;
    background: #fdf6e3;
    border-color: #f0d68a;
    color: #8a6d1a;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #9aa89b;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.countdown {
    text-align: center;
    font-size: 32px;
    font-weight: 700;
    color: var(--secondary-green);
    margin: 20px 0;
}

.countdown.expired {
    color: var(--error);
}

.countdown.bloqueo {
    color: var(--error);
    font-size: 40px;
    letter-spacing: 2px;
}

/* ===== Vista de seguimiento de grupos ===== */
.group-header {
    text-align: center;
    margin-bottom: 10px;
}
.group-header h2 {
    color: var(--mera-green-mid);
    font-size: 18px;
    margin-bottom: 4px;
    word-break: break-word;
}
.group-header p {
    color: var(--texto-suave);
    font-size: 12px;
}
.group-summary {
    display: flex;
    gap: 10px;
    margin: 16px 0;
}
.group-summary .stat {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
    border-radius: 10px;
    background: #f4f8f2;
}
.group-summary .stat .num {
    font-size: 24px;
    font-weight: 700;
    color: var(--texto);
}
.group-summary .stat .lbl {
    font-size: 11px;
    color: var(--texto-suave);
}
.group-summary .stat.usados .num { color: var(--secondary-green); }
.group-summary .stat.pendientes .num { color: var(--mera-blue-dark); }

.group-list {
    list-style: none;
    margin-top: 6px;
}
.group-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-radius: 10px;
    background: #f4f8f2;
    margin-bottom: 8px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}
.group-item .g-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 180px;
}
.group-item .g-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.group-item.pendiente .g-icon { background: var(--mera-blue); color: var(--mera-green); }
.group-item.usado .g-icon { background: var(--accent-green); color: var(--mera-green); }
.group-item.sinenlace .g-icon { background: #e3e9e0; color: #8a9790; }
.group-item.expirado .g-icon { background: #e74c3c; color: #fff; }
.group-item .g-nombre {
    font-size: 14px;
    font-weight: 600;
    color: var(--texto);
    min-width: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.group-item .g-tag {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 12px;
    flex-shrink: 0;
}
.group-item .g-acciones {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    margin-left: auto;
    flex-wrap: wrap;
    max-width: 100%;
}
.group-item.pendiente .g-tag { background: rgba(62, 155, 209, 0.12); color: var(--mera-blue-dark); }
.group-item.usado .g-tag { background: rgba(147, 192, 31, 0.15); color: #4f7a20; }
.group-item.sinenlace .g-tag { background: #e6ebe3; color: #8a9790; }
.group-item.expirado .g-tag { background: rgba(231, 76, 60, 0.15); color: #c0392b; }
.group-item .g-btn {
    width: auto;
    max-width: 100%;
    margin-top: 0;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    background: var(--accent-green);
    color: var(--mera-green);
    padding: 5px 12px;
    border-radius: 12px;
    flex-shrink: 0;
    cursor: pointer;
    white-space: nowrap;
}
.group-item .g-btn:hover { background: var(--secondary-green); color: #fff; }

@media (max-width: 380px) {
    .group-item .g-info {
        flex-basis: 100%;
    }

    .group-item .g-acciones {
        width: 100%;
        justify-content: flex-end;
    }
}
.group-item .g-btn-resend {
    background: var(--mera-blue);
    color: var(--mera-green);
    border: none;
    font-family: inherit;
    white-space: nowrap;
}
.group-item .g-btn-resend:hover { background: #a6e3f9; }
.group-item .g-btn-resend:disabled { background: #e0e5db; color: #9aa89b; cursor: default; }
.group-item .g-tag-exp { background: rgba(231, 76, 60, 0.15); color: #c0392b; }
.group-item .g-tag-resend { background: rgba(62, 155, 209, 0.12); color: var(--mera-blue-dark); }

.group-progress {
    margin: 16px 0 4px;
}
.group-progress .bar {
    width: 100%;
    height: 8px;
    background: #dfe6db;
    border-radius: 6px;
    overflow: hidden;
    margin-top: 8px;
}
.group-progress .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--aqua), var(--mera-blue));
    border-radius: 6px;
    transition: width 0.4s ease;
    min-width: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .container {
        display: flex;
        flex-direction: column;
        position: relative;
        min-height: 100vh;
        background:
            radial-gradient(700px 280px at 100% 0%, rgba(129, 207, 244, 0.32), transparent 58%),
            radial-gradient(500px 260px at 0% 100%, rgba(147, 192, 31, 0.24), transparent 60%),
            linear-gradient(168deg, var(--mera-green) 0%, var(--mera-green-mid) 52%, var(--secondary-green) 100%);
    }

    .visual-panel {
        position: relative;
        display: flex;
        min-height: auto;
        flex: 0 0 auto;
        padding: 24px 24px 16px;
        justify-content: flex-start;
        background: transparent;
        z-index: 0;
    }

    .visual-content {
        width: 100%;
        max-width: 470px;
        margin: 0 auto;
        gap: 16px;
    }

    .brand-mark span {
        font-size: clamp(42px, 13vw, 58px);
    }

    .visual-lema {
        font-size: 15px;
        margin-top: 0;
        max-width: 320px;
    }

    .visual-footer {
        display: block;
        position: static;
        margin: 16px auto 0;
        width: 100%;
        max-width: 470px;
    }

    .auth-panel {
        min-height: auto;
        flex: 0 0 auto;
        padding: 24px 20px 40px;
        background: transparent;
        position: relative;
        z-index: 1;
        margin-top: 0;
    }

    .auth-card {
        padding: 32px 26px;
    }
}

@media (max-width: 380px) {
    .auth-card {
        padding: 26px 18px;
    }

    .group-item .g-info {
        flex-basis: 100%;
    }

    .group-item .g-acciones {
        width: 100%;
        justify-content: flex-end;
    }

    .auth-panel {
        padding: 24px 12px 40px;
    }

    .auth-card {
        padding: 24px 16px;
        border-radius: 12px;
    }

    .group-summary {
        gap: 6px;
    }

    .group-summary .stat {
        padding: 10px 4px;
    }

    .group-summary .stat .num {
        font-size: 21px;
    }

    .group-item {
        padding: 10px;
    }

    #codigo {
        font-size: 24px !important;
        letter-spacing: 5px !important;
    }
}