/*
 * 前端問卷表單樣式
 * TAOT 品牌色彩設計
 * 主色：#566CA1 (藍)  輔色：#D9A270 (橘)
 */

/* ===== CSS 變數定義 ===== */
:root {
    /* TAOT 品牌色 */
    --survey-primary: #566CA1;
    --survey-primary-light: #6a82b8;
    --survey-primary-dark: #455a8a;
    --survey-accent: #D9A270;
    --survey-accent-light: #e4b58a;
    --survey-accent-dark: #c08a52;

    /* 中性色 */
    --survey-bg: #ffffff;
    --survey-bg-alt: #f8fafc;
    --survey-border: #e2e8f0;
    --survey-border-light: #f1f5f9;

    /* 文字色 */
    --survey-text: #1e293b;
    --survey-text-muted: #64748b;
    --survey-text-light: #94a3b8;

    /* 功能色 */
    --survey-success: #10b981;
    --survey-success-bg: #ecfdf5;
    --survey-error: #ef4444;
    --survey-error-bg: #fef2f2;

    /* 間距 */
    --survey-radius: 16px;
    --survey-radius-sm: 10px;
    --survey-radius-xs: 6px;

    /* 動畫 */
    --survey-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --survey-transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== 問卷區塊標題 ===== */
.hj-survey-section {
    margin-top: 48px;
    padding-top: 48px;
    border-top: 1px solid var(--survey-border);
}

.hj-survey-section-header {
    text-align: center;
    margin-bottom: 32px;
}

.hj-survey-section-header h3 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--survey-text);
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 12px 0;
}

.hj-survey-section-header h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 24px;
    background: linear-gradient(180deg, var(--survey-primary) 0%, var(--survey-accent) 100%);
    border-radius: 2px;
}

.hj-survey-section-header p {
    color: var(--survey-text-muted);
    font-size: 15px;
    line-height: 1.6;
    max-width: 480px;
    margin: 0 auto;
}

/* ===== 問卷主容器 ===== */
.hj-survey-container {
    max-width: 720px;
    margin: 24px auto;
    background: var(--survey-bg);
    border-radius: var(--survey-radius);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 6px 16px rgba(0, 0, 0, 0.06);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    border: 1px solid var(--survey-border-light);
    /* 不使用 overflow:hidden，改用子元素處理圓角 */
}

/* ===== 問卷標題區域 ===== */
.hj-survey-header {
    background: linear-gradient(135deg, var(--survey-primary) 0%, var(--survey-primary-light) 100%);
    color: white;
    padding: 40px 32px;
    text-align: center;
    position: relative;
    overflow: hidden;
    /* 頂部圓角對齊容器 */
    border-radius: var(--survey-radius) var(--survey-radius) 0 0;
    margin: -1px -1px 0 -1px;
    /* 修復邊框重疊 */
}

/* 裝飾圓形背景 */
.hj-survey-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}

.hj-survey-header::after {
    content: '';
    position: absolute;
    bottom: -60%;
    left: -10%;
    width: 250px;
    height: 250px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 50%;
}

.survey-title {
    margin: 0 0 12px 0;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.3;
    position: relative;
    z-index: 1;
    letter-spacing: -0.02em;
}

.survey-description {
    font-size: 15px;
    line-height: 1.7;
    opacity: 0.92;
    position: relative;
    z-index: 1;
    max-width: 500px;
    margin: 0 auto;
}

/* ===== 表單主體 ===== */
.hj-survey-form {
    padding: 28px 24px 32px 24px;
    background: var(--survey-bg);
}

/* ===== 問題區塊 ===== */
.survey-question {
    margin-bottom: 20px;
    padding: 24px;
    background: var(--survey-bg-alt);
    border-radius: 12px;
    border: 1px solid var(--survey-border);
    transition:
        border-color var(--survey-transition),
        box-shadow var(--survey-transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* 重置 fieldset 預設樣式 */
fieldset.survey-question {
    margin: 0 0 20px 0;
    min-width: 0;
}

.survey-question:last-child {
    margin-bottom: 16px;
}

.survey-question:hover {
    border-color: var(--survey-border);
}

.survey-question:focus-within {
    border-color: var(--survey-primary);
    box-shadow: 0 0 0 3px rgba(86, 108, 161, 0.12);
}

/* ===== 問題標題區 ===== */
.question-header {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
}

.question-title {
    flex: 1;
    margin: 0;
    padding: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--survey-text);
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    float: none;
    width: auto;
}

/* 重置 legend 預設樣式 */
legend.question-title {
    padding: 0;
    border: 0;
    display: contents;
}

.question-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    background: var(--survey-primary);
    color: white;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.required-mark {
    color: var(--survey-error);
    font-weight: 700;
    font-size: 16px;
    margin-left: 2px;
}

.question-type-indicator {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    color: var(--survey-primary);
    background: rgba(86, 108, 161, 0.1);
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ===== 選項區域 ===== */
.question-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 14px 18px;
    background: var(--survey-bg);
    border: 2px solid var(--survey-border);
    border-radius: var(--survey-radius-xs);
    transition:
        border-color var(--survey-transition),
        background-color var(--survey-transition),
        box-shadow var(--survey-transition);
    position: relative;
}

.option-label:hover {
    border-color: var(--survey-primary-light);
    background: rgba(86, 108, 161, 0.03);
}

.option-label:focus-within {
    border-color: var(--survey-primary);
    box-shadow: 0 0 0 3px rgba(86, 108, 161, 0.15);
    outline: none;
}

/* 隱藏原生輸入框 */
.option-label input[type="radio"],
.option-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* ===== 自定義選項按鈕 ===== */
.radio-custom,
.checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--survey-border);
    margin-right: 14px;
    position: relative;
    transition:
        border-color var(--survey-transition),
        background-color var(--survey-transition),
        transform var(--survey-transition);
    flex-shrink: 0;
    background: var(--survey-bg);
}

.radio-custom {
    border-radius: 50%;
}

.checkbox-custom {
    border-radius: 4px;
}

.option-label:hover .radio-custom,
.option-label:hover .checkbox-custom {
    border-color: var(--survey-primary-light);
}

/* ===== 選中狀態 ===== */
.option-label input:checked + .radio-custom,
.option-label input:checked + .checkbox-custom {
    border-color: var(--survey-primary);
    background: var(--survey-primary);
}

.option-label input:checked + .radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    animation: scaleIn var(--survey-transition);
}

.option-label input:checked + .checkbox-custom::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 6px;
    width: 5px;
    height: 9px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
    animation: checkIn var(--survey-transition);
}

/* 選中時的選項卡片樣式 */
.option-label:has(input:checked) {
    border-color: var(--survey-primary);
    background: rgba(86, 108, 161, 0.05);
}

@keyframes scaleIn {
    from { transform: translate(-50%, -50%) scale(0); }
    to { transform: translate(-50%, -50%) scale(1); }
}

@keyframes checkIn {
    from {
        opacity: 0;
        transform: rotate(45deg) scale(0);
    }
    to {
        opacity: 1;
        transform: rotate(45deg) scale(1);
    }
}

.option-text {
    flex: 1;
    line-height: 1.5;
    color: var(--survey-text);
    font-size: 15px;
    font-weight: 450;
}

/* ===== 錯誤提示 ===== */
.question-error {
    margin-top: 14px;
    padding: 12px 16px;
    background: var(--survey-error-bg);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--survey-radius-xs);
    border-left: 3px solid var(--survey-error);
}

.error-message {
    color: var(--survey-error);
    font-size: 14px;
    font-weight: 500;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-message::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background: var(--survey-error);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor'%3E%3Cpath fill-rule='evenodd' d='M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    flex-shrink: 0;
}

/* ===== 提交區域 ===== */
.survey-actions {
    text-align: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--survey-border-light);
}

.survey-submit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--survey-accent) 0%, var(--survey-accent-dark) 100%);
    color: white;
    border: none;
    padding: 14px 40px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform var(--survey-transition),
        box-shadow var(--survey-transition),
        opacity var(--survey-transition);
    min-width: 180px;
    box-shadow: 0 4px 14px rgba(217, 162, 112, 0.35);
}

.survey-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(217, 162, 112, 0.45);
}

.survey-submit-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(217, 162, 112, 0.3);
}

.survey-submit-btn:focus-visible {
    outline: none;
    box-shadow:
        0 4px 14px rgba(217, 162, 112, 0.35),
        0 0 0 3px rgba(217, 162, 112, 0.3);
}

.survey-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(217, 162, 112, 0.2);
}

.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-text::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    background: white;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z' clip-rule='evenodd'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn-loading::after {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 成功訊息 ===== */
.survey-success-message {
    padding: 56px 32px;
    text-align: center;
    background: var(--survey-success-bg);
}

.success-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--survey-success) 0%, #059669 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin: 0 auto 20px;
    animation: successBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
}

@keyframes successBounce {
    0% { transform: scale(0); }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.survey-success-message h4 {
    margin: 0 0 10px 0;
    color: var(--survey-text);
    font-size: 22px;
    font-weight: 700;
}

.survey-success-message p {
    margin: 0;
    color: var(--survey-text-muted);
    line-height: 1.6;
    font-size: 15px;
    max-width: 400px;
    margin: 0 auto;
}

/* ===== 響應式設計 ===== */
@media (max-width: 768px) {
    .hj-survey-section {
        margin-top: 32px;
        padding-top: 32px;
    }

    .hj-survey-section-header h3 {
        font-size: 18px;
    }

    .hj-survey-container {
        margin: 16px;
        border-radius: 12px;
    }

    .hj-survey-header {
        padding: 28px 20px;
        border-radius: 12px 12px 0 0;
    }

    .survey-title {
        font-size: 20px;
    }

    .survey-description {
        font-size: 14px;
    }

    .hj-survey-form {
        padding: 16px;
    }

    .survey-question {
        padding: 16px;
        margin-bottom: 16px;
        border-radius: 10px;
    }

    .question-header {
        flex-direction: column;
        gap: 10px;
    }

    .question-title {
        font-size: 16px;
    }

    .question-number {
        min-width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .option-label {
        padding: 12px 14px;
    }

    .radio-custom,
    .checkbox-custom {
        width: 18px;
        height: 18px;
        margin-right: 12px;
    }

    .option-text {
        font-size: 14px;
    }

    .survey-submit-btn {
        width: 100%;
        padding: 14px 24px;
        font-size: 15px;
    }

    .survey-success-message {
        padding: 40px 20px;
    }

    .success-icon {
        width: 56px;
        height: 56px;
        font-size: 26px;
    }

    .survey-success-message h4 {
        font-size: 18px;
    }
}

/* ===== 入場動畫 ===== */
.survey-question {
    animation: fadeSlideUp 0.4s ease-out backwards;
}

.survey-question:nth-child(1) { animation-delay: 0.05s; }
.survey-question:nth-child(2) { animation-delay: 0.1s; }
.survey-question:nth-child(3) { animation-delay: 0.15s; }
.survey-question:nth-child(4) { animation-delay: 0.2s; }
.survey-question:nth-child(5) { animation-delay: 0.25s; }

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 無障礙支援 ===== */

/* 高對比模式 */
@media (prefers-contrast: high) {
    .option-label {
        border-width: 3px;
    }

    .radio-custom,
    .checkbox-custom {
        border-width: 3px;
    }

    .survey-submit-btn {
        border: 2px solid var(--survey-accent-dark);
    }

    .question-error {
        border-width: 2px;
    }
}

/* 減少動畫模式 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 焦點可見性 */
.option-label:focus-visible,
.survey-submit-btn:focus-visible {
    outline: 2px solid var(--survey-primary);
    outline-offset: 2px;
}

/* ===== 打印樣式 ===== */
@media print {
    .hj-survey-container {
        box-shadow: none;
        border: 1px solid #ccc;
        margin: 0;
        border-radius: 0;
    }

    .hj-survey-header {
        background: #f0f0f0 !important;
        color: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .survey-actions {
        display: none;
    }

    .option-label {
        break-inside: avoid;
        margin-bottom: 6px;
        border-color: #ccc;
    }

    .survey-question {
        break-inside: avoid;
        margin-bottom: 16px;
        background: white;
    }

    .question-number {
        background: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
