:root {
    --primary: #4F6EF7;
    --primary-dark: #3A54D4;
    --primary-light: #E8ECFF;
    --success: #22C55E;
    --success-light: #DCFCE7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --warning: #F59E0B;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin:0; padding:0; box-sizing:border-box; }
html, body {
    width:100%; height:100%; overflow-x:hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

.page {
    position:absolute; top:0; left:0; width:100%; height:100%;
    display:none; flex-direction:column; opacity:0;
    transition: opacity var(--transition); overflow-y: auto;
}
.page.active { display:flex; opacity:1; }

/* 首页 */
.home-container {
    flex:1; display:flex; flex-direction:column; align-items:center;
    padding: 28px 20px 32px; gap:16px; max-width:600px; margin:0 auto; width:100%;
}
.logo-icon { color:var(--primary); animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-8px);} }
.app-title { font-size:26px; font-weight:700; }
.app-subtitle { font-size:14px; color:var(--text-secondary); }

.config-card {
    width:100%; background:var(--surface); border-radius:var(--radius-lg);
    padding:20px; box-shadow:var(--shadow-md); border:1px solid var(--border);
    display:flex; flex-direction:column; gap:14px;
}
.config-header { display:flex; flex-direction:column; gap:2px; }
.config-title { font-size:16px; font-weight:700; }
.config-hint { font-size:12px; color:var(--text-muted); }

.variables-list { display:flex; flex-direction:column; gap:10px; }
.variable-row { display:flex; align-items:center; gap:8px; }
.variable-input {
    flex:1; padding:10px 14px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; background:#F8FAFC; outline:none; transition: all var(--transition);
}
.variable-input:focus { border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:#fff; }
.variable-input.quantity-input { border-color:#FCD34D; background:#FFFBEB; }
.variable-index { font-size:12px; font-weight:600; color:var(--text-muted); min-width:24px; text-align:center; }

.variables-actions { display:flex; gap:8px; flex-wrap:wrap; }
.btn-add-variable, .btn-remove-variable {
    display:inline-flex; align-items:center; gap:6px; padding:8px 14px;
    font-size:13px; font-weight:500; border-radius:8px; border:1px dashed var(--border);
    background:transparent; color:var(--text-secondary); cursor:pointer; transition:all var(--transition);
}
.btn-add-variable:hover { border-color:var(--primary); color:var(--primary); background:var(--primary-light); }
.btn-remove-variable:hover:not(:disabled) { border-color:var(--danger); color:var(--danger); background:var(--danger-light); }
.btn-remove-variable:disabled { opacity:0.4; cursor:not-allowed; }

.unique-var-section {
    display:flex; flex-direction:column; gap:14px;
    padding:2px 0;
}
.unique-toggle { display:flex; align-items:center; gap:12px; cursor:pointer; font-size:14px; font-weight:500; }
.toggle-slider {
    position:relative; width:44px; height:24px; background:#CBD5E1; border-radius:12px; transition:background var(--transition);
}
.toggle-slider::after {
    content:''; position:absolute; top:2px; left:2px; width:20px; height:20px;
    background:#fff; border-radius:50%; transition:transform var(--transition); box-shadow:var(--shadow-sm);
}
#chkUniqueVar, #chkAllowChinese { display:none; }
#chkUniqueVar:checked + .toggle-slider,
#chkAllowChinese:checked + .toggle-slider { background:var(--primary); }
#chkUniqueVar:checked + .toggle-slider::after,
#chkAllowChinese:checked + .toggle-slider::after { transform:translateX(20px); }
.input-unique-var {
    width:100%; padding:10px 14px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; background:#F8FAFC; outline:none;
}
.input-unique-var:disabled { opacity:0.5; background:#F1F5F9; }

/* 高级选项折叠 */
.advanced-section {
    border-top:1px solid var(--border);
    padding-top:16px;
    margin-top:8px;
}
.btn-advanced-toggle {
    display:flex; align-items:center; justify-content:space-between; width:100%;
    padding:10px 14px; background:var(--bg); border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; font-weight:600; color:var(--text-secondary); cursor:pointer;
    transition: all var(--transition);
}
.btn-advanced-toggle:hover { background:var(--primary-light); border-color:var(--primary); }
.btn-advanced-toggle .arrow { transition: transform 0.3s; display:inline-block; }
.btn-advanced-toggle .arrow.open { transform: rotate(90deg); }

.advanced-content {
    margin-top:16px;
    display:flex; flex-direction:column; gap:22px;
    padding:4px 6px 2px;
}
.advanced-divider {
    border-top:1px dashed var(--border);
    margin:6px 0;
}
.option-row {
    display:flex; align-items:center; gap:16px; flex-wrap:wrap;
    min-height:40px;
    margin-bottom:0;
}
.option-label {
    font-size:14px; font-weight:500; min-width:88px;
    color:var(--text);
}
.sub-hint {
    font-size:12px; color:var(--text-muted);
    margin-left:104px; margin-top:-14px;
    line-height:1.4;
}

/* API 输入框 */
.input-api-url {
    flex:1; min-width:200px; padding:10px 14px;
    border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; background:#F8FAFC; outline:none;
    transition: all var(--transition);
}
.input-api-url:focus { border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:#fff; }

/* 白名单输入框 */
.input-whitelist {
    flex:1; min-width:120px; padding:10px 14px;
    border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
    transition: all var(--transition);
}
.input-whitelist:focus { border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:#fff; }

.quality-slider {
    flex:1; min-width:100px; max-width:180px;
    accent-color: var(--primary);
}
.quality-value {
    font-size:14px; font-weight:600; color:var(--primary); min-width:44px;
}
.input-interval {
    width:120px; padding:10px 12px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
    transition: all var(--transition);
}
.input-interval:focus { border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:#fff; }
.unit {
    font-size:13px; color:var(--text-secondary);
}
.input-confidence {
    width:100px; padding:10px 12px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
    transition: all var(--transition);
}
.input-confidence:focus { border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); background:#fff; }

/* 白名单输入框 */
.input-whitelist {
    flex:1; min-width:120px; padding:8px 12px;
    border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
}
.input-whitelist:focus { border-color:var(--primary); }

.quality-slider {
    flex:1; min-width:100px; max-width:180px;
    accent-color: var(--primary);
}
.quality-value {
    font-size:14px; font-weight:600; color:var(--primary); min-width:44px;
}
.input-interval {
    width:120px; padding:8px 10px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
}
.input-interval:focus { border-color:var(--primary); }
.unit {
    font-size:13px; color:var(--text-secondary);
}
.input-confidence {
    width:100px; padding:8px 10px; border:1px solid var(--border); border-radius:var(--radius-sm);
    font-size:14px; text-align:center; background:#F8FAFC; outline:none;
}
.input-confidence:focus { border-color:var(--primary); }

.btn-primary {
    display:inline-flex; align-items:center; gap:10px; padding:14px 36px;
    font-size:17px; font-weight:600; color:#fff; background:var(--primary);
    border:none; border-radius:50px; cursor:pointer;
    box-shadow:0 6px 24px rgba(79,110,247,0.35); transition:all var(--transition);
}
.btn-primary:hover { background:var(--primary-dark); transform:translateY(-1px); }
.home-hint { font-size:13px; color:var(--text-muted); }

/* 扫描页面 */
.video-container {
    width:100%; height:50vh; position:relative; background:#0F172A; overflow:hidden; flex-shrink:0;
}
.video-container video { width:100%; height:100%; object-fit:cover; }

.scan-overlay { position:absolute; inset:0; display:flex; flex-direction:column; pointer-events:none; z-index:10; }
.scan-mask {
    background: transparent;
}
.scan-mask-top, .scan-mask-bottom { flex:1 1 auto; width:100%; }
.scan-mask-row { display:flex; flex:0 0 auto; width:100%; }
.scan-mask-left, .scan-mask-right { flex:1 1 auto; height:100%; }

.scan-frame {
    flex:0 0 auto;
    width: min(38vw, 200px);
    height: min(63vw, 333px);
    min-width:80px; min-height:120px;
    max-width:85vw; max-height:70vh;
    position:relative;
    border:2px solid rgba(255,255,255,0.7);
    border-radius:4px;
    transition: border-color 0.4s, box-shadow 0.4s;
    box-shadow: 0 0 0 4px rgba(255,255,255,0.08);
    resize:both; overflow:auto; pointer-events:auto;
}
.scan-frame.aligned {
    border-color:var(--success) !important;
    box-shadow:0 0 0 6px rgba(34,197,94,0.2), 0 0 24px rgba(34,197,94,0.25) !important;
}

.corner { position:absolute; width:18px; height:18px; border-color:#fff; border-style:solid; z-index:2; pointer-events:none; }
.scan-frame.aligned .corner { border-color:var(--success); }
.corner-tl { top:-2px; left:-2px; border-width:3px 0 0 3px; }
.corner-tr { top:-2px; right:-2px; border-width:3px 3px 0 0; }
.corner-bl { bottom:-2px; left:-2px; border-width:0 0 3px 3px; }
.corner-br { bottom:-2px; right:-2px; border-width:0 3px 3px 0; }

.scan-line {
    position:absolute; left:8px; right:8px; height:2px;
    background:linear-gradient(90deg, transparent, rgba(79,110,247,0.6) 15%, rgba(79,110,247,0.95) 50%, rgba(79,110,247,0.6) 85%, transparent);
    top:10%; animation:scan-line-move 2.4s ease-in-out infinite;
    z-index:3; pointer-events:none;
}
@keyframes scan-line-move { 0%{top:8%;opacity:0.3;} 50%{top:88%;opacity:1;} 100%{top:8%;opacity:0.3;} }

.status-badge {
    position:absolute; bottom:-36px; left:50%; transform:translateX(-50%);
    font-size:12px; font-weight:600; padding:6px 14px; border-radius:20px;
    background:rgba(255,255,255,0.15); color:#fff; backdrop-filter:blur(8px);
    z-index:5; pointer-events:auto;
}
.scan-frame.aligned .status-badge { background:var(--success); color:#fff; }

/* 扫描框下方提示 */
.scan-notice {
    margin: 8px 16px 0;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    display: none;
}
.scan-notice.show { display:block; animation: noticePop 0.3s ease; }
.scan-notice.success { background: var(--success-light); color: var(--success); border:1px solid #86EFAC; }
.scan-notice.error { background: var(--danger-light); color: var(--danger); border:1px solid #FCA5A5; }
@keyframes noticePop { from { opacity:0; transform:translateY(-6px);} to { opacity:1; transform:translateY(0);} }

.data-section {
    flex:1; display:flex; flex-direction:column; padding:12px 16px; gap:8px;
    background:var(--surface); overflow-y:auto;
}

/* 确认面板 */
.confirm-panel {
    margin: 8px 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: none;
}
.confirm-panel.visible {
    display: block;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 600;
}
.panel-body {
    padding: 12px 16px;
    overflow-x: auto;
}
.panel-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* 确认面板内输入框样式 */
.confirm-panel .preview-table input {
    width: 100%;
    min-width: 60px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: #f9fafb;
    outline: none;
    transition: border-color var(--transition), background var(--transition);
}
.confirm-panel .preview-table input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}
.confirm-panel .preview-table input:read-only {
    background: #f1f5f9;
    cursor: default;
}
.confirm-panel .preview-table input:not(:read-only) {
    background: #ffffff;
}

.table-toolbar { display:flex; gap:6px; align-items:center; flex-wrap:nowrap; }
.btn-tool {
    padding:6px 10px; font-size:12px; font-weight:600; border-radius:20px;
    border:1px solid var(--border); background:#fff; color:var(--text);
    cursor:pointer; display:inline-flex; align-items:center; gap:4px; white-space:nowrap;
}
.btn-tool:hover { background:#F8FAFC; }
.btn-tool-danger { color:var(--danger); border-color:#FECACA; }
.btn-tool-download { color:var(--primary); border-color:#C7D2FE; }
.btn-tool-import { color:var(--primary); border-color:#C7D2FE; margin-left:auto; }

.table-wrapper {
    flex:1; overflow:auto; max-height:35vh; border:1px solid var(--border);
    border-radius:var(--radius-sm); background:#fff;
}
.data-table { width:100%; border-collapse:collapse; font-size:12px; white-space:nowrap; }
.data-table th, .data-table td { padding:8px 10px; text-align:center; border-bottom:1px solid var(--border); }
.data-table th { background:#F1F5F9; font-weight:700; position:sticky; top:0; z-index:2; }
/* 灰白交替行 */
.data-table tbody tr:nth-child(odd) { background:#FFFFFF; }
.data-table tbody tr:nth-child(even) { background:#F1F5F9; }
.data-table tbody tr:hover { background:#E8ECFF; }

/* 操作列按钮（三个点） */
.btn-row-actions {
    background: none;
    border: none;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 6px;
    line-height: 1;
    transition: color var(--transition);
}
.btn-row-actions:hover {
    color: var(--primary);
}

/* 行下拉菜单 */
.row-dropdown {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 6px 0;
    min-width: 100px;
    z-index: 999;
    display: none;
    flex-direction: column;
}
.row-dropdown .dropdown-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition);
    color: var(--text);
}
.row-dropdown .dropdown-btn:hover {
    background: var(--bg);
}
.row-dropdown .dropdown-btn:first-child {
    color: var(--primary);
}
.row-dropdown .dropdown-btn:last-child {
    color: var(--danger);
}

/* 编辑模态框内表单 */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.edit-field {
    display: flex;
    align-items: center;
    gap: 12px;
}
.edit-field label {
    font-weight: 500;
    min-width: 80px;
    font-size: 14px;
}
.edit-field input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: #F8FAFC;
    outline: none;
    transition: all var(--transition);
}
.edit-field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: #fff;
}
.edit-field input:disabled {
    opacity: 0.6;
    background: #F1F5F9;
    cursor: not-allowed;
}

/* 下载文件名字段：固定时间戳样式 */
.download-name-field { flex-wrap: wrap; }
.download-name-field input { min-width: 120px; }
.fixed-stamp {
    font-weight: 600;
    color: var(--text);
    background: #F1F5F9;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    white-space: nowrap;
}

/* 存档列表 */
.archive-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.archive-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}
.archive-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
    transition: all var(--transition);
}
.archive-item:hover { border-color: var(--primary); background: var(--bg); }
.archive-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}
.archive-info { flex: 1; min-width: 0; }
.archive-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archive-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.archive-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 20px 0; }
.archive-delete {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 6px 8px;
    border-radius: 8px;
    color: var(--danger);
    transition: background var(--transition);
}
.archive-delete:hover { background: var(--danger-light); }

.total-row {
    display:flex; align-items:center; justify-content:space-between;
    padding:8px 12px; font-weight:700; font-size:15px;
    background:#FFFBEB; border-radius:var(--radius-sm); border:1px solid #FCD34D;
}
.scan-status-text { text-align:center; font-size:12px; color:var(--text-muted); }

/* 模态框 */
.modal-overlay {
    position:fixed; inset:0; background:rgba(15,23,42,0.65); backdrop-filter:blur(6px);
    display:flex; align-items:center; justify-content:center; z-index:1000;
    opacity:0; pointer-events:none; transition:opacity var(--transition); padding:20px;
}
.modal-overlay.active { opacity:1; pointer-events:auto; }
.modal-content {
    background:var(--surface); border-radius:var(--radius-xl); width:100%; max-width:500px;
    max-height:80vh; display:flex; flex-direction:column; box-shadow:var(--shadow-lg);
    transform:translateY(20px) scale(0.96); transition:transform var(--transition); overflow:hidden;
}
.modal-overlay.active .modal-content { transform:translateY(0) scale(1); }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:18px 20px; border-bottom:1px solid var(--border); }
.modal-title { font-size:17px; font-weight:700; }
.btn-close-modal { width:36px; height:36px; border-radius:50%; border:none; background:var(--bg); color:var(--text-secondary); cursor:pointer; display:flex; align-items:center; justify-content:center; }
.modal-body { padding:16px 20px; overflow-y:auto; flex:1; }
.confirm-preview { overflow-x:auto; }
.preview-table { width:100%; border-collapse:collapse; font-size:13px; }
.preview-table th, .preview-table td { padding:8px; border:1px solid var(--border); text-align:center; }
.preview-table th { background:#F1F5F9; font-weight:600; }
.modal-footer { padding:14px 20px; border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; }
.btn-cancel { padding:10px 20px; border-radius:20px; border:1px solid var(--border); background:#fff; cursor:pointer; }
.btn-confirm-add { padding:10px 24px; border-radius:20px; border:none; background:var(--primary); color:#fff; font-weight:600; cursor:pointer; }

/* 下载模态框底部布局 */
.download-footer { justify-content: space-between; align-items: center; }
.download-footer .share-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* 冲突模态框底部 */
.conflict-footer { flex-wrap: wrap; }

.toast {
    position:fixed; bottom:40px; left:50%; transform:translateX(-50%) translateY(100px);
    background:#1E293B; color:#fff; padding:12px 24px; border-radius:50px;
    font-size:14px; z-index:2000; pointer-events:none; opacity:0;
    transition:all 0.35s; box-shadow:var(--shadow-lg);
}
.toast.show { transform:translateX(-50%) translateY(0); opacity:1; }
.toast.success { background:var(--success); }
.toast.error { background:var(--danger); }
