/* ===========================
   xml-formatter - XML 格式化工具頁面
   =========================== */

/* 主要內容區塊，佔滿 wrapper 剩餘寬度 */
.xf-container {
    flex: 1;
    min-width: 0;
}

/* 頁面頂部英雄區塊 */
.xf-hero {
    text-align: center;
    padding: 10px 0 30px;
}

/* 英雄區塊主標題 */
.xf-hero-title {
    font-size: 2.25em;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 4px;
}

/* 英雄區塊副標題 (#64748b 對比度 4.51:1，符合 WCAG AA) */
.xf-hero-subtitle {
    font-size: 1.063em;
    color: #64748b;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0 0 16px;
}

/* 工具卡片 */
.xf-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.03);
    transition: box-shadow 0.2s ease;
}

/* 卡片滑鼠懸停時加深陰影 */
.xf-card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.06), 0 10px 24px rgba(0, 0, 0, 0.06);
}

/* 卡片內容區域 */
.xf-card-body {
    padding: 24px;
}

/* 表單欄位群組 */
.xf-form-group {
    margin-bottom: 16px;
}

/* 表單標籤 */
.xf-label {
    display: block;
    font-size: 0.938em;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

/* 多行文字輸入框外層包裹 */
.xf-textarea-wrap {
    position: relative;
}

/* 多行文字輸入框 (邊框 #8b95a5 對比度 3.05:1，符合 UI 元件門檻) */
.xf-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #8b95a5;
    border-radius: 8px;
    font-size: 1em;
    color: #1e293b;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    box-sizing: border-box;
    resize: vertical;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    line-height: 1.6;
}

/* 輸入框聚焦時的藍色邊框 */
.xf-textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* 輸入框下方提示文字 (#64748b 對比度 4.51:1，符合 WCAG AA) */
.xf-hint {
    display: block;
    margin-top: 5px;
    font-size: 0.813em;
    color: #64748b;
}

/* 縮排選項外層容器 */
.xf-indent-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

/* 縮排選項標籤文字 */
.xf-indent-label {
    font-size: 0.938em;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

/* 縮排選項按鈕群組 */
.xf-indent-options {
    display: flex;
    gap: 0;
}

/* 隱藏原生 radio 按鈕，僅保留視覺樣式 */
.xf-indent-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* 縮排選項按鈕外觀 (邊框 #8b95a5 對比度 3.05:1，符合 UI 元件門檻) */
.xf-indent-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    font-size: 0.875em;
    font-weight: 500;
    color: #475569;
    background: #fff;
    border: 1px solid #8b95a5;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 36px;
}

/* 第一個選項左側圓角 */
.xf-indent-option:first-child .xf-indent-btn {
    border-radius: 8px 0 0 8px;
}

/* 最後一個選項右側圓角 */
.xf-indent-option:last-child .xf-indent-btn {
    border-radius: 0 8px 8px 0;
    border-left: none;
}

/* 選項懸停效果 */
.xf-indent-btn:hover {
    background: #f1f5f9;
}

/* 選中狀態 (#2563eb 白字對比度 5.18:1，符合 WCAG AA) */
.xf-indent-option input[type="radio"]:checked + .xf-indent-btn {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

/* 選中狀態右側相鄰按鈕不需重複左邊框 */
.xf-indent-option input[type="radio"]:checked + .xf-indent-btn + input[type="radio"] + .xf-indent-btn {
    border-left: none;
}

/* 縮排選項鍵盤聚焦指示 */
.xf-indent-option input[type="radio"]:focus-visible + .xf-indent-btn {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
    z-index: 1;
    position: relative;
}

/* 操作按鈕群組 */
.xf-btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* 按鈕基礎樣式 */
.xf-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

/* 按鈕點擊時的按壓效果 */
.xf-btn:active {
    transform: scale(0.98);
}

/* 藍色按鈕 - 格式化 (#2563eb 白字對比度 5.18:1，符合 WCAG AA) */
.xf-btn--blue {
    background: #2563eb;
}
.xf-btn--blue:hover {
    background: #1d4ed8;
}

/* 橙色按鈕 - 壓縮 (#c2410c 白字對比度 5.02:1，符合 WCAG AA) */
.xf-btn--orange {
    background: #c2410c;
}
.xf-btn--orange:hover {
    background: #9a3412;
}

/* 綠色按鈕 - 複製 (#15803d 白字對比度 5.09:1，符合 WCAG AA) */
.xf-btn--green {
    background: #15803d;
}
.xf-btn--green:hover {
    background: #166534;
}

/* 灰色按鈕 - 清除 (#475569 白字對比度 7.28:1，符合 WCAG AAA) */
.xf-btn--gray {
    background: #475569;
}
.xf-btn--gray:hover {
    background: #334155;
}

/* 小螢幕時按鈕改為兩行排列 */
@media (max-width: 576px) {
    .xf-btn-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

/* 結果容器 */
.xf-result {
    margin-top: 8px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    overflow: hidden;
}

/* 結果區標題列 */
.xf-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #334155;
    background: #0f172a;
}

/* 結果標籤 (#94a3b8 在深色背景 #0f172a 上對比度 5.68:1，符合 WCAG AA) */
.xf-result-label {
    font-size: 0.813em;
    font-weight: 600;
    color: #94a3b8;
}

/* 結果內容區域 */
.xf-result-body {
    padding: 16px;
    overflow-x: auto;
}

/* 結果文字（使用等寬字型方便閱讀 XML） */
.xf-result-text {
    margin: 0;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.875em;
    color: #e2e8f0;
    line-height: 1.7;
    white-space: pre;
    word-break: normal;
    tab-size: 4;
}

/* 結果錯誤訊息 */
.xf-result-error {
    color: #f87171;
    font-family: inherit;
    font-size: 1em;
}

/* ===========================
   語法高亮色彩定義
   所有顏色在深色背景 #1e293b 上的對比度皆符合 WCAG AA
   =========================== */

/* 標籤名稱 - 藍色 (#60a5fa 對比度 6.45:1) */
.xf-hl-tag {
    color: #60a5fa;
}

/* 屬性名稱 - 橙色 (#fb923c 對比度 5.63:1) */
.xf-hl-attr {
    color: #fb923c;
}

/* 屬性值 - 綠色 (#4ade80 對比度 8.19:1) */
.xf-hl-value {
    color: #4ade80;
}

/* 角括號與斜線 - 灰色 (#94a3b8 對比度 5.49:1) */
.xf-hl-bracket {
    color: #94a3b8;
}

/* 註解 - 淺灰色 (#64748b 對比度 3.01:1，非關鍵文字可接受) */
.xf-hl-comment {
    color: #64748b;
    font-style: italic;
}

/* CDATA 區段 - 靛色 (#a5b4fc 對比度 7.19:1) */
.xf-hl-cdata {
    color: #a5b4fc;
}

/* XML 宣告與處理指令 - 洋紅色 (#f0abfc 對比度 8.04:1) */
.xf-hl-prolog {
    color: #f0abfc;
}

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

/* 按鈕鍵盤聚焦指示 (WCAG 2.4.7 Focus Visible) */
.xf-btn:focus-visible {
    outline: 2px solid #1e293b;
    outline-offset: 2px;
}

/* 多行輸入框鍵盤聚焦指示 */
.xf-textarea:focus-visible {
    outline: none;
}

/* 尊重使用者減少動態效果的偏好設定 (WCAG 2.3.3 Animation from Interactions) */
@media (prefers-reduced-motion: reduce) {
    .xf-card,
    .xf-btn,
    .xf-textarea,
    .xf-indent-btn {
        transition: none;
    }
}

/* Windows 高對比模式支援，確保邊框與聚焦指示在強制色彩下仍可見 */
@media (forced-colors: active) {
    /* 輸入框邊框改用系統邊框色 */
    .xf-textarea {
        border-color: ButtonText;
    }

    /* 聚焦時使用系統高亮色 */
    .xf-textarea:focus {
        border-color: Highlight;
        box-shadow: none;
    }

    /* 按鈕在高對比模式下保持可見邊框 */
    .xf-btn {
        border: 2px solid ButtonText;
    }

    .xf-btn:focus-visible {
        outline-color: Highlight;
    }

    /* 卡片邊框確保在高對比模式下可見 */
    .xf-card {
        border-color: CanvasText;
    }

    /* 結果區域邊框在高對比模式下可見 */
    .xf-result {
        border-color: CanvasText;
    }

    /* 縮排選項按鈕在高對比模式下保持可見邊框 */
    .xf-indent-btn {
        border-color: ButtonText;
    }

    /* 縮排選項選中狀態在高對比模式下使用系統高亮色 */
    .xf-indent-option input[type="radio"]:checked + .xf-indent-btn {
        background: Highlight;
        color: HighlightText;
        border-color: Highlight;
    }

    /* 語法高亮在高對比模式下使用系統色 */
    .xf-hl-tag,
    .xf-hl-attr,
    .xf-hl-value,
    .xf-hl-bracket,
    .xf-hl-comment,
    .xf-hl-cdata,
    .xf-hl-prolog {
        color: CanvasText;
    }
}
