/* ─── CSS Variables (Light Theme) ────────────────────────── */
:root {
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-card-hover: #f6f8fa;
    --bg-input: #f5f6f8;
    --border: #dfe3e8;
    --border-focus: #3b82f6;
    --text: #1e2330;
    --text-muted: #6b7280;
    --text-dim: #9ca3af;
    --accent: #3b82f6;
    --accent-light: #dbeafe;
    --accent-glow: rgba(59, 130, 246, 0.12);
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.10);
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.10);
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.08);
    --danger-light: #fee2e2;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ─── Layout ─────────────────────────────────────────────── */
.app-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    padding: 0.8rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.online-dot {
    width: 8px; height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(22,163,74,0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(22,163,74,0); }
}

.main-content {
    max-width: 1480px;
    margin: 0 auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1rem;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    overflow-y: auto;
    max-height: 100%;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
    font-weight: 700;
}

/* ─── Upload Area ────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    background: var(--bg);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-zone svg {
    width: 36px; height: 36px;
    stroke: var(--text-muted);
    margin-bottom: 0.5rem;
}

.upload-zone p {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.upload-zone .hint {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 0.3rem;
}

/* ─── Batch List ─────────────────────────────────────────── */
.batch-item {
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
}

.batch-item:hover { background: var(--bg-card-hover); border-color: #cbd5e1; }

.batch-item.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.batch-info .batch-name {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
}

.batch-info .batch-time {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.batch-progress {
    text-align: right;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
}

.batch-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.3rem;
}

/* ─── Recipients List ────────────────────────────────────── */
.recipient-item {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
}

.recipient-item:hover { background: var(--bg-card-hover); border-color: #cbd5e1; }

.recipient-item.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.recipient-item.complete {
    border-color: var(--success);
    background: var(--success-light);
}

.recipient-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
}

.recipient-stats {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: right;
}

.recipient-stats .qty-progress {
    font-weight: 600;
    color: var(--accent);
}

.progress-bar {
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin-top: 0.35rem;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.progress-bar-fill.complete {
    background: var(--success);
}

/* ─── Scanner Area ───────────────────────────────────────── */
.scanner-section {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    max-height: 100%;
    overflow: hidden;
}

.scanner-top-pinned {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.scan-input-wrap {
    position: relative;
}

.scan-input {
    width: 100%;
    padding: 0.9rem 1rem 0.9rem 3rem;
    background: #ffffff;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 700;
    font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    letter-spacing: 2px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

.scan-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow-sm);
}

.scan-input::placeholder {
    color: var(--text-dim);
    font-weight: 400;
    letter-spacing: 0;
    font-size: 0.92rem;
}

.scan-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 22px; height: 22px;
    stroke: var(--text-muted);
}

/* ─── Scan Card Container ────────────────────────────────── */
.scan-card-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 180px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.scan-card {
    display: flex;
    align-items: stretch;
    background: #ffffff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: cardSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    transition: opacity 0.4s, transform 0.4s;
}

.scan-card.fading {
    opacity: 0.5;
    transform: scale(0.97);
}

.scan-card-accent {
    width: 5px;
    flex-shrink: 0;
}

.scan-card.success .scan-card-accent { background: var(--success); }
.scan-card.warning .scan-card-accent { background: var(--warning); }
.scan-card.error .scan-card-accent { background: var(--danger); }

.scan-card-body {
    flex: 1;
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.8rem;
    align-items: center;
    min-width: 0;
}

.scan-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.scan-card.success .scan-card-icon { background: var(--success-light); color: var(--success); }
.scan-card.warning .scan-card-icon { background: var(--warning-light); color: var(--warning); }
.scan-card.error .scan-card-icon { background: var(--danger-light); color: var(--danger); }

.scan-card-icon svg { width: 22px; height: 22px; }

.scan-card-info {
    flex: 1;
    min-width: 0;
}

.scan-card-recipient {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.3;
}

.scan-card-material {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.scan-card-product {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scan-card-meta {
    text-align: right;
    flex-shrink: 0;
    padding-left: 0.5rem;
}

.scan-card-price {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--warning);
}

.scan-card-progress {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.scan-card-progress strong {
    color: var(--success);
}

@keyframes cardSlideIn {
    from { opacity: 0; transform: translateX(40px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

/* ─── Items Table ────────────────────────────────────────── */
.items-table-wrap {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    min-height: 0;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.items-table thead th {
    background: #f8fafc;
    padding: 0.65rem 0.8rem;
    text-align: left;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.8px;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.items-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: all 0.3s;
}

.items-table tbody tr:hover {
    background: #f8fafc;
}

.items-table tbody td {
    padding: 0.55rem 0.8rem;
    vertical-align: middle;
}

.items-table .barcode-cell {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-weight: 600;
    letter-spacing: 1px;
    font-size: 0.78rem;
    color: var(--text);
}

.items-table .price-cell {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    color: var(--warning);
    font-weight: 600;
}

.items-table .qty-cell {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-weight: 600;
}

.items-table tbody tr.scanned {
    background: var(--success-light);
}

.items-table tbody tr.scanned td:first-child {
    box-shadow: inset 4px 0 0 var(--success);
}

.items-table tbody tr.partial-scanned {
    background: #fffbeb;
}

.items-table tbody tr.partial-scanned td:first-child {
    box-shadow: inset 4px 0 0 var(--warning);
}

.items-table tbody tr.just-scanned {
    animation: scanFlash 1.8s ease;
}

@keyframes scanFlash {
    0% { background: rgba(22, 163, 74, 0.35); transform: scale(1.005); }
    25% { background: rgba(22, 163, 74, 0.2); }
    100% { background: var(--success-light); transform: scale(1); }
}

.scan-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
}

.scan-status-badge.pending {
    background: #f1f5f9;
    color: var(--text-dim);
}

.scan-status-badge.partial {
    background: var(--warning-light);
    color: var(--warning);
}

.scan-status-badge.done {
    background: var(--success-light);
    color: var(--success);
}

/* ─── Summary Bar ────────────────────────────────────────── */
.summary-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.6rem;
}

.summary-stat {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.8rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.summary-stat .stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.summary-stat .stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--text);
    font-size: 0.76rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: #cbd5e1; }

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-accent:hover { background: #2563eb; }

.btn-danger {
    border-color: #fca5a5;
    color: var(--danger);
    background: #fff;
}

.btn-danger:hover { background: var(--danger-light); }

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.68rem; }

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    color: var(--text-dim);
    text-align: center;
}

.empty-state svg {
    width: 56px; height: 56px;
    stroke: var(--text-dim);
    margin-bottom: 0.8rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font-weight: 600;
}

.empty-state p { font-size: 0.82rem; }

/* ─── Toast Notifications ────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 65px;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    min-width: 260px;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.82rem;
}

.toast.toast-out { animation: toastOut 0.3s ease forwards; }

.toast-success { border-left: 4px solid var(--success); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--accent); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(30px); }
}

/* ─── Scanner Name Input ─────────────────────────────────── */
.scanner-name-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.scanner-name-wrap label {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 600;
}

.scanner-name-wrap input {
    flex: 1;
    padding: 0.35rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.82rem;
    outline: none;
}

.scanner-name-wrap input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ─── Loading ────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.show { display: flex; }

.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Celebration Overlay ────────────────────────────────── */
.celebration-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    animation: fadeIn 0.3s ease;
}

.celebration-overlay.show { display: flex; }

.celebration-card {
    background: #ffffff;
    border: 3px solid var(--success);
    border-radius: 20px;
    padding: 2.5rem 3.5rem;
    text-align: center;
    box-shadow: 0 20px 60px rgba(22, 163, 74, 0.2);
    animation: celebrationPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.celebration-card .celebration-icon {
    width: 64px; height: 64px;
    background: var(--success-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.celebration-card .celebration-icon svg {
    width: 32px; height: 32px;
    stroke: var(--success);
    stroke-width: 2.5;
}

.celebration-card h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--success);
    margin-bottom: 0.3rem;
}

.celebration-card p {
    font-size: 1rem;
    color: var(--text-muted);
}

.celebration-card .celebration-name {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text);
    margin: 0.5rem 0;
}

@keyframes celebrationPop {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .sidebar { order: 2; }
    .scanner-section { order: 1; }
}

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ─── View All button ────────────────────────────────────── */
.recipient-item.view-all {
    justify-content: center;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.82rem;
    background: var(--accent-light);
    border-color: transparent;
}

.recipient-item.view-all:hover {
    background: var(--accent-glow);
}
