/* ===================================
   CSS VARIABLES
   =================================== */
:root {
    --forest-green: #3d5a3d;
    --deep-blue: #2b4a7c;
    --accent-gold: #c9a961;
    --cream: #f8f6f2;
    --charcoal: #2a2a2a;
    --soft-white: #ffffff;
}

/* ===================================
   GLOBAL RESET
   =================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===================================
   BODY & BACKGROUND
   =================================== */
body {
    font-family: 'Work Sans', sans-serif;
    background-image: url('../images/panpacific_background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #4a7c7c;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Tinted overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, rgba(100,180,200,0.7) 0%, rgba(120,200,180,0.7) 100%);
    z-index: 1;
    pointer-events: none;
}

/* Blur */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 2;
    pointer-events: none;
}

/* ===================================
   ANIMATIONS
   =================================== */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-8px); }
    75%       { transform: translateX(8px); }
}

/* ===================================
   LOGIN CONTAINER & CARD
   =================================== */
.login-container {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 420px;
    padding: 20px;
    animation: slideUp 0.8s ease-out;
}

.login-card {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 40px 36px 32px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    position: relative;
}

/* ===================================
   LOGO & TITLE
   =================================== */
.logo-container {
    text-align: center;
    margin-bottom: 24px;
    animation: fadeIn 1s ease-out 0.2s backwards;
}

.logo-container img {
    width: 150px;
    height: auto;
    margin: 0 auto 14px;
    display: block;
}

.system-title {
    font-family: 'Work Sans', sans-serif;
    font-size: clamp(16px, 5vw, 22px);
    font-weight: 600;
    color: var(--charcoal);
    letter-spacing: 0;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* ===================================
   FORM HEADING
   =================================== */
.form-heading {
    text-align: center;
    font-size: clamp(16px, 4.5vw, 20px);
    font-weight: 600;
    color: var(--charcoal);
    margin-bottom: 20px;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ===================================
   FORM GROUPS
   =================================== */
.form-group {
    margin-bottom: 14px;
}

/* ── FIX 1: Only hide <label> elements that are INSIDE .form-group,
              NOT the .terms-check label which must stay visible ── */
.form-group > label {
    display: none;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

/* ===================================
   INPUT FIELDS
   =================================== */
input[type="text"],
input[type="password"],
input[type="email"],
select {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Work Sans', sans-serif;
    transition: border-color 0.25s, box-shadow 0.25s;
    background: #fff;
    color: var(--charcoal);
}

.input-wrapper input[type="password"],
.input-wrapper input[type="text"] {
    padding-right: 48px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--forest-green);
    box-shadow: 0 0 0 3px rgba(61,90,61,0.1);
}

input::placeholder { color: #aaa; }

/* ===================================
   PASSWORD TOGGLE
   =================================== */
.password-toggle {
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 16px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    outline: none;
    transition: color 0.2s;
}

.password-toggle:hover { color: var(--forest-green); }
.password-toggle i     { pointer-events: none; }

/* ===================================
   LOGIN BUTTON
   =================================== */
.login-button {
    width: 100%;
    padding: 13px;
    background: var(--forest-green);
    color: var(--soft-white);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Work Sans', sans-serif;
    cursor: pointer;
    transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(61,90,61,0.3);
    position: relative;
    margin-top: 6px;
    display: block;
}

.login-button:hover {
    background: #2d4a2d;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(61,90,61,0.4);
}

.login-button:active { transform: translateY(0); }

.login-button.loading {
    pointer-events: none;
    opacity: 0.75;
}

.login-button.loading::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px; height: 15px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}

/* ===================================
   FORGOT / REMEMBER ROW
   =================================== */
.remember-forgot {
    display: flex;
    justify-content: center;
    margin-top: 12px;
}

.remember-me { display: none; }

.forgot-password {
    color: #777;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color 0.2s;
}

.forgot-password:hover { color: var(--charcoal); }

/* ===================================
   REGISTER CTA
   =================================== */
.register-cta {
    text-align: center;
    margin-top: 18px;
    font-size: 13px;
    color: #777;
    word-break: break-word;
    overflow-wrap: break-word;
    /* Prevent the two parts ("Don't have..." + "Register Now") from
       sitting on a single line that overflows a 320 px card */
    line-height: 1.7;
}

.register-cta a {
    color: var(--forest-green);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.register-cta a:hover {
    color: #2d4a2d;
    text-decoration: underline;
}

/* ===================================
   OR DIVIDER  (now sits above Google)
   =================================== */
.or-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 14px;
}

.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e4e4e4;
}

.or-divider span {
    font-size: 11.5px;
    color: #bbb;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

/* ===================================
   GOOGLE SIGN-IN BUTTON
   =================================== */
.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #dadce0;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-family: 'Work Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #3c4043;
    transition: background 0.18s, box-shadow 0.18s, border-color 0.18s;
    position: relative;
}

.google-btn:hover {
    background: #f8f9fa;
    box-shadow: 0 1px 6px rgba(60,64,67,.18);
    border-color: #bbb;
}

.google-btn:active { background: #f1f3f4; }

.google-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.google-btn.loading::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    border: 2px solid rgba(61,90,61,.25);
    border-top-color: var(--forest-green);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Domain restriction note */
.google-domain-note {
    text-align: center;
    font-size: 11.5px;
    color: #aaa;
    margin-top: 7px;
}

.google-domain-note i      { color: var(--forest-green); margin-right: 3px; }
.google-domain-note strong { color: #666; }

/* ===================================
   GOOGLE ERROR TOAST
   =================================== */
.g-toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #c62828;
    color: #fff;
    font-family: 'Work Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 11px 22px;
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.2);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    /* FIXED: was nowrap — overflowed on phones narrower than the message */
    white-space: normal;
    text-align: center;
    /* Never wider than the viewport minus breathing room */
    max-width: calc(100vw - 32px);
    word-break: break-word;
    overflow-wrap: break-word;
    pointer-events: none;
}

.g-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===================================
   MODAL BASE  (shared by both modals)
   =================================== */
.gp-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.52);
    z-index: 9000;
    display: flex;
    align-items: center;         /* vertically centre the card */
    justify-content: center;
    padding: 20px;
    overflow-y: auto;            /* allow page-scroll if card is taller than viewport */
    animation: fadeIn 0.2s ease;
}

/* ── FIX 2: max-height + overflow on the card itself ── */
.gp-modal-card {
    background: #fff;
    border-radius: 20px;
    padding: 36px 32px 28px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;           /* never taller than 90% of the viewport */
    overflow-y: auto;           /* scroll inside the card when content is tall */
    box-shadow: 0 14px 44px rgba(0,0,0,0.26);
    position: relative;
    animation: slideUp 0.28s cubic-bezier(0.34,1.36,0.64,1);
    /* push card to top when viewport is very short */
    margin: auto;
}

/* Register modal is slightly wider */
.reg-modal-card {
    max-width: 460px;
}

/* Modal logo */
.modal-logo {
    text-align: center;
    margin-bottom: 14px;
}

.modal-logo img {
    width: 78px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Modal subtitle */
.modal-subtitle {
    text-align: center;
    font-size: 13px;
    color: #777;
    margin-bottom: 20px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Close button */
.modal-close-btn {
    position: absolute;
    top: 13px;
    right: 16px;
    background: none;
    border: none;
    font-size: 26px;
    font-weight: 700;
    color: #bbb;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    transition: color 0.18s;
}

.modal-close-btn:hover { color: var(--charcoal); }

/* Shared feedback message (replaces .fp-msg and .reg-msg) */
.modal-feedback {
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    margin-top: 10px;
    min-height: 18px;
    line-height: 1.4;
    /* Prevent long server error strings from overflowing the modal card */
    word-break: break-word;
    overflow-wrap: break-word;
    padding: 0 4px;
}

.modal-feedback.success { color: #27ae60; }
.modal-feedback.error   { color: #e74c3c; }

/* ===================================
   REGISTER MODAL — SPECIFIC STYLES
   =================================== */

/* ── FIX 3: proper centering without positional hacks ── */
.reg-domain-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 12px;
    color: #6a4e00;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 20px;
    padding: 4px 14px;
    margin: 0 auto 18px;
    width: fit-content;
    max-width: 100%;
    /* Wrap gracefully if text is wider than the card on small screens */
    word-break: break-word;
    overflow-wrap: break-word;
    text-align: center;
    /* flex children must be able to shrink below their content width */
    min-width: 0;
}

.reg-domain-badge i { color: var(--forest-green); }

/* Two-column grid */
.reg-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 4px;
}

.reg-grid .form-group { margin-bottom: 0; }
.reg-full             { grid-column: 1 / -1; }

/* Email hint */
.reg-email-hint {
    font-size: 11.5px;
    color: #aaa;
    margin-top: 5px;
    transition: color 0.2s;
    line-height: 1.3;
}

.reg-email-hint.ok  { color: #27ae60; }
.reg-email-hint.err { color: #e74c3c; }

/* Password strength bar */
.strength-track {
    height: 4px;
    background: #eee;
    border-radius: 4px;
    margin-top: 7px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.3s ease, background-color 0.3s ease;
    background-color: transparent;
}

.strength-lbl {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
    min-height: 15px;
}

/* ── FIX 4: Terms checkbox — use div+label pattern so the
              global label rule never hides it ── */
.terms-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
}

.terms-check input[type="checkbox"] {
    /* reset width from the global input rule */
    width: 15px;
    min-width: 15px;
    height: 15px;
    margin-top: 2px;
    accent-color: var(--forest-green);
    cursor: pointer;
    flex-shrink: 0;
    /* override any padding from global input rule */
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.terms-check label {
    /* Override the global label rule — this label MUST be visible */
    display: block !important;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    line-height: 1.5;
}

.terms-check label a {
    color: var(--forest-green);
    text-decoration: none;
}

.terms-check label a:hover { text-decoration: underline; }

/* Register submit button spacing */
#regBtn { margin-top: 16px; }

/* Select dropdown */
.reg-modal-card select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 36px;
    cursor: pointer;
    color: #555;
}

/* Success screen */
.reg-success-wrap {
    text-align: center;
    padding: 16px 0;
    animation: fadeIn 0.35s ease;
}

.reg-success-ico {
    font-size: 52px;
    color: #27ae60;
    display: block;
    margin-bottom: 14px;
}

.reg-success-title {
    font-family: 'Playfair Display', serif;
    font-size: 22px;
    color: var(--charcoal);
    margin-bottom: 10px;
}

.reg-success-body {
    font-size: 14px;
    color: #666;
    line-height: 1.75;
    margin-bottom: 4px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.reg-success-email { color: var(--forest-green); }

/* ===================================
   RESPONSIVE — MOBILE
   =================================== */
@media (max-width: 768px) {
    .login-container { max-width: 92%; padding: 16px; }
    .login-card { padding: 34px 28px 28px; }
    .logo-container img { width: 140px; }
}

@media (max-width: 500px) {
    .login-container { max-width: 96%; padding: 12px; }
    .login-card { padding: 28px 20px 24px; border-radius: 16px; }
    .logo-container img { width: 120px; }
    .system-title { font-size: 20px; }
    .form-heading { font-size: 18px; margin-bottom: 16px; }

    input[type="text"],
    input[type="password"],
    input[type="email"] { font-size: 16px; padding: 12px 14px; }

    .input-wrapper input[type="password"],
    .input-wrapper input[type="text"] { padding-right: 44px; }

    .login-button { font-size: 15px; }

    /* Register modal: single column on phones */
    .reg-grid               { grid-template-columns: 1fr; }
    .reg-full               { grid-column: 1; }
    .gp-modal-card          { padding: 28px 20px 22px; }
    .reg-modal-card         { max-width: 100%; }
}

@media (max-width: 380px) {
    .login-card { padding: 24px 16px 20px; border-radius: 14px; }
    .logo-container img { width: 105px; }
    .system-title { font-size: 18px; }
    .form-heading { font-size: 16px; margin-bottom: 14px; }
    .google-btn { font-size: 13px; }
    .form-group { margin-bottom: 12px; }
    .login-button { font-size: 14px; }
    .password-toggle { right: 10px; }
}

/* ── Galaxy S5 / iPhone SE (1st gen) and older small phones (≤ 320 px) ── */
@media (max-width: 320px) {
    .login-container    { max-width: 100%; padding: 8px; }
    .login-card         { padding: 20px 12px 18px; border-radius: 12px; }
    .logo-container img { width: 90px; margin-bottom: 10px; }
    .system-title       { font-size: 16px; }
    .form-heading       { font-size: 15px; margin-bottom: 12px; }
    .register-cta       { font-size: 12px; }
    .forgot-password    { font-size: 12px; }

    input[type="text"],
    input[type="password"],
    input[type="email"] { font-size: 15px; padding: 11px 12px; }

    .login-button       { font-size: 14px; padding: 11px; }
    .google-btn         { font-size: 12px; padding: 10px 12px; gap: 8px; }
    .google-domain-note { font-size: 10.5px; }

    .gp-modal-card      { padding: 22px 14px 18px; }
    .reg-domain-badge   { font-size: 11px; padding: 4px 10px; }
    .modal-subtitle     { font-size: 12px; }
    .modal-feedback     { font-size: 12px; }
    .reg-email-hint     { font-size: 11px; }
    .strength-lbl       { font-size: 10px; }
    .terms-check label  { font-size: 11px; }

    /* Toasts should never be wider than the screen */
    .g-toast { font-size: 12px; padding: 9px 14px; }
}

/* Short landscape (e.g. phone rotated) */
@media (max-height: 600px) and (orientation: landscape) {
    body { align-items: flex-start; }
    .login-container { margin: 16px auto; }
    .login-card { padding: 20px 24px 18px; }
    .logo-container { margin-bottom: 10px; }
    .logo-container img { width: 80px; margin-bottom: 8px; }
    .system-title { font-size: 16px; }
    .form-heading { font-size: 15px; margin-bottom: 12px; }
    .form-group { margin-bottom: 10px; }
    input[type="text"], input[type="password"], input[type="email"] { padding: 10px 12px; }
    .login-button { padding: 10px; }
    .or-divider { margin: 10px 0 10px; }
    .register-cta { margin-top: 12px; }
    /* Modal: allow scroll on short screens */
    .gp-modal { align-items: flex-start; padding: 12px; }
    .gp-modal-card { margin: 0 auto; max-height: 95vh; }
}

/* Retina screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .login-card { box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
}

/* Touch devices — bigger tap targets */
@media (hover: none) and (pointer: coarse) {
    .password-toggle { padding: 8px; min-width: 44px; min-height: 44px; }
    .forgot-password { padding: 8px 4px; display: inline-block; }
    .login-button    { min-height: 48px; }
    .google-btn      { min-height: 48px; }
    .modal-close-btn { min-width: 44px; min-height: 44px; }
}

/* Safe-area insets (notch / Dynamic Island) */
@supports (padding: max(0px)) {
    .login-container {
        padding-left:   max(20px, env(safe-area-inset-left));
        padding-right:  max(20px, env(safe-area-inset-right));
        padding-top:    max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}