/* ===== 基础重置与全局样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #001d31;
    --primary-hover: #004060;
    --danger-color: #dc3545;
    --danger-hover: #bb2d3b;
    --bg-color: #f8f9fa;
    --text-color: #001d31;
    --border-color: #dee2e6;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    line-height: 1.6;
}

/* ===== 顶部导航栏 ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background-color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    height: 60px;
    flex-shrink: 0;
    z-index: 10;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 36px;
    transition: transform 0.2s;
}

.logo:hover {
    transform: scale(1.05);
}

.app-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

/* 智能版 - 渐变色文字特效 */
.smart-badge {
    /* 1. 设置从左(#5f4699)到右(#9766a8)的线性渐变背景 */
    background: linear-gradient(to top, #5f4699, #9766a8);
    
    /* 2. 将背景裁剪为文字形状 (核心步骤) */
    -webkit-background-clip: text;
    background-clip: text;
    
    /* 3. 将文字颜色设为透明，从而透出背景的渐变色 */
    color: transparent;
    
    /* 4. 稍微缩小字号 (0.85em 表示父元素大小的 85%) */
    font-size: 0.85em;
    
    /* 5. 可选：微调间距，让它离前面的字稍微远一点点 */
    margin-left: 4px;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* 优化：防止小屏幕挤压 */
    justify-content: flex-end;
}

.btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-info {
    background-color: #bdcbd2;
    color: var(--primary-color);
}

.btn-info:hover {
    background-color: #e5e8ea;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

/* ===== 主内容区域 ===== */
.main-container {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* ===== 左侧工具栏 ===== */
.toolbar-panel {
    width: 280px;
    background-color: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.toolbar-tabs {
    flex-shrink: 0;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    background: white;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toolbar-tab {
    padding: 6px 15px;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s;
    font-size: 0.9rem;
    white-space: nowrap;
}

.toolbar-tab:hover {
    background-color: #f1f1f1;
}

.toolbar-tab.active {
    background-color: #dfe9ec;
    color: var(--primary-color);
    font-weight: 500;
}

.toolbar-items {
    flex: 1;
    padding: 10px;
    /* 优化：增加底部内边距，优化移动端滚动体验 */
    padding-bottom: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(4, 60px);
    grid-auto-rows: 60px;
    gap: 10px;
    justify-content: center;
    align-content: start;
    min-height: 0;
    -webkit-overflow-scrolling: touch; /* 优化：iOS 平滑滚动 */
}

.toolbar-item {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
}

.toolbar-item:hover {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.toolbar-item img {
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
    display: block;
}

.toolbar-item.add-text-btn {
    grid-column: span 4;
    aspect-ratio: unset;
    width: calc(100% - 20px);
    height: auto;
    min-height: 40px;
    padding: 8px;
    background-color: var(--primary-color);
    color: white;
    font-size: 0.9rem;
    margin: 0 10px;
}

.toolbar-item.add-text-btn:hover {
    background-color: var(--primary-hover);
    transform: none;
}

/* ===== 画布区域 ===== */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 20px;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    scroll-behavior: smooth;
}

.canvas-area::before,
.canvas-area::after {
    content: "";
    flex: 0 0 0px;
    margin: 0 -20px;
}

/* 美化滚动条 */
.canvas-area::-webkit-scrollbar {
    height: 8px;
}
.canvas-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.canvas-area::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}
.canvas-area::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.canvas {
    height: 150px;
    background-color: #001D31;
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 25px;
    transition: width 0.3s ease;
    flex-shrink: 0;
    overflow: visible;
    margin: 0 auto;
    min-width: min-content;
}

.canvas.empty {
    width: 50px;
    padding: 0;
}

.canvas-item {
    height: 150px;
    cursor: move;
    transition: transform 0.1s ease;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-right: 25px;
    position: relative;
}

.canvas-item:last-child {
    margin-right: 0 !important;
}

.canvas-item img {
    height: 100%;
    width: auto;
}

.canvas-item:hover {
    transform: scale(1.05);
}

.canvas-item.active {
    outline: 3px solid #00a0e9;
    outline-offset: -4px;
    border-radius: 4px;
    opacity: 0.9;
}

.dragging {
    opacity: 0.5;
}

/* ===== 底部信息栏 ===== */
.bottom-bar {
    background-color: white;
    border-top: 1px solid var(--border-color);
    padding: 8px 20px;
    font-size: 0.8rem;
    color: #6c757d;
    height: 40px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.footer-content {
    display: flex;
    gap: 15px;
    align-items: center;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
}

.footer-content a {
    color: inherit;
    text-decoration: none;
}

.footer-content a:hover {
    text-decoration: underline;
}

.beian-icon {
    height: 14px;
    margin-right: 2px;
    vertical-align: middle;
}

/* ===== 上下文菜单 ===== */
.context-menu {
    position: fixed;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    display: none;
    z-index: 1000;
    padding: 6px;
    min-width: 120px;
}

.context-menu.show {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-color);
}

.menu-item:hover {
    background-color: #f1f1f1;
}

.menu-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.remove-btn {
    color: var(--danger-color);
}

/* ===== 对话框样式 ===== */
.text-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    width: 400px;
    max-width: 90vw;
}

.dialog-row {
    margin-bottom: 15px;
}

.dialog-row strong {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #495057;
}

.dialog-row label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.dialog-row input[type="text"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    margin-top: 4px;
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.dialog-buttons button {
    padding: 6px 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.color-btn {
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

/* ===== 新增：对话框关闭按钮样式 ===== */
.dialog-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
    z-index: 10;
}

.dialog-close-btn:hover {
    color: #333;
}

/* ===== 滚动条美化 ===== */
.toolbar-items::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.toolbar-items::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.toolbar-items::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.toolbar-items::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ========== 内联 SVG 样式 ========== */
.toolbar-icon svg,
.menu-icon svg,
.btn-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    margin-right: 0.3em;
    pointer-events: none;
}

.toolbar-tab svg {
    width: 16px;
    height: 16px;
}

/* ===== 悬浮操作栏容器 ===== */
.float-action-bar {
    position: absolute;
    bottom: 30px;
    /* 桌面端居中逻辑：50%屏幕 + 150px侧边栏偏移 */
    left: calc(50% + 150px);
    transform: translateX(-50%);
    
    display: none; /* 默认隐藏，JS控制为 flex */
    flex-direction: row;
    gap: 15px; /* 按钮之间的间距 */
    z-index: 900;
}

/* 悬浮按钮基础样式 */
.btn-float-base {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 50px; /* 胶囊形状 */
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 纠错按钮特定样式 (橙色) */
.btn-float-feedback {
    background-color: #eb9605;
}

/* 焕新按钮特定样式 (蓝色 #00A0E9) */
.btn-float-refresh {
    background-color: #00A0E9;
}

/* 悬浮交互效果 */
.btn-float-base:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    filter: brightness(1.1); /* 稍微变亮 */
}

.btn-float-base:active {
    transform: translateY(1px);
}

/* 移动端适配 */
@media (max-width: 900px) {
    .float-action-bar {
        left: 50%; /* 移动端直接居中 */
        bottom: 20px;
        gap: 10px;
    }
    .btn-float-base {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
}

/* 桌面端特定设置 */
@media (min-width: 993px) {
    .toolbar-panel {
        width: 300px;
    }
    .toolbar-items {
        grid-template-columns: repeat(4, 60px);
        justify-content: space-around;
    }
}

/* ===== 移动端适配 ===== */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }
    
    .bottom-bar {
        font-size: 0.65rem;
        height: 60px;
        line-height: 0.1;
    }
    
    .toolbar-panel {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-top: 1px solid var(--border-color);
    }
    
    .toolbar-tabs {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 5px;
    }
    
    .toolbar-tab {
        margin-bottom: 0;
        margin-right: 4px;
    }

    .toolbar-items {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        justify-content: start;
    }
    
    .canvas-area {
        padding: 15px;
    }

    .top-bar {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 10px;
    }
    
    .logo-container {
        width: 100%;
        justify-content: center;
    }

    .btn-float-feedback {
        /* 移动端侧边栏在顶部，画板占满宽度，所以直接居中 */
        left: 50%;
        bottom: 20px;
        padding: 8px 20px;
        font-size: 0.85rem;
    }
}

@media (max-width: 520px) {
    .app-title {
        font-size: 0.9rem;
    }    
    .logo {
        height: 26px;
        transition: transform 0.2s;
    }

    /* 1. 调整容器为 Grid 布局 */
    .action-buttons {
        display: grid !important;
        width: 100%;
        /* 定义3列：第1列自动撑满，第2、3列自适应 */
        grid-template-columns: 1fr auto auto;
        /* 定义3行：按钮行 - 分割线 - 按钮行 */
        grid-template-rows: auto auto auto;
        /* 上下间距4px，左右间距4px (保持与上一级一致) */
        gap: 4px 4px; 
        padding-top: 4px;
        justify-content: end; /* 整体右对齐 */
    }

    /* 2. 第一行定位 */
    #clear-btn {
        grid-row: 1;
        grid-column: 1;
        justify-self: start; /* 清空在左侧 */
    }
    #export-btn {
        grid-row: 1;
        grid-column: 2;
    }
    #export-svg-btn {
        grid-row: 1;
        grid-column: 3;
    }

    /* 3. 中间分割线 */
    .action-buttons::after {
        content: '';
        grid-row: 2;         /* 放在第2行 */
        grid-column: 1 / -1; /* 跨越整行 */
        height: 1px;
        background-color: #e0e0e0;
        width: 100%;
        margin: 2px 0;
    }

    /* 4. 第二行定位 */
    #scan-btn {
        grid-row: 3;
        grid-column: 1;
        justify-self: start; /* AI识图在左侧 */
    }
    #verinfo {
        grid-row: 3;
        grid-column: 3; /* 帮助在最右侧 */
    }

    /* 5. 隐藏多余元素 */
    #camera-input { display: none; }

    /* 6. 【关键修改】按钮样式强制同步上一级 (520px) */
    .btn {
        padding: 6px 6px;   /* 同步 */
        font-size: 0.85rem;  /* 同步 */
        gap: 2px;           /* 同步 */
        white-space: nowrap; /* 防止文字换行 */
        border-radius: 4px;
    }

    /* 7. 【关键修改】图标大小强制同步上一级 */
    .btn-icon {
        width: 0.85em;  /* 同步 */
        height: 0.85em; /* 同步 */
    }
    
    /* 8. 顶部栏高度自适应 */
    .top-bar {
        height: auto;
        padding-bottom: 10px;
    }
}