/* ==========================================================
   calc-currency-exchange — 实时汇率换算
   颜色跟随网站主题变量（带多级回退），支持暗色主题，容器自适应
   ========================================================== */

.calc-currency-exchange-container {
    --ce-primary: var(--primary, var(--success, #10b981));
    --ce-primary-hover: var(--primary-hover, #059669);
    --ce-primary-light: var(--primary-light, #d1fae5);
    --ce-primary-bg: var(--primary-bg, #ecfdf5);
    --ce-text: var(--text, #1f2937);
    --ce-text-sub: var(--text-secondary, #6b7280);
    --ce-text-mute: var(--text-muted, #9ca3af);
    --ce-border: var(--border, #e5e7eb);
    --ce-bg: var(--bg, #ffffff);
    --ce-bg-sub: var(--bg-secondary, #f9fafb);
    --ce-radius: var(--radius, 12px);
    --ce-radius-sm: var(--radius-sm, 8px);
    --ce-radius-lg: var(--radius-lg, 16px);

    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    color: var(--ce-text);
    font-size: 14px;
    line-height: 1.6;
    overflow-wrap: break-word;
    word-break: break-word;
}

.calc-currency-exchange-container *,
.calc-currency-exchange-container *::before,
.calc-currency-exchange-container *::after {
    box-sizing: border-box;
}

.calc-currency-exchange-shell {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    min-width: 0;
}

/* ---------- 状态条 ---------- */
.calc-currency-exchange-status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 12px;
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    background: var(--ce-bg-sub);
    font-size: 12px;
    color: var(--ce-text-sub);
}

.calc-currency-exchange-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--ce-text-mute);
}
.calc-currency-exchange-dot.is-live { background: var(--success, #10b981); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.calc-currency-exchange-dot.is-offline { background: var(--warning, #f59e0b); box-shadow: 0 0 0 3px rgba(245,158,11,.18); }
.calc-currency-exchange-dot.is-cache { background: var(--info, #3b82f6); box-shadow: 0 0 0 3px rgba(59,130,246,.18); }
.calc-currency-exchange-dot.is-loading { background: var(--info, #3b82f6); animation: ce-pulse 1s ease-in-out infinite; }
.calc-currency-exchange-dot.calc-currency-exchange-is-idle,
.calc-currency-exchange-dot.is-idle { background: var(--ce-text-mute); }

@keyframes ce-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

.calc-currency-exchange-status-text { font-weight: 600; color: var(--ce-text); }

.calc-currency-exchange-updated {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.calc-currency-exchange-refresh {
    flex: 0 0 auto;
    border: 1px solid var(--ce-border);
    background: var(--ce-bg);
    color: var(--ce-text-sub);
    border-radius: var(--ce-radius-sm);
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}
.calc-currency-exchange-refresh:hover:not(:disabled) {
    color: var(--ce-primary);
    border-color: var(--ce-primary);
}
.calc-currency-exchange-refresh:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 卡片 ---------- */
.calc-currency-exchange-card {
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius-lg);
    background: var(--ce-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.calc-currency-exchange-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ce-text-sub);
    letter-spacing: .02em;
}

.calc-currency-exchange-io {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.calc-currency-exchange-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.calc-currency-exchange-input {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ce-text);
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.calc-currency-exchange-input:focus {
    border-color: var(--ce-primary);
    box-shadow: 0 0 0 3px var(--ce-primary-light);
}
.calc-currency-exchange-input::placeholder { font-size: 14px; font-weight: 400; color: var(--ce-text-mute); }

/* ---------- 币种选择行 ---------- */
.calc-currency-exchange-pair {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: nowrap;
    min-width: 0;
}

.calc-currency-exchange-selwrap {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calc-currency-exchange-select {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--ce-text);
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    outline: none;
    cursor: pointer;
    text-overflow: ellipsis;
}
.calc-currency-exchange-select:focus {
    border-color: var(--ce-primary);
    box-shadow: 0 0 0 3px var(--ce-primary-light);
}

.calc-currency-exchange-swap {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    font-size: 18px;
    line-height: 1;
    color: var(--ce-primary);
    background: var(--ce-primary-bg);
    border: 1px solid var(--ce-primary-light);
    border-radius: 50%;
    cursor: pointer;
    transition: transform .2s, background .15s;
}
.calc-currency-exchange-swap:hover { background: var(--ce-primary-light); transform: rotate(180deg); }

/* ---------- 操作按钮 ---------- */
.calc-currency-exchange-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.calc-currency-exchange-btn {
    flex: 1 1 auto;
    min-width: 84px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--ce-text);
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    cursor: pointer;
    transition: all .15s;
}
.calc-currency-exchange-btn:hover { border-color: var(--ce-primary); color: var(--ce-primary); }
.calc-currency-exchange-btn.calc-currency-exchange-is-primary,
.calc-currency-exchange-btn.is-primary {
    color: #fff;
    background: var(--ce-primary);
    border-color: var(--ce-primary);
}
.calc-currency-exchange-btn.calc-currency-exchange-is-primary:hover,
.calc-currency-exchange-btn.is-primary:hover {
    background: var(--ce-primary-hover);
    border-color: var(--ce-primary-hover);
    color: #fff;
}
.calc-currency-exchange-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- 结果区 ---------- */
.calc-currency-exchange-result {
    border: 1px solid var(--ce-border);
    border-left: 4px solid var(--ce-primary);
    border-radius: var(--ce-radius-lg);
    background: var(--ce-primary-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.calc-currency-exchange-result-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.calc-currency-exchange-result-value {
    font-size: clamp(24px, 6vw, 34px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--ce-text);
    letter-spacing: -.01em;
    overflow-wrap: anywhere;
}

.calc-currency-exchange-rate {
    font-size: 13px;
    color: var(--ce-text-sub);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}
.calc-currency-exchange-rate.calc-currency-exchange-is-rev,
.calc-currency-exchange-rate.is-rev { color: var(--ce-text-mute); }

.calc-currency-exchange-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
    font-size: 12px;
    color: var(--ce-text-mute);
}
.calc-currency-exchange-src { overflow-wrap: anywhere; }

.calc-currency-exchange-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.calc-currency-exchange-badge.is-api { color: var(--ce-primary-hover); background: var(--ce-primary-light); }
.calc-currency-exchange-badge.is-local { color: var(--warning-text, #b45309); background: var(--warning-bg, #fef3c7); }
.calc-currency-exchange-badge.is-cache { color: var(--info-text, #1d4ed8); background: var(--info-bg, #dbeafe); }

.calc-currency-exchange-mini {
    flex: 0 0 auto;
    padding: 3px 10px;
    font-size: 12px;
    color: var(--ce-text-sub);
    background: var(--ce-bg);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius-sm);
    cursor: pointer;
    transition: all .15s;
}
.calc-currency-exchange-mini:hover { color: var(--ce-primary); border-color: var(--ce-primary); }

/* ---------- 区块 ---------- */
.calc-currency-exchange-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.calc-currency-exchange-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.calc-currency-exchange-chip {
    padding: 5px 12px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--ce-text-sub);
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    border-radius: 999px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.calc-currency-exchange-chip:hover {
    color: var(--ce-primary-hover);
    background: var(--ce-primary-bg);
    border-color: var(--ce-primary);
}
.calc-currency-exchange-chip.is-pair { font-weight: 600; }

/* ---------- 对照网格 ---------- */
.calc-currency-exchange-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 8px;
}

.calc-currency-exchange-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    text-align: left;
    background: var(--ce-bg);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    cursor: pointer;
    transition: all .15s;
    min-width: 0;
}
.calc-currency-exchange-cell:hover {
    border-color: var(--ce-primary);
    background: var(--ce-primary-bg);
}
.calc-currency-exchange-cell.is-active {
    border-color: var(--ce-primary);
    background: var(--ce-primary-bg);
    box-shadow: 0 0 0 2px var(--ce-primary-light);
}

.calc-currency-exchange-cell-code {
    font-size: 11px;
    font-weight: 700;
    color: var(--ce-text-mute);
    letter-spacing: .04em;
}
.calc-currency-exchange-cell-name {
    font-size: 11px;
    color: var(--ce-text-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.calc-currency-exchange-cell-val {
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ce-text);
    overflow-wrap: anywhere;
}

.calc-currency-exchange-hint { font-size: 12px; color: var(--ce-text-mute); }

/* ---------- 汇率表 ---------- */
.calc-currency-exchange-table-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.calc-currency-exchange-search {
    flex: 1 1 140px;
    min-width: 0;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--ce-text);
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius-sm);
    outline: none;
}
.calc-currency-exchange-search:focus { border-color: var(--ce-primary); }

.calc-currency-exchange-table {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--ce-border);
    border-radius: var(--ce-radius);
    overflow: hidden;
    max-height: 340px;
    overflow-y: auto;
}

.calc-currency-exchange-tr {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 8px 12px;
    align-items: center;
    border-bottom: 1px solid var(--ce-border);
    font-size: 13px;
    cursor: pointer;
    min-width: 0;
}
.calc-currency-exchange-tr:last-child { border-bottom: none; }
.calc-currency-exchange-tr:hover { background: var(--ce-primary-bg); }
.calc-currency-exchange-tr.is-head {
    background: var(--ce-bg-sub);
    font-size: 11px;
    font-weight: 700;
    color: var(--ce-text-sub);
    cursor: default;
    position: sticky;
    top: 0;
    z-index: 1;
}
.calc-currency-exchange-tr.is-head:hover { background: var(--ce-bg-sub); }

.calc-currency-exchange-td {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.calc-currency-exchange-td.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
    justify-content: center;
    overflow-wrap: anywhere;
}
.calc-currency-exchange-td-code { font-weight: 700; }
.calc-currency-exchange-td-name {
    font-size: 11px;
    color: var(--ce-text-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-currency-exchange-empty {
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--ce-text-mute);
}

/* ---------- 消息 ---------- */
.calc-currency-exchange-message {
    padding: 10px 14px;
    border-radius: var(--ce-radius);
    font-size: 13px;
    background: var(--ce-bg-sub);
    border: 1px solid var(--ce-border);
    color: var(--ce-text-sub);
    overflow-wrap: anywhere;
}
.calc-currency-exchange-message.is-error {
    color: var(--danger, #b91c1c);
    background: var(--danger-bg, #fef2f2);
    border-color: var(--danger-border, #fecaca);
}
.calc-currency-exchange-message.is-success {
    color: var(--ce-primary-hover);
    background: var(--ce-primary-bg);
    border-color: var(--ce-primary-light);
}

.calc-currency-exchange-note {
    font-size: 12px;
    line-height: 1.7;
    color: var(--ce-text-mute);
    padding-top: 2px;
}

/* ---------- 暗色主题：跟随网站 ---------- */
@media (prefers-color-scheme: dark) {
    .calc-currency-exchange-container:not(.ce-force-light) {
        --ce-text: var(--text, #e5e7eb);
        --ce-text-sub: var(--text-secondary, #9ca3af);
        --ce-text-mute: var(--text-muted, #6b7280);
        --ce-border: var(--border, #374151);
        --ce-bg: var(--bg, #1f2937);
        --ce-bg-sub: var(--bg-secondary, #111827);
        --ce-primary-bg: rgba(16, 185, 129, .12);
        --ce-primary-light: rgba(16, 185, 129, .28);
    }
    .calc-currency-exchange-container:not(.ce-force-light) .calc-currency-exchange-badge.is-local {
        color: var(--warning-text-dark, #fbbf24);
        background: rgba(245, 158, 11, .16);
    }
    .calc-currency-exchange-container:not(.ce-force-light) .calc-currency-exchange-message.is-error {
        color: var(--danger-text-dark, #fca5a5);
        background: rgba(185, 28, 28, .14);
        border-color: rgba(185, 28, 28, .4);
    }
}

/* ---------- 窄容器 / 移动端 ---------- */
@media (max-width: 520px) {
    .calc-currency-exchange-card { padding: 12px; }
    .calc-currency-exchange-input { font-size: 20px; padding: 10px 12px; }
    .calc-currency-exchange-pair { flex-wrap: wrap; }
    .calc-currency-exchange-selwrap { flex: 1 1 100%; }
    .calc-currency-exchange-swap { align-self: center; margin: -6px 0; }
    .calc-currency-exchange-btn { min-width: 72px; padding: 9px 12px; font-size: 13px; }
    .calc-currency-exchange-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }
    .calc-currency-exchange-tr { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); font-size: 12px; }
    .calc-currency-exchange-updated { margin-left: 0; width: 100%; }
}

/* 收起必须真正生效：.calc-currency-exchange-table{display:flex} 属作者样式，
   会覆盖 UA 的 [hidden]{display:none}（作者样式优先于 UA 样式），
   导致 hidden 属性无效、表格无法收起。此处显式声明，并用 !important 兜底。 */
.calc-currency-exchange-table[hidden],
.calc-currency-exchange-table.is-collapsed { display: none !important; }
