/* ==================== CSS 变量定义 ==================== */
:root {
    /* 深色主题（默认） */
    --bg-primary: #0f172a;
    --bg-secondary: rgba(30, 41, 59, 0.7);
    --bg-input: rgba(15, 23, 42, 0.6);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(148, 163, 184, 0.2);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.5);
    --preview-bg: #ffffff;
    --preview-text: #1e293b;
    --gradient-start: rgba(56, 189, 248, 0.1);
    --gradient-end: rgba(168, 85, 247, 0.1);
}

/* 浅色主题 */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: rgba(255, 255, 255, 0.95);
    --bg-input: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: rgba(148, 163, 184, 0.3);
    --glass-border: rgba(0, 0, 0, 0.08);
    --shadow-color: rgba(0, 0, 0, 0.1);
    --preview-bg: #ffffff;
    --preview-text: #1e293b;
    --gradient-start: rgba(56, 189, 248, 0.05);
    --gradient-end: rgba(168, 85, 247, 0.05);
}

/* ==================== 基础样式 ==================== */
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    background-image: 
        radial-gradient(at 0% 0%, var(--gradient-start) 0px, transparent 50%),
        radial-gradient(at 100% 0%, var(--gradient-end) 0px, transparent 50%),
        radial-gradient(at 100% 100%, var(--gradient-start) 0px, transparent 50%),
        radial-gradient(at 0% 100%, var(--gradient-end) 0px, transparent 50%);
}

/* ==================== 玻璃效果（仅用于用户下拉菜单） ==================== */
.glass-effect {
    background: var(--bg-secondary);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* ==================== 模态框内容（不使用模糊效果） ==================== */
.modal-content {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* 浅色主题下的模态框 */
[data-theme="light"] .modal-content {
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .modal-content h2 {
    color: #1e293b;
}

[data-theme="light"] .modal-content label {
    color: #64748b;
}

[data-theme="light"] .modal-content .input-field {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #1e293b;
}

[data-theme="light"] .modal-content .border-slate-700 {
    border-color: #e2e8f0;
}

[data-theme="light"] .modal-content .text-slate-400 {
    color: #64748b;
}

[data-theme="light"] .modal-content .text-slate-300 {
    color: #475569;
}

/* ==================== 输入框样式 ==================== */
.input-field {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.input-field::placeholder {
    color: var(--text-muted);
}

.input-field:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
    outline: none;
}

/* ==================== 按钮样式 ==================== */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 浅色主题下的按钮 */
[data-theme="light"] .btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: #1e293b;
}

[data-theme="light"] .btn-secondary:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* ==================== 报价单预览 ==================== */
.quote-preview {
    background: var(--preview-bg);
    color: var(--preview-text);
    box-shadow: 0 25px 50px -12px var(--shadow-color);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* 预览区域表格表头 - 深色背景保持 */
.quote-preview table thead tr {
    background-color: #111827 !important;
    color: #ffffff !important;
}

.quote-preview table thead th {
    color: #ffffff !important;
}

/* 预览区域表格内容 */
.quote-preview table tbody td {
    color: #1e293b !important;
}

.quote-preview table tbody td .text-gray-800 {
    color: #1e293b !important;
}

.quote-preview table tbody td .text-gray-600 {
    color: #4b5563 !important;
}

.quote-preview table tbody td .text-gray-500 {
    color: #6b7280 !important;
}

/* 预览区域其他文字 */
.quote-preview h1 {
    color: #111827 !important;
}

.quote-preview .text-gray-900 {
    color: #111827 !important;
}

.quote-preview .text-blue-600 {
    color: #2563eb !important;
}

.quote-preview .text-red-600 {
    color: #dc2626 !important;
}

/* ==================== 动画效果 ==================== */
.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== 模态框背景 ==================== */
.modal-backdrop {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
}

/* ==================== 备注展开动画 ==================== */
.note-section {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out, margin 0.3s ease;
    opacity: 0;
}

.note-section.expanded {
    max-height: 200px;
    opacity: 1;
    margin-top: 12px;
}

.note-toggle-btn {
    transition: all 0.3s ease;
}

.note-toggle-btn.active {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.1);
}

/* ==================== 金额显示 ==================== */
.amount-display {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* ==================== TAB样式 ==================== */
.tab-container {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

.tab-container::-webkit-scrollbar {
    height: 4px;
}

.tab-container::-webkit-scrollbar-track {
    background: transparent;
}

.tab-container::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.3);
    border-radius: 2px;
}

.tab {
    position: relative;
    padding: 8px 12px 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    max-width: 220px;
    user-select: none;
}

.tab:hover {
    background: rgba(56, 189, 248, 0.1);
}

.tab.active {
    background: var(--bg-secondary);
    border-color: #38bdf8;
    border-bottom-color: transparent;
}

.tab-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    color: var(--text-primary);
    pointer-events: none;
}

.tab-edit-btn {
    opacity: 0.5;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-edit-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    color: #38bdf8;
}

.tab-close {
    opacity: 0.5;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-close:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.tab-close.hidden {
    display: none;
}

/* 编辑模式下的输入框 */
.tab.editing .tab-name {
    display: none;
}

.tab-edit-input {
    display: none;
    background: var(--bg-input);
    border: 1px solid #38bdf8;
    border-radius: 4px;
    color: var(--text-primary);
    padding: 2px 6px;
    font-size: 14px;
    width: 100%;
    outline: none;
}

.tab.editing .tab-edit-input {
    display: block;
}

/* ==================== 打印样式 ==================== */
.print-only {
    display: none;
}

@media print {
    @page {
        size: A4;
        margin: 15mm;
    }
    
    body { 
        background: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .no-print { display: none !important; }
    .no-print-header { display: none !important; }
    .print-only { display: block !important; }
    
    .quote-preview { 
        box-shadow: none !important; 
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }
    
    /* 防止分页截断 */
    .quote-preview > div > div {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    /* 表格行防止截断 */
    .quote-preview table tbody tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    /* 表格表头在每页重复 */
    .quote-preview table thead {
        display: table-header-group;
    }
    
    /* 防止标题和表格之间分页 */
    .quote-preview table {
        break-before: avoid;
        page-break-before: avoid;
    }
    
    /* 总计区域防止截断 */
    .quote-preview .flex.justify-end {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    /* 底部信息防止截断 */
    .quote-preview .grid.grid-cols-1,
    .quote-preview .text-center {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ==================== 货币输入框 ==================== */
.currency-input::-webkit-outer-spin-button,
.currency-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ==================== 存储模式指示器 ==================== */
.storage-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.storage-indicator.cloud {
    background: rgba(56, 189, 248, 0.2);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.storage-indicator.local {
    background: rgba(148, 163, 184, 0.2);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

/* ==================== 用户下拉菜单 ==================== */
#userDropdown {
    animation: dropdownSlide 0.2s ease-out;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 主题切换动画 ==================== */
#themeIconSun,
#themeIconMoon {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ==================== 底部版权栏 ==================== */
footer {
    background: linear-gradient(to top, var(--bg-secondary), transparent);
}

/* 底部品牌文字颜色适配 */
.footer-brand p:first-child {
    color: var(--text-primary);
}

.footer-brand p:last-child {
    color: var(--text-secondary);
}

.footer-links,
.footer-meta {
    color: var(--text-secondary);
}

/* ==================== 响应式调整 ==================== */
@media (max-width: 768px) {
    .tab {
        min-width: 120px;
        padding: 6px 10px 6px 12px;
    }
    
    .tab-name {
        font-size: 12px;
    }
}

/* ==================== Checkbox样式 ==================== */
/* 浅色主题下的checkbox */
[data-theme="light"] input[type="checkbox"] {
    border-color: #d1d5db;
    background-color: #ffffff;
}

[data-theme="light"] input[type="checkbox"]:checked {
    background-color: #3b82f6;
    border-color: #3b82f6;
}

/* ==================== 浅色主题特定调整 ==================== */
[data-theme="light"] h1,
[data-theme="light"] h2 {
    color: #1e293b;
}

[data-theme="light"] .text-slate-200 {
    color: #1e293b;
}

[data-theme="light"] .text-slate-300 {
    color: #334155;
}

[data-theme="light"] .text-slate-400 {
    color: #64748b;
}

/*[data-theme="light"] .text-white {
    color: #1e293b;
}*/

[data-theme="light"] .border-slate-700 {
    border-color: #e2e8f0;
}

[data-theme="light"] footer {
    border-color: #e2e8f0;
}

/* 浅色主题下的输入框文字 */
[data-theme="light"] .input-field {
    color: #1e293b;
}

/* 浅色主题下的玻璃效果卡片标题 */
[data-theme="light"] .glass-effect h2 {
    color: #1e293b;
}

/* 浅色主题下的标签文字 */
[data-theme="light"] label.text-slate-400 {
    color: #64748b;
}

/* 浅色主题下的下拉菜单 */
[data-theme="light"] #userDropdown .text-white {
    color: #1e293b;
}

[data-theme="light"] #userDropdown .text-slate-400 {
    color: #64748b;
}

/* 浅色主题下的边框 */
[data-theme="light"] .border-slate-700\/50 {
    border-color: rgba(226, 232, 240, 0.5);
}

/* 金额显示在浅色主题下 */
[data-theme="light"] .amount-display {
    color: #334155;
}

/* 项目总计在浅色主题下 */
[data-theme="light"] .item-total {
    color: #334155 !important;
}

/* 备注按钮在浅色主题下 */
[data-theme="light"] .note-toggle-btn {
    color: #64748b;
}

[data-theme="light"] .note-toggle-btn:hover {
    color: #38bdf8;
}

/* 删除按钮在浅色主题下 */
[data-theme="light"] .text-red-400 {
    color: #ef4444;
}

/* 打赏模态框图片样式 */
.donate-qr-code {
    width: 100%;
    height: auto;
    max-width: 160px;
    border-radius: 8px;
    object-fit: contain;
}

/* ==================== 项目清单网格布局（桌面端） ==================== */
.item-grid {
    display: grid;
    grid-template-columns: minmax(0, 4fr) minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 12px;
}

/* ==================== 移动端样式优化 ==================== */
@media (max-width: 768px) {
    /* 项目清单卡片 */
    .item-row {
        padding: 12px !important;
    }
    
    /* 项目清单网格改为垂直布局 */
    .item-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas: 
            "name name"
            "qty price"
            "actions actions";
        gap: 8px;
    }
    
    .item-name-col {
        grid-area: name;
    }
    
    .item-qty-col {
        grid-area: qty;
    }
    
    .item-price-col {
        grid-area: price;
    }
    
    .item-actions-col {
        grid-area: actions;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 0 !important;
        padding-top: 8px;
        border-top: 1px solid rgba(148, 163, 184, 0.2);
        margin-top: 4px;
    }
    
    .item-actions-col .item-total {
        flex: 1;
        text-align: left;
        font-size: 14px;
    }
    
    /* 底部版权区域优化 */
    footer {
        margin-top: 24px !important;
    }
    
    footer .max-w-7xl > div {
        flex-direction: column;
        gap: 12px !important;
        text-align: center;
    }
    
    footer .flex.items-center.gap-6 {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 16px !important;
        font-size: 12px;
    }
    
    footer .flex.items-center.gap-6 span.text-slate-600 {
        display: none;
    }
    
    footer .text-xs.text-slate-500 {
        font-size: 11px;
    }
    
    /* 输入框在移动端更紧凑 */
    .input-field {
        padding: 8px 10px !important;
        font-size: 14px !important;
    }
    
    /* 玻璃效果卡片内边距减小 */
    .glass-effect {
        padding: 16px !important;
    }
    
    /* 标题字号调整 */
    .glass-effect h2 {
        font-size: 16px;
    }
    
    /* 按钮尺寸调整 */
    .btn-primary, .btn-secondary {
        padding: 8px 12px !important;
        font-size: 13px !important;
    }
    
    /* 税务与折扣区域 */
    .grid.grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* 公司信息和客户信息的网格 */
    .grid.grid-cols-1.md\\:grid-cols-2 {
        gap: 12px;
    }
    
    /* 预览区域按钮组 */
    .flex.gap-2.flex-wrap {
        gap: 6px;
    }
    
    .flex.gap-2.flex-wrap button {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    
    .flex.gap-2.flex-wrap button svg {
        width: 14px;
        height: 14px;
    }
}

/* 超小屏幕进一步优化 */
@media (max-width: 480px) {
    body {
        padding: 12px !important;
    }
    
    .glass-effect {
        padding: 12px !important;
        border-radius: 12px !important;
    }
    
    /* 项目清单进一步压缩 */
    .item-row {
        padding: 10px !important;
    }
    
    .item-grid {
        gap: 6px;
    }
    
    /* 底部版权更紧凑 */
    footer .py-6 {
        padding-top: 16px !important;
        padding-bottom: 16px !important;
    }
    
    footer .flex.items-center.gap-6 {
        flex-direction: column;
        gap: 6px !important;
    }
    
    /* 头部标题 */
    header h1 {
        font-size: 18px;
    }
    
    header p {
        font-size: 11px;
    }
    
    /* 用户菜单按钮 */
    #userMenuContainer button {
        padding: 8px 10px !important;
    }
    
    #userMenuContainer button span {
        display: none;
    }
}