/**
 * Auth Modal - スライドインモーダル認証UI
 *
 * 右からスライドインするモーダル型の認証フォーム
 */

/* ========================================
   CSS Variables
   ======================================== */
:root {
    --auth-modal-width: 420px;
    --auth-modal-bg: #ffffff;
    --auth-modal-overlay: rgba(0, 0, 0, 0.5);
    --auth-modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Colors */
    --auth-primary: #111111;
    --auth-primary-hover: #333333;
    --auth-text: #111111;
    --auth-text-muted: #6b7280;
    --auth-border: #e5e7eb;
    --auth-border-focus: #111111;
    --auth-error: #dc2626;
    --auth-error-bg: #fef2f2;
    --auth-success: #059669;
    --auth-success-bg: #d1fae5;

    /* Spacing */
    --auth-spacing-xs: 4px;
    --auth-spacing-sm: 8px;
    --auth-spacing-md: 16px;
    --auth-spacing-lg: 24px;
    --auth-spacing-xl: 32px;

    /* Typography */
    --auth-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
    --auth-font-size-sm: 13px;
    --auth-font-size-base: 15px;
    --auth-font-size-lg: 18px;
    --auth-font-size-xl: 24px;

    /* Animation */
    --auth-transition-fast: 0.15s ease;
    --auth-transition-normal: 0.3s ease;
    --auth-transition-slide: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ========================================
   Modal Container
   ======================================== */
.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    pointer-events: none;
    visibility: hidden;
}

.auth-modal.is-open {
    pointer-events: auto;
    visibility: visible;
}

/* ========================================
   Overlay
   ======================================== */
.auth-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--auth-modal-overlay);
    opacity: 0;
    transition: opacity var(--auth-transition-normal);
}

.auth-modal.is-open .auth-modal-overlay {
    opacity: 1;
}

/* ========================================
   Panel (Slide-in Container)
   ======================================== */
.auth-modal-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    max-width: var(--auth-modal-width);
    height: 100%;
    background: var(--auth-modal-bg);
    box-shadow: var(--auth-modal-shadow);
    transform: translateX(100%);
    transition: transform var(--auth-transition-slide);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.auth-modal.is-open .auth-modal-panel {
    transform: translateX(0);
}

/* ========================================
   Panel Header
   ======================================== */
.auth-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--auth-spacing-md) var(--auth-spacing-lg);
    border-bottom: 1px solid var(--auth-border);
    flex-shrink: 0;
}

.auth-modal-title {
    font-size: var(--auth-font-size-lg);
    font-weight: 600;
    color: var(--auth-text);
    margin: 0;
}

.auth-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--auth-text-muted);
    transition: background var(--auth-transition-fast), color var(--auth-transition-fast);
}

.auth-modal-close:hover {
    background: var(--auth-border);
    color: var(--auth-text);
}

.auth-modal-close svg {
    width: 24px;
    height: 24px;
}

/* ========================================
   Panel Body
   ======================================== */
.auth-modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* ========================================
   Auth Views Container
   ======================================== */
.auth-views {
    position: relative;
    width: 300%;
    display: flex;
    transition: transform var(--auth-transition-slide);
}

.auth-views[data-active="login"] {
    transform: translateX(0);
}

.auth-views[data-active="register"] {
    transform: translateX(-33.333%);
}

.auth-views[data-active="reset"] {
    transform: translateX(-66.666%);
}

/* ========================================
   Individual View
   ======================================== */
.auth-view {
    width: 33.333%;
    flex-shrink: 0;
    padding: var(--auth-spacing-xl) var(--auth-spacing-lg);
}

/* ========================================
   Form Styles
   ======================================== */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--auth-spacing-lg);
}

/* Form Group */
.auth-form-group {
    display: flex;
    flex-direction: column;
    gap: var(--auth-spacing-xs);
}

.auth-form-group label {
    font-size: var(--auth-font-size-sm);
    font-weight: 500;
    color: var(--auth-text);
}

.auth-form-group label .required {
    color: var(--auth-error);
    margin-left: 2px;
}

/* Input Fields */
.auth-input {
    width: 100%;
    padding: 12px 16px;
    font-size: var(--auth-font-size-base);
    font-family: var(--auth-font-family);
    color: var(--auth-text);
    background: var(--auth-modal-bg);
    border: 1px solid var(--auth-border);
    border-radius: 8px;
    outline: none;
    transition: border-color var(--auth-transition-fast), box-shadow var(--auth-transition-fast);
}

.auth-input:focus {
    border-color: var(--auth-border-focus);
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.1);
}

.auth-input.has-error {
    border-color: var(--auth-error);
}

.auth-input.has-error:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.auth-input::placeholder {
    color: var(--auth-text-muted);
}

/* Password Input Wrapper */
.auth-password-wrapper {
    position: relative;
}

.auth-password-wrapper .auth-input {
    padding-right: 48px;
}

.auth-password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--auth-text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-password-toggle:hover {
    color: var(--auth-text);
}

.auth-password-toggle svg {
    width: 20px;
    height: 20px;
}

/* Password Strength Indicator */
.auth-password-strength {
    display: flex;
    gap: 4px;
    margin-top: var(--auth-spacing-sm);
}

.auth-password-strength-bar {
    height: 4px;
    flex: 1;
    background: var(--auth-border);
    border-radius: 2px;
    transition: background var(--auth-transition-fast);
}

.auth-password-strength[data-strength="1"] .auth-password-strength-bar:nth-child(1) {
    background: var(--auth-error);
}

.auth-password-strength[data-strength="2"] .auth-password-strength-bar:nth-child(-n+2) {
    background: #f59e0b;
}

.auth-password-strength[data-strength="3"] .auth-password-strength-bar:nth-child(-n+3) {
    background: #10b981;
}

.auth-password-strength[data-strength="4"] .auth-password-strength-bar {
    background: var(--auth-success);
}

.auth-password-strength-text {
    font-size: var(--auth-font-size-sm);
    color: var(--auth-text-muted);
    margin-top: 4px;
}

/* Checkbox */
.auth-checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: var(--auth-spacing-sm);
}

.auth-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--auth-primary);
    cursor: pointer;
}

.auth-checkbox-label {
    font-size: var(--auth-font-size-sm);
    color: var(--auth-text);
    cursor: pointer;
}

/* Field Error */
.auth-field-error {
    font-size: 12px;
    color: var(--auth-error);
    margin-top: 4px;
    display: none;
}

.auth-form-group.has-error .auth-field-error {
    display: block;
}

/* ========================================
   Submit Button
   ======================================== */
.auth-submit-btn {
    width: 100%;
    padding: 14px 24px;
    font-size: var(--auth-font-size-base);
    font-weight: 600;
    font-family: var(--auth-font-family);
    color: #ffffff;
    background: var(--auth-primary);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: background var(--auth-transition-fast), transform var(--auth-transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--auth-spacing-sm);
}

.auth-submit-btn:hover:not(:disabled) {
    background: var(--auth-primary-hover);
}

.auth-submit-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.auth-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading Spinner */
.auth-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Messages
   ======================================== */
.auth-message {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: var(--auth-font-size-sm);
    line-height: 1.5;
    display: none;
}

.auth-message.is-visible {
    display: block;
}

.auth-message.is-error {
    background: var(--auth-error-bg);
    border: 1px solid var(--auth-error);
    color: #991b1b;
}

.auth-message.is-success {
    background: var(--auth-success-bg);
    border: 1px solid var(--auth-success);
    color: #065f46;
}

/* ========================================
   Links & Navigation
   ======================================== */
.auth-links {
    display: flex;
    flex-direction: column;
    gap: var(--auth-spacing-sm);
    text-align: center;
    margin-top: var(--auth-spacing-md);
}

.auth-link {
    font-size: var(--auth-font-size-sm);
    color: var(--auth-text-muted);
    text-decoration: none;
    transition: color var(--auth-transition-fast);
}

.auth-link:hover {
    color: var(--auth-text);
    text-decoration: underline;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--auth-spacing-md);
    margin: var(--auth-spacing-lg) 0;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--auth-border);
}

.auth-divider span {
    font-size: var(--auth-font-size-sm);
    color: var(--auth-text-muted);
}

/* ========================================
   Optional Fields (Collapsible)
   ======================================== */
.auth-optional-fields {
    border: 1px solid var(--auth-border);
    border-radius: 8px;
    overflow: hidden;
}

.auth-optional-fields summary {
    padding: 12px 16px;
    font-size: var(--auth-font-size-sm);
    font-weight: 500;
    color: var(--auth-text-muted);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--auth-spacing-sm);
}

.auth-optional-fields summary::-webkit-details-marker {
    display: none;
}

.auth-optional-fields summary::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 5px solid var(--auth-text-muted);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--auth-transition-fast);
}

.auth-optional-fields[open] summary::before {
    transform: rotate(90deg);
}

.auth-optional-fields-content {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: var(--auth-spacing-md);
}

/* ========================================
   Select (Prefecture)
   ======================================== */
.auth-select {
    width: 100%;
    padding: 12px 16px;
    font-size: var(--auth-font-size-base);
    font-family: var(--auth-font-family);
    color: var(--auth-text);
    background: var(--auth-modal-bg);
    border: 1px solid var(--auth-border);
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.auth-select:focus {
    border-color: var(--auth-border-focus);
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.1);
}

/* ========================================
   Header Login Button
   ======================================== */
.header-auth-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--auth-font-family);
    color: #ffffff;
    background: var(--auth-primary);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background var(--auth-transition-fast), transform var(--auth-transition-fast);
    white-space: nowrap;
    line-height: 1.4;
    vertical-align: middle;
}

.header-auth-btn:hover {
    background: var(--auth-primary-hover);
}

.header-auth-btn:active {
    transform: scale(0.96);
}

.header-auth-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* SWELL Theme Navigation Integration */
.l-header .header-auth-btn,
.l-header__gnav .header-auth-btn,
.c-gnav .header-auth-btn,
.p-gnav .header-auth-btn,
.l-fixHeader .header-auth-btn {
    margin: 0;
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
}

/* Menu item wrapper integration */
.menu-item .header-auth-btn,
.c-gnav__item .header-auth-btn,
.p-gnav__item .header-auth-btn,
li .header-auth-btn {
    display: inline-flex;
}

/* Account icon container styling for logged-out state */
.account-icon-wrapper:has(.header-auth-btn),
.menu-item:has(.header-auth-btn) {
    display: flex;
    align-items: center;
}

/* Reset any inherited menu link styles */
.menu-item .header-auth-btn,
.c-gnav__item .header-auth-btn {
    text-decoration: none;
    box-shadow: none;
}

/* Auth trigger wrapper - ensure proper inline positioning */
.ua-auth-trigger-wrapper {
    display: inline-flex;
    align-items: center;
}

/* SWELL theme specific: ensure button stays in line */
.c-gnav__item > .ua-auth-trigger-wrapper,
.c-gnav__item > .ua-simple-account {
    display: inline-flex;
    align-items: center;
    height: 100%;
}

/* Fix for SWELL menu item alignment */
.menu-item.menu-item-type-custom .ua-auth-trigger-wrapper {
    position: static;
}

/* ========================================
   Body Scroll Lock
   ======================================== */
body.auth-modal-open {
    overflow: hidden;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 480px) {
    .auth-modal-panel {
        max-width: 100%;
    }

    .auth-view {
        padding: var(--auth-spacing-lg) var(--auth-spacing-md);
        padding-bottom: calc(var(--auth-spacing-lg) + env(safe-area-inset-bottom, 0px));
    }

    .auth-modal-header {
        padding: var(--auth-spacing-md);
        padding-top: calc(var(--auth-spacing-md) + env(safe-area-inset-top, 0px));
    }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .auth-modal-panel,
    .auth-modal-overlay,
    .auth-views,
    .auth-input,
    .auth-submit-btn {
        transition: none;
    }

    .auth-spinner {
        animation: none;
    }
}

/* Focus visible for keyboard navigation */
.auth-input:focus-visible,
.auth-submit-btn:focus-visible,
.auth-modal-close:focus-visible,
.auth-link:focus-visible,
.auth-password-toggle:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
}

/* ========================================
   Profile Modal Styles
   ======================================== */

/* Profile Modal uses same base modal styles */
#profile-modal {
    /* Inherits from .auth-modal */
}

/* Profile Views Container */
.profile-views {
    position: relative;
    width: 600%;
    display: flex;
    transition: transform var(--auth-transition-slide);
}

.profile-views[data-active="menu"] {
    transform: translateX(0);
}

.profile-views[data-active="edit"] {
    transform: translateX(calc(-100% / 6));
}

.profile-views[data-active="email"] {
    transform: translateX(calc(-200% / 6));
}

.profile-views[data-active="address"] {
    transform: translateX(calc(-300% / 6));
}

.profile-views[data-active="password"] {
    transform: translateX(calc(-400% / 6));
}

.profile-views[data-active="withdrawal"] {
    transform: translateX(calc(-500% / 6));
}

/* Individual Profile View */
.profile-view {
    width: calc(100% / 6);
    flex-shrink: 0;
    padding: var(--auth-spacing-lg) var(--auth-spacing-lg);
}

/* Profile Header (Avatar + Name) */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--auth-spacing-md);
    padding-bottom: var(--auth-spacing-lg);
    border-bottom: 1px solid var(--auth-border);
    margin-bottom: var(--auth-spacing-lg);
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--auth-border);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-info {
    flex: 1;
    min-width: 0;
}

.profile-name {
    font-size: var(--auth-font-size-lg);
    font-weight: 600;
    color: var(--auth-text);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-email {
    font-size: var(--auth-font-size-sm);
    color: var(--auth-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Profile Menu Navigation */
.profile-menu {
    display: flex;
    flex-direction: column;
    gap: var(--auth-spacing-sm);
}

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: var(--auth-spacing-md);
    padding: 14px 16px;
    background: none;
    border: 1px solid var(--auth-border);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--auth-transition-fast);
    text-align: left;
    color: var(--auth-text);
    font-size: var(--auth-font-size-base);
    font-family: var(--auth-font-family);
}

.profile-menu-item:hover {
    background: #f9fafb;
    border-color: var(--auth-text-muted);
}

.profile-menu-item svg {
    width: 22px;
    height: 22px;
    color: var(--auth-text-muted);
    flex-shrink: 0;
}

.profile-menu-item span {
    flex: 1;
}

.profile-menu-arrow {
    width: 18px !important;
    height: 18px !important;
    color: var(--auth-text-muted) !important;
}

/* Back Button */
.profile-back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--auth-spacing-sm);
    padding: 8px 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--auth-text-muted);
    font-size: var(--auth-font-size-sm);
    font-family: var(--auth-font-family);
    margin-bottom: var(--auth-spacing-lg);
    transition: color var(--auth-transition-fast);
}

.profile-back-btn:hover {
    color: var(--auth-text);
}

.profile-back-btn svg {
    width: 18px;
    height: 18px;
}

/* Form Row (Side by Side Fields) */
.auth-form-row {
    display: flex;
    gap: var(--auth-spacing-md);
}

.auth-form-group--half {
    flex: 1;
}

/* Field Hint */
.auth-field-hint {
    font-size: 12px;
    color: var(--auth-text-muted);
    margin-top: 4px;
}

/* Current Value Display */
.auth-current-value {
    padding: 12px 16px;
    background: #f9fafb;
    border: 1px solid var(--auth-border);
    border-radius: 8px;
    color: var(--auth-text);
    font-size: var(--auth-font-size-base);
}

/* ========================================
   Responsive - Profile Modal
   ======================================== */
@media (max-width: 480px) {
    .profile-view {
        padding: var(--auth-spacing-md);
    }

    .profile-header {
        flex-direction: column;
        text-align: center;
    }

    .profile-avatar {
        width: 80px;
        height: 80px;
    }

    .profile-info {
        text-align: center;
    }

    .profile-name,
    .profile-email {
        white-space: normal;
    }

    .auth-form-row {
        flex-direction: column;
    }
}

/* ─── Account Withdrawal (Danger) ─── */
.profile-menu-item--danger {
    color: #dc2626;
    border-color: #fecaca;
}

.profile-menu-item--danger:hover {
    background: #fef2f2;
    border-color: #f87171;
}

.profile-menu-item--danger svg {
    color: #dc2626;
}

.auth-withdrawal-warning {
    display: flex;
    gap: var(--auth-spacing-md);
    padding: 14px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    margin-bottom: var(--auth-spacing-lg);
    font-size: var(--auth-font-size-sm);
    color: #991b1b;
    line-height: 1.6;
}

.auth-withdrawal-warning svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    margin-top: 2px;
}

.auth-textarea {
    width: 100%;
    padding: 12px 16px;
    font-size: var(--auth-font-size-base);
    font-family: var(--auth-font-family);
    color: var(--auth-text);
    background: #ffffff;
    border: 1.5px solid var(--auth-border);
    border-radius: 10px;
    transition: border-color var(--auth-transition-fast);
    resize: vertical;
    min-height: 80px;
    box-sizing: border-box;
}

.auth-textarea:focus {
    outline: none;
    border-color: var(--auth-primary);
}

.auth-submit-btn--danger {
    background: #dc2626;
}

.auth-submit-btn--danger:hover:not(:disabled) {
    background: #b91c1c;
}
