:root {
    --blue-gradient: linear-gradient(180deg, #1d9bf0, #0c6cec);
    --card-bg: #fff;
    --border-soft: rgba(0, 0, 0, 0.1);
    --text-dark: #1e2a38;
    --accent: #1976d2;
    --success: #1ba54a;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    min-height: 100vh;
    background: var(--blue-gradient);
    color: var(--text-dark);
}

/* Center the layout for standalone pages like Registration */
.register-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
}

header {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    text-align: center;
    color: white;
}

header h1 {
    margin: 0.5rem 0;
    font-size: 1.8rem;
}

header p {
    margin: 0;
    font-weight: 600;
}

main {
    padding: 1rem;
    display: grid;
    gap: 1rem;
    max-width: 480px;
    margin: 0 auto;
    margin-bottom: calc(1rem + env(safe-area-inset-bottom));
}

@media (max-width: 400px) {
    .card { padding: 1.5rem; }
    .emergency-grid { gap: 1rem; }
    .emergency-button { font-size: 1.1rem; }
    .btn-hotline {
        width: 75px;
        height: 75px;
    }
}

.anchor-nav {
    display: flex;
    justify-content: space-around;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    font-weight: 600;
}

.anchor-nav a {
    color: white;
    text-decoration: none;
    font-size: 0.95rem;
}

.card {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 2.2rem;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.2);
    border: 1px solid var(--border-soft);
}

.card h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.3rem;
    color: var(--accent);
}

.card-section h2 {
    margin-top: 0;
    margin-bottom: 0.3rem;
    font-size: 1.7rem;
    color: var(--accent);
}

.section-subtitle {
    margin: 0 0 1rem;
    color: #6c7b98;
    font-size: 0.95rem;
}

.input-group {
    position: relative;
    margin-bottom: 1rem;
}

.input-group span {
    position: absolute;
    top: 50%;
    left: 0.65rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    color: #65748b;
}

.input-group input {
    width: 100%;
    padding: 0.85rem 0.85rem 0.85rem 2.6rem;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    font-size: 1rem;
}

.input-group.invalid input {
    border-color: #d32f2f;
    box-shadow: 0 0 0 2px rgba(211, 47, 47, 0.2);
}

.input-group input.has-toggle {
    padding-right: 3.2rem;
}

.input-group .toggle-password {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #65748b;
    font-size: 1rem;
    cursor: pointer;
    padding: 5%;
}

.input-group .toggle-password.is-visible span {
    color: var(--accent);
}

.input-wrapper {
    margin-bottom: 1rem;
}

.input-wrapper label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5f86;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.helper-text {
    font-size: 0.75rem;
    color: #0f76d8;
    margin-top: 0.35rem;
    display: block;
}

.validation-text {
    display: block;
    font-size: 0.75rem;
    color: #d32f2f;
    min-height: 1rem;
    margin-top: 0.35rem;
}

.validation-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(13, 110, 253, 0.95);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.3);
    font-size: 0.95rem;
    opacity: 0;
    transition: transform 240ms ease, opacity 240ms ease;
    z-index: 100;
}

.validation-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.segmented {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.segmented-row.invalid {
    border: 1px solid #d32f2f;
    border-radius: 10px;
    padding: 0.35rem;
    background: rgba(211, 47, 47, 0.05);
}

.segmented-row.invalid .segmented-option {
    border-color: #d32f2f;
}

.segmented button {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: #f8f9fc;
    font-weight: 600;
    color: #1e2a38;
    cursor: pointer;
}

.segmented button.active {
    border-color: var(--accent);
    background: rgba(25, 118, 210, 0.1);
    color: var(--accent);
}

.cta {
    width: 100%;
    padding: 0.9rem;
    border-radius: 10px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.cta.primary {
    background: var(--accent);
}

.cta.secondary {
    background: #fff;
    color: #65748b;
    border: 1px solid #d9dee7;
}

.cta.success {
    background: var(--success);
}

.cta-link {
    width: auto;
    padding: 0.55rem 1.4rem;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    text-decoration: none;
    color: white;
    background: rgba(255, 255, 255, 0.2);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.3px;
}

.otp-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.otp-row > * {
    min-width: 0;
}

.otp-input {
    padding-left: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
}

@media (max-width: 420px) {
    .otp-row {
        grid-template-columns: 1fr 1fr;
    }

    .otp-row .cta {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

@media (max-width: 480px) {
    main {
        padding: 0.9rem;
    }

    .card {
        padding: 1.6rem;
        border-radius: 16px;
    }

    .segmented {
        flex-direction: column;
    }

    .segmented button {
        width: 100%;
    }

    .otp-row .cta {
        width: 100%;
    }
}

@media (max-width: 360px) {
    .card {
        padding: 1.25rem;
    }

    .card-section h2 {
        font-size: 1.45rem;
    }

    .cta-link {
        width: 100%;
    }

    .otp-row {
        grid-template-columns: 1fr;
    }

    .otp-row .otp-input,
    .otp-row .cta {
        min-height: 44px;
    }

    .otp-row .cta {
        padding-top: 0.7rem;
        padding-bottom: 0.7rem;
    }
}

.consent {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    line-height: 1.3rem;
}

.emergency-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.emergency-button {
    border: none;
    border-radius: 24px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.link-row {
    font-size: 0.85rem;
    text-align: center;
}

.link-row a {
    color: #1976d2;
    text-decoration: none;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 500;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 18px;
    padding: 1.5rem;
    width: min(420px, 100%);
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.2);
    position: relative;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: #65748b;
}

.modal-toast {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(13, 110, 253, 0.95);
    color: white;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 200ms ease;
    pointer-events: none;
}

.modal-toast.show {
    opacity: 1;
}

.forgot-row {
    text-align: right;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.forgot-row a {
    color: #1976d2;
    text-decoration: none;
    font-weight: 600;
}

.button-row {
    margin-bottom: 0.5rem;
}

.footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #fff;
    font-size: 0.85rem;
}

.btn-hotline {
    background: #0b4f95;
    color: white;
    border-radius: 50%;
    width: 85px;
    height: 85px;
    flex-direction: column;
    gap: 4px;
    font-weight: 700;
    font-size: 0.7rem;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.bottom-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    margin-top: 1rem;
}

.logout-link {
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0.9;
}
