/* ================================================================
   表單驗證視覺回饋 FormValidator
   - 不只靠顏色（搭配圖示與訊息，色盲友善）
   - WCAG 2.1 對比度達標
   - 訊息使用 role="alert" + aria-live
   ================================================================ */

:root {
    --fv-valid:        #2e8b57;   /* 綠 */
    --fv-valid-bg:     #f0faf4;
    --fv-invalid:      #d9534f;   /* 紅 */
    --fv-invalid-bg:   #fff5f4;
    --fv-focus:        #365a9e;
    --fv-disabled-bg:  #f4f4f4;
    --fv-disabled-fg:  #aaa;
}

/* ---------- 輸入框狀態 ---------- */

input.fv-valid,
textarea.fv-valid,
select.fv-valid {
    border-color: var(--fv-valid) !important;
    background-color: var(--fv-valid-bg);
    /* 右側勾號，用 SVG inline 不依賴 icon font */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232e8b57' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='5 12 10 17 19 7'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px 18px;
    padding-right: 38px !important;
    /* 勾號彈入動畫：背景圖由小放大到正常尺寸 */
    animation: fv-check-in .35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

input.fv-invalid,
textarea.fv-invalid,
select.fv-invalid {
    border-color: var(--fv-invalid) !important;
    background-color: var(--fv-invalid-bg);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d9534f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><line x1='12' y1='8' x2='12' y2='13'/><line x1='12' y1='17' x2='12.01' y2='17'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px 18px;
    padding-right: 38px !important;
    /* 錯誤時欄位輕微抖動，提示使用者注意 */
    animation: fv-shake .32s ease-in-out;
}

@keyframes fv-check-in {
    0%   { background-size: 0 0; }
    60%  { background-size: 22px 22px; }
    100% { background-size: 18px 18px; }
}

@keyframes fv-shake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-5px); }
    40%      { transform: translateX(4px); }
    60%      { transform: translateX(-3px); }
    80%      { transform: translateX(2px); }
}

/* textarea 圖示靠上 + 留多一些 padding */
textarea.fv-valid,
textarea.fv-invalid {
    background-position: right 12px top 12px;
}

input:disabled,
textarea:disabled {
    background-color: var(--fv-disabled-bg) !important;
    color: var(--fv-disabled-fg) !important;
    cursor: not-allowed;
}

/* ---------- 錯誤/成功訊息 ---------- */

.fv-msg {
    font-size: 13px;
    line-height: 1.5;
    margin-top: 6px;
    min-height: 0;
    transition: color .15s ease-out;
}
.fv-msg:empty {
    margin-top: 0;
}
.fv-msg.is-error {
    color: var(--fv-invalid);
}
.fv-msg.is-success {
    color: var(--fv-valid);
}
.fv-msg__icon {
    display: inline-block;
    margin-right: 4px;
    font-weight: bold;
}

/* ---------- Label & 必填星號 ---------- */

.fv-label {
    display: block;
    font-size: 14px;
    color: #333;
    font-weight: 500;
    margin-bottom: 6px;
}
.fv-required {
    color: var(--fv-invalid);
    margin-left: 2px;
}

/* ---------- 提交按鈕 loading ---------- */

button.fv-submitting {
    cursor: wait;
    opacity: 0.7;
    pointer-events: none;
}

/* ================================================================
   密碼強度條 PasswordHelper
   ================================================================ */

.pw-strength {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.pw-strength__bar {
    flex: 1;
    height: 6px;
    background-color: #eee;
    border-radius: 3px;
    overflow: hidden;
}
.pw-strength__fill {
    height: 100%;
    width: 0;
    background-color: #d9534f;
    transition: width .25s ease-out, background-color .15s;
    border-radius: 3px;
}
.pw-strength__fill[data-color="weak"]   { background-color: #d9534f; }
.pw-strength__fill[data-color="medium"] { background-color: #f0ad4e; }
.pw-strength__fill[data-color="strong"] { background-color: #2e8b57; }
.pw-strength__label {
    font-size: 13px;
    color: #666;
    min-width: 78px;
    text-align: right;
}

/* 條件清單 */
.pw-checks {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 4px 14px;
    font-size: 13px;
    color: #999;
}
.pw-checks li {
    position: relative;
    padding-left: 22px;
}
.pw-checks li::before {
    content: '✗';
    position: absolute;
    left: 4px;
    color: #ccc;
    font-weight: bold;
}
.pw-checks li.is-pass {
    color: var(--fv-valid);
}
.pw-checks li.is-pass::before {
    content: '✓';
    color: var(--fv-valid);
}

/* ---------- 密碼欄位 + 顯示/隱藏鈕容器 ---------- */
.pw-input-wrap {
    position: relative;
}
.pw-input-wrap input {
    padding-right: 44px !important;
}
.pw-toggle-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
    font-size: 18px;
    padding: 4px 8px;
    line-height: 1;
}
.pw-toggle-btn:hover { color: #333; }
.pw-toggle-btn:focus-visible { outline: 2px solid var(--fv-focus); outline-offset: 2px; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .fv-msg,
    .pw-strength__fill { transition: none; }
    input.fv-valid, textarea.fv-valid, select.fv-valid,
    input.fv-invalid, textarea.fv-invalid, select.fv-invalid {
        animation: none !important;
    }
}

/* ---------- 行動版微調 ---------- */
@media (max-width: 576px) {
    .pw-checks { grid-template-columns: 1fr 1fr; }
    .fv-msg { font-size: 12px; }
}
