/*
 * MeatMaster — unified phone verification modal.
 *
 * One shell, three screens (phone → otp → success). Visual chrome only —
 * the state machine lives in phone-modal.js. Designed to look and feel
 * consistent with a modern app-style verification flow (Stripe, banking,
 * one-time-code inputs from iOS/Android autofill).
 *
 * Palette:
 *   --mm-modal-ink       primary text
 *   --mm-modal-muted     secondary text
 *   --mm-modal-hair      hairline borders
 *   --mm-modal-accent    brand green — the "verified" moment
 *   --mm-modal-danger    error state
 */

:root {
    --mm-modal-ink:    #111827;
    --mm-modal-muted:  #6B7280;
    --mm-modal-hair:   #E5E7EB;
    --mm-modal-tile:   #FFFFFF;
    --mm-modal-accent: #009363;
    --mm-modal-danger: #DC2626;
    --mm-modal-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.08);
    --mm-modal-radius: 16px;
}

/* Root modal — hidden by default (also has [hidden] as belt-and-braces). */
.mm-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--mm-modal-ink);
}
.mm-modal[hidden] { display: none; }

/* Body scroll lock when open. */
html.mm-modal-open { overflow: hidden; }

/* Backdrop */
.mm-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: mm-modal-fade 200ms ease-out;
}

/* Dialog */
.mm-modal__dialog {
    position: relative;
    background: var(--mm-modal-tile);
    border-radius: var(--mm-modal-radius);
    box-shadow: var(--mm-modal-shadow);
    width: 100%;
    max-width: 440px;
    padding: 32px 28px 28px;
    animation: mm-modal-pop 240ms cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

/* Close button */
.mm-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 0;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--mm-modal-muted);
    transition: background 120ms ease, color 120ms ease;
}
.mm-modal__close:hover {
    background: #F3F4F6;
    color: var(--mm-modal-ink);
}

/* Content wrapper — for screen transitions */
.mm-modal__content { text-align: center; }

/* Individual screen */
.mm-modal__screen[hidden] { display: none; }
.mm-modal__screen {
    animation: mm-modal-slide 260ms ease-out;
}

/* Icon at the top of a screen */
.mm-modal__icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F3F4F6;
    color: var(--mm-modal-ink);
    border-radius: 999px;
}

/* Title + intro copy */
.mm-modal__title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px;
    line-height: 1.2;
    color: var(--mm-modal-ink);
}
.mm-modal__intro {
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--mm-modal-muted);
    margin: 0 0 20px;
}
.mm-modal__intro strong {
    color: var(--mm-modal-ink);
    font-weight: 600;
    white-space: nowrap;
}

/* Field label */
.mm-modal__label {
    display: block;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--mm-modal-ink);
    margin: 0 0 8px;
}

/* +971 phone input */
.mm-modal__phone {
    display: flex;
    align-items: stretch;
    margin: 0 0 16px;
    border: 2px solid var(--mm-modal-hair);
    border-radius: 12px;
    background: #FFF;
    transition: border-color 120ms ease, box-shadow 120ms ease;
    overflow: hidden;
}
.mm-modal__phone:focus-within {
    border-color: var(--mm-modal-ink);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08);
}
.mm-modal__prefix {
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    background: #F9FAFB;
    border-right: 1px solid var(--mm-modal-hair);
    font-weight: 600;
    font-size: 16px;
    color: var(--mm-modal-ink);
    white-space: nowrap;
}
.mm-modal__phone-input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 14px 16px;
    font-size: 17px;
    font-weight: 500;
    color: var(--mm-modal-ink);
    outline: none;
    min-width: 0;
}
.mm-modal__phone-input::placeholder { color: #9CA3AF; font-weight: 400; }

/* Primary CTA */
.mm-modal__primary {
    display: block;
    width: 100%;
    height: 52px;
    padding: 0 20px;
    border: 0;
    border-radius: 12px;
    background: var(--mm-modal-ink);
    color: #FFF;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, transform 60ms ease;
}
.mm-modal__primary:hover { background: #000; }
.mm-modal__primary:active { transform: translateY(1px); }
.mm-modal__primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Disclosure text */
.mm-modal__disclosure {
    font-size: 12.5px;
    line-height: 1.55;
    color: #9CA3AF;
    margin: 16px 0 0;
    text-align: center;
}
.mm-modal__disclosure a {
    color: var(--mm-modal-muted);
    text-decoration: underline;
}

/* Message row (status / error) */
.mm-modal__message {
    min-height: 20px;
    margin: 12px 0 0;
    font-size: 13px;
    color: var(--mm-modal-muted);
    text-align: center;
}
.mm-modal__message.is-error { color: var(--mm-modal-danger); font-weight: 500; }
.mm-modal__message.is-ok    { color: var(--mm-modal-accent); font-weight: 500; }

/* ── OTP screen ─────────────────────────────────────────────────── */

.mm-modal__otp {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 8px 0 4px;
    direction: ltr; /* keep OTP LTR even in RTL locales */
}
.mm-modal__otp-box {
    width: 48px;
    height: 56px;
    padding: 0;
    border: 2px solid var(--mm-modal-hair);
    border-radius: 12px;
    background: #FFF;
    color: var(--mm-modal-ink);
    font-family: inherit;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
    -moz-appearance: textfield;
}
.mm-modal__otp-box::-webkit-outer-spin-button,
.mm-modal__otp-box::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.mm-modal__otp-box:focus {
    border-color: var(--mm-modal-ink);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08);
}
.mm-modal__otp-box.is-error {
    border-color: var(--mm-modal-danger);
    animation: mm-modal-shake 0.35s;
}

/* Bottom action row (change / resend) */
.mm-modal__actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--mm-modal-hair);
}
.mm-modal__link {
    background: transparent;
    border: 0;
    color: var(--mm-modal-muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    padding: 6px 4px;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.mm-modal__link:hover:not(:disabled) { color: var(--mm-modal-ink); }
.mm-modal__link:disabled { opacity: 0.55; cursor: not-allowed; text-decoration: none; }

/* ── Success screen ─────────────────────────────────────────────── */

.mm-modal__screen--success {
    padding: 12px 0;
}
.mm-modal__check {
    color: var(--mm-modal-accent);
    margin: 8px auto 20px;
    width: 88px;
    height: 88px;
}
.mm-modal__check-svg { display: block; }
.mm-modal__check-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    animation: mm-modal-draw-circle 500ms 100ms ease-out forwards;
}
.mm-modal__check-mark {
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: mm-modal-draw-mark 400ms 600ms ease-out forwards;
}
.mm-modal__success-title {
    color: var(--mm-modal-accent);
    margin: 0 0 8px;
    font-size: 24px;
}
.mm-modal__success-line {
    color: var(--mm-modal-ink);
    font-size: 15px;
    line-height: 1.5;
    margin: 0;
    padding: 0 8px;
}

/* ── Checkout step-1 verify block (rendered by Checkout::renderStep1Contents)
   The actual OTP UI is this modal; the block just shows the state inside
   the accordion — either a "verified" summary or a re-open trigger. */

.mm-verify-block { margin: 0; }

/* Verified summary — green tick + phone */
.mm-verify-summary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(0, 147, 99, 0.08);
    border: 1px solid rgba(0, 147, 99, 0.25);
    border-radius: 10px;
    color: #065F46;
    font-size: 15px;
}
.mm-verify-summary__check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: var(--mm-modal-accent);
    color: #FFF;
    flex-shrink: 0;
}
.mm-verify-summary__text strong { color: var(--mm-modal-ink); }

/* Unverified prompt (shown if the shopper closed the modal) */
.mm-verify-prompt { text-align: left; }
.mm-verify-prompt__lead {
    margin: 0 0 12px;
    color: #4B5563;
    font-size: 15px;
}
.mm-verify-prompt__button {
    display: inline-block;
    padding: 12px 20px;
    border: 0;
    border-radius: 10px;
    background: var(--mm-modal-ink);
    color: #FFF;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease;
}
.mm-verify-prompt__button:hover { background: #000; }

/* Hide WooCommerce's default email/password login + register forms on the
   logged-out My Account page — the modal replaces them. Scoped so it never
   affects a logged-in user's account screens. */
.woocommerce-account:not(.logged-in) .woocommerce-form-login,
.woocommerce-account:not(.logged-in) .woocommerce-form-register,
.woocommerce-account:not(.logged-in) .u-column1.col-1 > h2,
.woocommerce-account:not(.logged-in) .u-column2.col-2 { display: none !important; }

/* Dev bypass hint — pinned at bottom, easy to ignore in prod (never shows). */
.mm-modal-devhint {
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 99999;
    margin: 0;
    padding: 8px 12px;
    background: #FFF7ED;
    color: #A15C00;
    border: 1px solid #FED7AA;
    border-radius: 8px;
    font-size: 12px;
    max-width: 320px;
}

/* ── Animations ─────────────────────────────────────────────────── */

@keyframes mm-modal-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes mm-modal-pop {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes mm-modal-slide {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}
@keyframes mm-modal-shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    50%      { transform: translateX(6px); }
    75%      { transform: translateX(-3px); }
}
@keyframes mm-modal-draw-circle {
    to { stroke-dashoffset: 0; }
}
@keyframes mm-modal-draw-mark {
    to { stroke-dashoffset: 0; }
}

/* ── Mobile ─────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    .mm-modal { padding: 0; align-items: flex-end; }
    .mm-modal__dialog {
        max-width: none;
        max-height: 95vh;
        border-radius: var(--mm-modal-radius) var(--mm-modal-radius) 0 0;
        padding: 28px 22px 22px;
        animation: mm-modal-slide-up 300ms cubic-bezier(0.16, 1, 0.3, 1);
    }
    .mm-modal__title { font-size: 20px; }
    .mm-modal__otp { gap: 8px; }
    .mm-modal__otp-box {
        width: 44px;
        height: 52px;
        font-size: 22px;
    }
}

@keyframes mm-modal-slide-up {
    from { opacity: 0; transform: translateY(60px); }
    to   { opacity: 1; transform: translateY(0);    }
}

/* Even tighter on very narrow phones */
@media (max-width: 360px) {
    .mm-modal__otp { gap: 6px; }
    .mm-modal__otp-box { width: 40px; height: 48px; font-size: 20px; }
    .mm-modal__dialog { padding: 24px 16px 18px; }
}

/* Reduced motion — disable non-essential animations */
@media (prefers-reduced-motion: reduce) {
    .mm-modal__backdrop,
    .mm-modal__dialog,
    .mm-modal__screen,
    .mm-modal__otp-box,
    .mm-modal__check-circle,
    .mm-modal__check-mark {
        animation: none !important;
    }
    .mm-modal__check-circle { stroke-dashoffset: 0; }
    .mm-modal__check-mark   { stroke-dashoffset: 0; }
}
