/* ============================================
   登录/注册弹窗 - 暗黑手绘黄色风格（共享版）
   ============================================
   从 css/preview-dark.css + css/preview-custom.css 提取的弹窗专用样式，
   供「读书与思考」等非 Preview 页面复用。所有主题变量在本文件内自带定义，
   不依赖 preview-dark.css，也不会污染宿主页面的其他样式。
   弹窗结构 / ID 必须与 Preview.html 保持一致（preview-auth.js 依赖）。
   ============================================ */

:root {
    --tom-auth-dark-bg: #0a0a0a;
    --tom-auth-dark-card: #1a1a1a;
    --tom-auth-dark-border: #2a2a2a;
    --tom-auth-yellow: #E0B33C;
    --tom-auth-yellow-dark: #C1932A;
    --tom-auth-yellow-bright: #F2D06B;
    --tom-auth-text-light: #f5f5f5;
    --tom-auth-text-muted: #a0a0a0;
}

/* 弹窗内部统一走原变量名（在弹窗根节点上做局部映射，避免与宿主页面冲突） */
#auth-modal-overlay,
#user-profile-modal,
#preview-confirm-dialog {
    --dark-bg: var(--tom-auth-dark-bg);
    --dark-card: var(--tom-auth-dark-card);
    --dark-border: var(--tom-auth-dark-border);
    --yellow: var(--tom-auth-yellow);
    --yellow-dark: var(--tom-auth-yellow-dark);
    --yellow-bright: var(--tom-auth-yellow-bright);
    --text-light: var(--tom-auth-text-light);
    --text-muted: var(--tom-auth-text-muted);
}

.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.auth-modal-overlay:not(.hidden) {
    opacity: 1;
}

.auth-modal-overlay.hidden {
    display: none;
}

.auth-modal-content {
    background: var(--dark-card);
    border: 3px solid var(--yellow);
    border-radius: 12px;
    padding: 1rem;
    max-width: 480px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 8px 8px 0 rgba(224, 179, 60, 0.3),
        0 0 0 2px rgba(224, 179, 60, 0.1) inset,
        0 0 30px rgba(224, 179, 60, 0.15);
    transform: none;
    position: relative;
    animation: tomAuthModalFadeIn 0.3s ease-out;
    pointer-events: auto;
    z-index: 10001;
}

@keyframes tomAuthModalFadeIn {
    0% { transform: scale(0.95); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.auth-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--yellow);
    color: var(--dark-bg);
    border: 2px solid var(--yellow);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    transform: rotate(-15deg);
}

.auth-modal-close:hover {
    background: var(--yellow-bright);
    transform: rotate(90deg) scale(1.1);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
}

.auth-view { display: block; }
.auth-view.hidden { display: none; }

.auth-title {
    color: var(--yellow) !important;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.8rem;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.auth-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.auth-form-row { display: flex; gap: 0.6rem; }
.auth-form-row .auth-form-group { flex: 1; }

.auth-register-hint {
    background: rgba(224, 179, 60, 0.1);
    border: 2px solid var(--yellow);
    border-radius: 6px;
    padding: 0.6rem;
    margin-bottom: 0.6rem;
    color: var(--text-light);
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
    box-shadow: 2px 2px 0 rgba(224, 179, 60, 0.2);
}

.auth-input {
    background: var(--dark-bg);
    border: 2px solid var(--dark-border);
    color: var(--text-light);
    -webkit-text-fill-color: var(--text-light);
    caret-color: var(--text-light);
    color-scheme: dark;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    width: 100%;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.auth-input:focus {
    border-color: var(--yellow);
    box-shadow: 0 0 8px rgba(224, 179, 60, 0.1);
    transform: translateY(-1px);
}

.auth-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

#auth-modal-overlay input.auth-input:-webkit-autofill,
#auth-modal-overlay input.auth-input:-webkit-autofill:hover,
#auth-modal-overlay input.auth-input:-webkit-autofill:focus,
#auth-modal-overlay input.auth-input:-webkit-autofill:active,
#auth-modal-overlay input.auth-input:autofill,
#auth-modal-overlay input.auth-input:-moz-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--dark-bg) inset;
    box-shadow: 0 0 0 1000px var(--dark-bg) inset;
    background-color: var(--dark-bg);
    background: var(--dark-bg);
    -webkit-text-fill-color: var(--text-light);
    caret-color: var(--text-light);
    transition: background-color 5000s ease-in-out 0s;
}

/* 密码输入框 + 小眼睛 */
.auth-password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.auth-password-wrapper .auth-input {
    width: 100%;
    padding-right: 56px;
}

.auth-password-toggle-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.85;
    border-radius: 8px;
}

.auth-password-toggle-btn:hover {
    opacity: 1;
    border-color: var(--yellow);
    color: var(--yellow);
}

/* 验证码 */
.auth-captcha-wrapper { display: flex; gap: 0.4rem; align-items: center; }
.auth-captcha-wrapper-style { display: flex; gap: 0.5rem; align-items: center; }
.auth-captcha-input { flex: 1; }

.auth-captcha-img {
    width: 80px;
    height: 32px;
    background: var(--dark-bg);
    border: 2px solid var(--yellow);
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(224, 179, 60, 0.2);
    transition: all 0.3s ease;
    transform: rotate(2deg);
    object-fit: contain;
    object-position: center;
}

.auth-captcha-img-style {
    height: 38px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--yellow);
    flex: 0 0 auto;
    transform: none;
    width: 120px;
    display: block;
    object-fit: fill;
    object-position: center;
}

.auth-captcha-img:hover,
.auth-captcha-img-style:hover {
    transform: scale(1.05);
    box-shadow: 3px 3px 0 rgba(224, 179, 60, 0.3);
    border-color: var(--yellow-bright);
}

/* 提交按钮 */
.auth-submit-btn {
    background: var(--yellow) !important;
    color: var(--dark-bg) !important;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 700;
    border: 2px solid var(--yellow);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3),
        0 0 0 1px var(--yellow) inset;
    transform: rotate(-1deg);
    transition: all 0.3s ease;
    margin-top: 0.2rem;
}

.auth-submit-btn:hover {
    transform: rotate(0deg) translateY(-2px);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4),
        0 0 0 2px var(--yellow-bright) inset;
    background: var(--yellow-bright) !important;
}

.auth-submit-btn:active {
    transform: rotate(0deg) translateY(0);
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}

.auth-switch {
    text-align: center;
    margin-top: 0.5rem;
    color: var(--text-muted) !important;
    font-size: 12px;
}

.auth-switch-link {
    color: var(--yellow) !important;
    text-decoration: none;
    font-weight: 700;
    margin-left: 0.5rem;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
    display: inline-block;
}

.auth-switch-link:hover {
    color: var(--yellow-bright) !important;
    transform: translateY(-2px);
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.auth-error-message {
    color: #ff6b6b;
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
    word-break: break-word;
}

.auth-form-group label {
    color: var(--yellow);
    font-size: 0.9rem;
    font-weight: bold;
    margin-bottom: 0.3rem;
    display: block;
}

/* 登录进度条 */
.tom-auth-login-progress {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 2px solid rgba(224, 179, 60, 0.45);
    background: rgba(224, 179, 60, 0.08);
    display: none;
}

.tom-auth-login-progress.is-error {
    border-color: rgba(255, 107, 107, 0.7);
    background: rgba(255, 107, 107, 0.1);
}

.tom-auth-login-progress-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.4;
    margin-bottom: 8px;
}

.tom-auth-login-progress-text {
    color: #fff;
    font-weight: 700;
}

.tom-auth-login-progress-track {
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 999px;
    overflow: hidden;
}

.tom-auth-login-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ffe58f, var(--yellow, #E0B33C));
    border-radius: 999px;
    background-size: 180% 100%;
    position: relative;
    overflow: hidden;
    transition: width 360ms cubic-bezier(.22,.61,.36,1);
}

.tom-auth-login-progress.is-running .tom-auth-login-progress-bar {
    animation: tom-auth-login-progress-flow 1.1s linear infinite;
}

.tom-auth-login-progress.is-running .tom-auth-login-progress-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.45) 50%, transparent 100%);
    transform: translateX(-130%);
    animation: tom-auth-login-progress-glow 1.1s linear infinite;
}

.tom-auth-login-progress.is-error .tom-auth-login-progress-bar {
    background: linear-gradient(90deg, #ffd6d6, #ff6b6b);
}

@keyframes tom-auth-login-progress-flow {
    from { background-position: 0% 50%; }
    to { background-position: 100% 50%; }
}

@keyframes tom-auth-login-progress-glow {
    from { transform: translateX(-130%); }
    to { transform: translateX(230%); }
}

.tom-auth-login-progress-error {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.5;
    color: #ffd6d6;
    word-break: break-word;
}

/* 已登录：用户名下拉菜单 */
.user-menu-container {
    position: relative;
    display: inline-block;
}

.username-text { cursor: pointer; font-weight: bold; }

.user-dropdown-menu {
    display: none;
    position: absolute;
    background-color: var(--dark-card, #1a1a1a);
    min-width: 160px;
    box-shadow: 4px 4px 0 rgba(224, 179, 60, 0.3);
    z-index: 1000;
    border: 2px solid var(--yellow, #E0B33C);
    border-radius: 8px;
    overflow: hidden;
    padding: 8px 0;
    margin-top: 10px;
    right: 0;
}

.user-dropdown-menu a {
    color: var(--text-light, #f5f5f5);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
    transition: all 0.2s ease;
    font-weight: bold;
}

.user-dropdown-menu a:hover {
    background-color: var(--yellow, #E0B33C);
    color: var(--dark-bg, #0a0a0a);
}

.user-menu-container .user-dropdown-menu.show {
    display: block !important;
}

/* 账户类型标签 */
.user-role-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    vertical-align: middle;
    transition: all 0.2s ease;
    margin-right: 8px;
}

.user-role-badge.role-badge-superadmin {
    background-color: #f56c6c;
    color: #ffffff;
    border: 1px solid #f56c6c;
}

.user-role-badge.role-badge-admin {
    background-color: #f56c6c;
    color: #ffffff;
    border: 1px solid #f56c6c;
}

.user-role-badge.role-badge-pro {
    background-color: #e6a23c;
    color: #ffffff;
    border: 1px solid #e6a23c;
    position: relative;
    padding-right: 24px;
}

.user-role-badge.role-badge-pro::after {
    content: '👑';
    position: absolute;
    top: -7px;
    right: -7px;
    font-size: 18px;
    transform: rotate(35deg);
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

.user-role-badge.role-badge-normal {
    background-color: #409eff;
    color: #ffffff;
    border: 1px solid #409eff;
}

.user-role-badge.role-badge-guest {
    background-color: #909399;
    color: #ffffff;
    border: 1px solid #909399;
}

/* 通用确认 / 资料弹窗 */
.d-none { display: none !important; }

.preview-confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 11000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.preview-confirm-overlay:not(.d-none) {
    opacity: 1;
    pointer-events: auto;
}

.preview-confirm-dialog {
    background: var(--dark-card);
    border: 3px solid var(--yellow);
    border-radius: 12px;
    padding: 1.5rem;
    width: var(--width, 90%);
    max-width: var(--max-width, 400px);
    box-shadow: 8px 8px 0 rgba(224, 179, 60, 0.3),
        0 0 0 2px rgba(224, 179, 60, 0.1) inset;
    animation: tomAuthModalFadeIn 0.3s ease-out;
    position: relative;
}

.preview-confirm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px dashed rgba(224, 179, 60, 0.3);
    padding-bottom: 0.8rem;
}

.preview-confirm-title {
    color: var(--yellow);
    font-size: 1.25rem;
    font-weight: 700;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.preview-confirm-body {
    margin-bottom: 1.5rem;
    color: var(--text-light);
    font-size: 1rem;
    line-height: 1.6;
}

.preview-confirm-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.preview-confirm-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.preview-confirm-btn-cancel {
    background: transparent;
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.preview-confirm-btn-cancel:hover {
    border-color: var(--text-light);
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
}

.preview-confirm-btn-ok {
    background: var(--yellow);
    color: var(--dark-bg);
    border-color: var(--yellow);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

.preview-confirm-btn-ok:hover {
    background: var(--yellow-bright);
    border-color: var(--yellow-bright);
    transform: translateY(-2px);
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.4);
}
