/* ============================================================
   前端站点 AI 助手（悬浮按钮 + 弹窗）
   跟随主题变量，兼容浅色/深色主题
   ============================================================ */

/* 悬浮按钮 */
.ai-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 70px;
    border-radius: 5%;
    border: none;
    cursor: pointer;
    z-index: 9990;
    background: linear-gradient(135deg, var(--theme-primary, #c9a96e), var(--theme-primary-dark, #a07828));
    color: #fff;
    font-size: 26px;
    line-height: 60px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    animation: ai-fab-breath 3s ease-in-out infinite;
}
.ai-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}
@keyframes ai-fab-breath {
    0%, 100% { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22); }
    50% { box-shadow: 0 8px 30px rgba(201, 169, 110, 0.55); }
}
.ai-fab .ai-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53e3e;
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 5px;
    border: 2px solid var(--theme-surface, #fff);
}
.ai-fab-logo {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 5%;
    object-fit: cover;
    background: #fff;
}

/* 弹窗容器 */
.ai-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 130px);
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #e6e6e6);
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
    z-index: 9991;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease;
}
.ai-panel.ai-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* 头部 */
.ai-header {
    background: linear-gradient(135deg, var(--theme-primary, #c9a96e), var(--theme-primary-dark, #a07828));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}
.ai-header .ai-avatar {
    width: 40px;
    height: 48px;
    border-radius: 5%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.ai-header .ai-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 5%;
    object-fit: cover;
    display: block;
}
.ai-header .ai-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}
.ai-header .ai-subtitle {
    font-size: 0.72rem;
    opacity: 0.9;
    margin-top: 2px;
}
.ai-header .ai-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    line-height: 28px;
    text-align: center;
}
.ai-header .ai-close:hover { background: rgba(255, 255, 255, 0.35); }

/* 工具区 */
.ai-tools {
    display: flex;
    gap: 8px;
    padding: 12px 14px 4px;
}
.ai-tool {
    flex: 1;
    background: var(--theme-background, #faf8f5);
    border: 1px solid var(--theme-border, #e6e6e6);
    border-radius: 12px;
    padding: 10px 6px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}
.ai-tool:hover {
    border-color: var(--theme-primary, #c9a96e);
    transform: translateY(-2px);
}
.ai-tool .ai-tool-icon { font-size: 20px; }
.ai-tool .ai-tool-label {
    display: block;
    font-size: 0.72rem;
    color: var(--theme-text, #333);
    margin-top: 4px;
    font-weight: 500;
}

/* 话题推荐 */
.ai-suggests {
    padding: 8px 14px 4px;
}
.ai-suggests-title {
    font-size: 0.74rem;
    color: var(--theme-text-secondary, #888);
    margin-bottom: 8px;
}
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ai-chip {
    background: rgba(201, 169, 110, 0.12);
    color: var(--theme-primary-dark, #8a6d3b);
    border: 1px solid rgba(201, 169, 110, 0.3);
    border-radius: 14px;
    padding: 6px 12px;
    font-size: 0.74rem;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-chip:hover {
    background: rgba(201, 169, 110, 0.22);
    transform: translateY(-1px);
}

/* 消息区 */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--theme-background, #faf8f5);
}
.ai-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
}
.ai-msg .ai-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 0.86rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.ai-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.ai-msg-user .ai-bubble {
    background: var(--theme-primary, #c9a96e);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg-bot {
    align-self: flex-start;
}
.ai-msg-bot .ai-bubble {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #e6e6e6);
    color: var(--theme-text, #333);
    border-bottom-left-radius: 4px;
}
.ai-msg-bot .ai-avatar-sm {
    width: 28px;
    height: 34px;
    border-radius: 5%;
    background: linear-gradient(135deg, var(--theme-primary, #c9a96e), var(--theme-primary-dark, #a07828));
    color: #fff;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
}
.ai-msg-bot .ai-avatar-sm img {
    width: 100%;
    height: 100%;
    border-radius: 5%;
    object-fit: cover;
    display: block;
}
.ai-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 1px;
    background: var(--theme-text-secondary, #aaa);
    border-radius: 50%;
    animation: ai-typing 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* 输入区 */
.ai-input-area {
    border-top: 1px solid var(--theme-border, #e6e6e6);
    padding: 10px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--theme-surface, #fff);
}
.ai-input {
    flex: 1;
    border: 1px solid var(--theme-border, #e6e6e6);
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 0.86rem;
    resize: none;
    outline: none;
    max-height: 96px;
    font-family: inherit;
    background: var(--theme-background, #faf8f5);
    color: var(--theme-text, #333);
    line-height: 1.4;
}
.ai-input:focus { border-color: var(--theme-primary, #c9a96e); }
.ai-send-btn, .ai-voice-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.ai-send-btn {
    background: var(--theme-primary, #c9a96e);
    color: #fff;
}
.ai-send-btn:hover { background: var(--theme-primary-dark, #a07828); }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-voice-btn {
    background: var(--theme-background, #f0ece6);
    color: var(--theme-primary-dark, #8a6d3b);
}
.ai-voice-btn.ai-recording {
    background: #e53e3e;
    color: #fff;
    animation: ai-fab-breath 1.2s ease-in-out infinite;
}
.ai-voice-btn.hidden { display: none; }

/* 成本计算器弹窗（自包含，不依赖 /jisuanqi） */
.ai-calc-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(40, 28, 16, 0.45);
    backdrop-filter: blur(2px);
    --card-bg: #ffffff;
    --primary: #c67a3d;
    --primary-dark: #a05e2a;
    --primary-light: #fef0e4;
    --text: #3e2c1c;
    --text-secondary: #6b5744;
    --text-light: #8a7562;
    --border: #e8d5c4;
    --success-bg: #f9f5ef;
    --shadow-lg: 0 8px 30px rgba(62, 44, 28, 0.18);
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 18px;
}
.ai-calc-modal.ai-open { display: flex; }
.ai-calc-modal-dialog {
    width: 100%;
    max-width: 880px;
    min-width: 320px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    animation: ai-calc-pop 0.25s ease-out;
}
@keyframes ai-calc-pop {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: none; }
}
.ai-calc-modal-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(135deg, #d4944a, #c67a3d);
    color: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.9rem;
    font-weight: 600;
}
.ai-calc-modal-close {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background 0.2s;
}
.ai-calc-modal-close:hover { background: rgba(255, 255, 255, 0.32); }

/* 左右分栏布局：填写内容在左，计算结果在右，左右均分 */
.ai-calc-modal .calc-layout {
    display: flex;
    gap: 20px;
    align-items: stretch;
}
.ai-calc-modal .calc-col {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.ai-calc-modal .calc-left .form-section { margin-bottom: 16px; }
.ai-calc-modal .calc-left .btn-row { margin-top: auto; }

/* 卡片内部（复用 jisuanqi 视觉，作用域限定在 .ai-calc-modal 内） */
.ai-calc-modal .main-card {
    background: var(--card-bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 22px 20px 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-top: none;
    position: relative;
    overflow-y: auto;
    max-height: calc(92vh - 44px);
}
.ai-calc-modal .main-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, #d4944a, #c67a3d, #b8682a, #c67a3d, #d4944a);
}
.ai-calc-modal .header { text-align: center; margin-bottom: 18px; }
.ai-calc-modal .header .icon-row { font-size: 34px; margin-bottom: 4px; letter-spacing: 2px; }
.ai-calc-modal .header h1 { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.ai-calc-modal .header .subtitle { font-size: 0.8rem; color: var(--text-light); margin-top: 3px; }
.ai-calc-modal .rule-badge {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--primary-light); color: #8b5a30;
    font-size: 0.72rem; padding: 5px 12px; border-radius: 20px;
    margin-top: 8px; font-weight: 500; border: 1px solid #f0dcc8;
}
.ai-calc-modal .form-section { display: flex; flex-direction: column; gap: 13px; margin-bottom: 18px; }
.ai-calc-modal .form-row { display: flex; flex-direction: column; gap: 5px; }
.ai-calc-modal .form-row.inline-row { flex-direction: row; align-items: center; gap: 10px; }
.ai-calc-modal .form-label { font-size: 0.86rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 5px; }
.ai-calc-modal .form-label .unit { font-weight: 400; color: var(--text-light); font-size: 0.74rem; }
.ai-calc-modal input[type="number"],
.ai-calc-modal input[type="text"],
.ai-calc-modal select {
    width: 100%; padding: 10px 13px; font-size: 0.95rem;
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: #fefcf9; color: var(--text); font-family: inherit;
    outline: none; transition: 0.2s; -webkit-appearance: none; appearance: none;
}
.ai-calc-modal input:focus,
.ai-calc-modal select:focus { border-color: #d4944a; box-shadow: 0 0 0 3px rgba(212, 148, 74, 0.1); background: #fff; }
.ai-calc-modal select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a7562' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px; cursor: pointer;
}
.ai-calc-modal .input-with-unit { display: flex; gap: 8px; align-items: center; }
.ai-calc-modal .input-with-unit input { flex: 2; }
.ai-calc-modal .input-with-unit select { flex: 1; padding-right: 28px; }
.ai-calc-modal .checkbox-wrapper { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.ai-calc-modal .checkbox-wrapper input { display: none; }
.ai-calc-modal .custom-checkbox {
    width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--border);
    background: #fefcf9; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.ai-calc-modal .checkbox-wrapper input:checked + .custom-checkbox { background: #c67a3d; border-color: #c67a3d; }
.ai-calc-modal .checkbox-wrapper input:checked + .custom-checkbox::after {
    content: ''; display: block; width: 5px; height: 10px; border: solid #fff;
    border-width: 0 2px 2px 0; transform: rotate(45deg); position: relative; top: -1px;
}
.ai-calc-modal .checkbox-label-text { font-size: 0.88rem; font-weight: 500; color: var(--text); }
.ai-calc-modal .checkbox-hint { font-size: 0.74rem; color: var(--text-light); }
.ai-calc-modal .btn-row { display: flex; gap: 10px; }
.ai-calc-modal .btn {
    flex: 1; padding: 11px 18px; font-size: 0.95rem; font-weight: 600;
    border: none; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; transition: 0.2s;
}
.ai-calc-modal .btn-calculate { background: linear-gradient(135deg, #d4944a, #c67a3d); color: #fff; flex: 2; box-shadow: 0 3px 12px rgba(198, 122, 61, 0.3); }
.ai-calc-modal .btn-calculate:hover { background: linear-gradient(135deg, #dd9d54, #cf8345); }
.ai-calc-modal .btn-reset { background: #f9f5ef; color: var(--text-secondary); border: 1.5px solid var(--border); flex: 1; }
.ai-calc-modal .btn-reset:hover { background: #f3ede4; }
.ai-calc-modal .result-section { background: var(--success-bg); border-radius: var(--radius); padding: 18px; border: 1px solid #e8dbcc; display: flex; flex-direction: column; flex: 1; margin-top: 0; }
.ai-calc-modal .result-section.visible { animation: ai-calc-fade 0.3s ease-out; }
.ai-calc-modal .result-empty { text-align: center; color: var(--text-light); font-size: 0.9rem; padding: 30px 12px; line-height: 1.8; }
.ai-calc-modal .result-body { display: block; }
@keyframes ai-calc-fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.ai-calc-modal .result-title { font-size: 0.8rem; font-weight: 700; color: #8b5a30; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; text-align: center; }
.ai-calc-modal .result-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed #e5d7c6; font-size: 0.9rem; color: var(--text-secondary); }
.ai-calc-modal .result-item:last-of-type { border-bottom: none; }
.ai-calc-modal .result-label { font-weight: 500; display: flex; align-items: center; gap: 5px; font-size: 0.85rem; }
.ai-calc-modal .result-value { font-weight: 700; color: var(--text); font-size: 0.92rem; text-align: right; }
.ai-calc-modal .result-item.result-total { margin-top: 6px; padding: 12px 14px; background: #fff; border-radius: var(--radius-sm); border: 2px solid #d4944a; font-size: 0.95rem; }
.ai-calc-modal .result-item.result-total .result-label { font-weight: 700; color: #8b4a1d; }
.ai-calc-modal .result-item.result-total .result-value { font-weight: 800; color: #b85d1f; font-size: 1.1rem; }
.ai-calc-modal .result-note { font-size: 0.72rem; color: var(--text-light); text-align: center; margin-top: 10px; font-style: italic; }
.ai-calc-modal .result-disclaimer { font-size: 0.7rem; color: #b0967a; text-align: center; margin-top: auto; border-top: 1px dashed #e0cfba; padding-top: 10px; }
.ai-calc-modal .highlight-zero { color: #9b8b78; font-style: italic; }
.ai-calc-modal .hidden-input { display: none; }

/* 移动端 */
@media (max-width: 720px) {
    .ai-calc-modal .calc-layout { flex-direction: column; gap: 16px; }
    .ai-calc-modal .calc-col { flex: 1 1 auto; }
    .ai-calc-modal .calc-left .btn-row { margin-top: 0; }
}
@media (max-width: 480px) {
    .ai-calc-modal { padding: 8px; }
    .ai-calc-modal .main-card { padding: 18px 14px 16px; }
    .ai-calc-modal-dialog { max-width: 100%; }
}

/* 移动端适配 */
@media (max-width: 480px) {
    .ai-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    .ai-fab { right: 16px; bottom: 16px; }
}
