* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #f5f7fb;
    color: #1e293b;
}

/* 整个应用容器固定视口高度，防止整体滚动 */
.app {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    height: 100vh;
    /*overflow: hidden;*/
    display: flex;
    flex-direction: column;
}

header {
    background: #0f172a;
    color: white;
    padding: 12px 16px;
    flex-shrink: 0;
    z-index: 10;
}
header h1 {
    margin: 0;
    font-size: 1.4rem;
}
.status {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-top: 4px;
}

/* 摄像头容器 + 红色矩形框 */
.camera-container {
    position: relative;
    width: 100%;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}
video {
    width: 100%;
    max-height: 400px;
    background: #111;
    border-radius: 16px;
    transform: scaleX(-1);
    object-fit: cover;
}
/* 基础样式（共用） */
.scan-rect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 3px solid #ff0000;
    border-radius: 12px;
    pointer-events: none;
    z-index: 10;
}
/* OCR 模式：宽而矮 */
.scan-rect-ocr {
    width: 82%;
    height: 21%;
}
/* 条形码模式：窄而高 */
.scan-rect-barcode {
    width: 79%;
    height: 30%;
}
.fullscreen-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 20;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 30px;
    width: 44px;
    height: 44px;
    font-size: 24px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}
.fullscreen-toggle:hover {
    background: rgba(255,255,255,0.3);
}
.fullscreen-mode .main-layout {
    display: none;
}
.fullscreen-mode header {
    display: none;
}
.fullscreen-mode .button-group {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    width: 90%;
    margin: 0;
}
.fullscreen-mode .camera-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: #000;
    border-radius: 0;
}
.fullscreen-mode .camera-container video {
    max-height: 100%;
    border-radius: 0;
}
.fullscreen-mode .fullscreen-toggle {
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
}

/* 按钮组 */
.button-group {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 16px 16px 0;
    flex-shrink: 0;
}
.recognize-btn {
    background: #2c7da0;
    border: none;
    color: white;
    padding: 12px 12px;
    border-radius: 40px;
    font-size: 1rem;
    font-weight: bold;
    flex: 1;
}
.save-btn {
    background: #2b9348;
    border: none;
    color: white;
    padding: 12px 12px;
    border-radius: 40px;
    font-size: 1rem;
    font-weight: bold;
    flex: 1;
}

/* 左右布局容器，占满剩余高度 */
.main-layout {
    display: flex;
    flex: 1;
    /*overflow: hidden;*/
    gap: 1px;
    background: #e2e8f0;
    /*min-height: 0;*/
}

/* 左侧文件夹面板 */
.folders-panel {
    width: 35%;
    max-width: 260px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e2e8f0;
    /*flex: 1;*/
    /*min-height: 0;*/
    /*overflow: hidden;*/
}
.folders-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    padding: 12px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.folder-title-buttons {
    display: flex;
    gap: 8px;
}
.title-btn {
    background: #475569;
    border: none;
    color: white;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    cursor: pointer;
    font-weight: normal;
}
.delete-all-btn {
    background: #dc2626;
}
.title-btn:hover {
    opacity: 0.9;
}
.search-box {
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.folder-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
    box-sizing: border-box;
}
.folder-search:focus {
    border-color: #2c7da0;
}
.folders-list {
    /*flex: 1;*/
    /*overflow-y: auto;    !* 竖向滚动 *!*/
    padding: 8px;
    /*min-height: 0;*/
}
.folder-chip {
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.1s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}
.folder-chip.active {
    background: #2c7da0;
    border-color: #2c7da0;
    color: white;
}
.folder-chip .count {
    background: #e2e8f0;
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 0.7rem;
    color: #0f172a;
    margin-left: 6px;
}
.folder-chip.active .count {
    background: #ffffff80;
    color: #0f172a;
}
.remain-days {
    font-size: 0.7rem;
    margin-left: 4px;
    color: #f97316;
}
.current-badge {
    font-size: 0.7rem;
    background: #22c55e;
    color: white;
    padding: 2px 6px;
    border-radius: 12px;
    margin-left: 6px;
}
.folder-delete {
    background: rgba(0,0,0,0.1);
    border: none;
    border-radius: 20px;
    width: 26px;
    height: 26px;
    font-size: 14px;
    cursor: pointer;
    color: #dc2626;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.folder-chip.active .folder-delete {
    color: #fff;
    background: rgba(255,255,255,0.2);
}

/* 右侧照片面板 */
.photos-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
}
.current-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
#currentFolderLabel {
    font-weight: bold;
    background: #eef2ff;
    padding: 6px 12px;
    border-radius: 40px;
    font-size: 0.9rem;
}
.download-btn {
    background: #2b9348;
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 40px;
    font-weight: bold;
}
.download-btn:disabled {
    background: #cbd5e1;
}
.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    row-gap: 8px;
    column-gap: 6px;
    padding: 12px;
    /* 移除 flex:1，改为 min-height 保证至少显示2行（每行约120px+gap） */
    min-height: 280px;   /* 2行高度（120*2 + 8*2 + padding） */
    align-content: start;
}
.photo-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    height: 120px;
    border: 1px solid #000;
    margin: 0;
}
.photo-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.delete-photo {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 16px;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
}
.empty-tip {
    text-align: center;
    color: #64748b;
    grid-column: 1 / -1;
    padding: 40px;
}

/* 移动端适配：宽度小于640px时，左右布局转为上下结构，文件夹横向滚动 */
@media (max-width: 640px) {
    .main-layout {
        flex-direction: column;
    }
    .folders-panel {
        width: 100%;
        max-width: none;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
        max-height: 30vh;        /* 限制高度，超出可横向滚动 */
        flex: none;
    }
    .folders-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px;
        gap: 8px;
        flex: none;
        min-height: auto;
    }
    .folder-chip {
        flex-shrink: 0;
        min-width: 120px;
        margin-bottom: 0;
    }
    .photos-panel {
        flex: 1;
    }
}