:root {
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: rgba(99, 102, 241, 0.15);
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --card-border: rgba(15, 23, 42, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
    --radius: 12px;
    --radius-lg: 16px;
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #06b6d4 100%);
    --gradient-card: linear-gradient(135deg, rgba(99,102,241,0.08) 0%, rgba(6,182,212,0.05) 100%);
}

[data-bs-theme="dark"] {
    --body-bg: #0b1120;
    --card-bg: #111827;
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --gradient-card: linear-gradient(135deg, rgba(99,102,241,0.12) 0%, rgba(6,182,212,0.08) 100%);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--body-bg);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── App Layout ── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    flex: 1;
}

.sidebar-nav .nav-section {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 0.75rem 0.75rem 0.5rem;
}

.sidebar-nav .nav-link {
    color: #94a3b8;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 2px;
    text-decoration: none;
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    color: #e2e8f0;
    background: var(--sidebar-hover);
}

.sidebar-nav .nav-link.active {
    color: #fff;
    background: var(--sidebar-active);
    box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #cbd5e1;
    font-size: 0.85rem;
}

.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 0.85rem;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
}

.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-sm);
}

.topbar-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.topbar-title .breadcrumb-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-content {
    padding: 1.5rem;
    flex: 1;
}

.app-footer {
    padding: 1rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--card-border);
}

/* ── Cards & Panels ── */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.panel-header h5 {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel-body { padding: 1.5rem; }
.panel-body.flush { padding: 0; }

/* ── Stat Cards ── */
.stat-card-v2 {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    height: 100%;
}

.stat-card-v2:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-card-v2::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.stat-card-v2.stat-primary::before { background: var(--gradient-primary); }
.stat-card-v2.stat-success::before { background: linear-gradient(90deg, #10b981, #34d399); }
.stat-card-v2.stat-info::before { background: linear-gradient(90deg, #06b6d4, #22d3ee); }
.stat-card-v2.stat-danger::before { background: linear-gradient(90deg, #ef4444, #f87171); }
.stat-card-v2.stat-warning::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }

.stat-card-v2 .stat-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

.stat-card-v2 .stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.stat-card-v2 .stat-icon-wrap {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    opacity: 0.9;
}

.stat-primary .stat-icon-wrap { background: rgba(99,102,241,0.12); color: var(--primary); }
.stat-success .stat-icon-wrap { background: rgba(16,185,129,0.12); color: var(--success); }
.stat-info .stat-icon-wrap { background: rgba(6,182,212,0.12); color: var(--accent); }
.stat-danger .stat-icon-wrap { background: rgba(239,68,68,0.12); color: var(--danger); }

.stat-card-v2 .stat-trend {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* ── Status Badges ── */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.status-new { background: rgba(6,182,212,0.15); color: #0891b2; }
.status-unused { background: rgba(99,102,241,0.15); color: #4f46e5; }
.status-used { background: rgba(16,185,129,0.15); color: #059669; }
.status-expired { background: rgba(245,158,11,0.15); color: #d97706; }
.status-blocked { background: rgba(239,68,68,0.15); color: #dc2626; }
.status-default { background: rgba(100,116,139,0.15); color: #475569; }

[data-bs-theme="dark"] .status-new { color: #22d3ee; }
[data-bs-theme="dark"] .status-unused { color: #818cf8; }
[data-bs-theme="dark"] .status-used { color: #34d399; }
[data-bs-theme="dark"] .status-expired { color: #fbbf24; }
[data-bs-theme="dark"] .status-blocked { color: #f87171; }

/* ── Buttons ── */
.btn-gradient {
    background: var(--gradient-primary);
    border: none;
    color: #fff;
    font-weight: 600;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    transition: opacity 0.2s, transform 0.2s;
}

.btn-gradient:hover {
    opacity: 0.9;
    color: #fff;
    transform: translateY(-1px);
}

.btn-gradient:disabled {
    opacity: 0.6;
    transform: none;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    transition: all 0.2s;
}

.btn-ghost:hover {
    background: var(--gradient-card);
    border-color: var(--primary);
    color: var(--primary);
}

/* ── Upload Zone ── */
.upload-zone-v2 {
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--gradient-card);
    position: relative;
}

.upload-zone-v2 .upload-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-zone-v2:hover,
.upload-zone-v2.dragover {
    border-color: var(--primary);
    background: rgba(99,102,241,0.06);
    transform: scale(1.005);
}

.upload-zone-v2 .upload-icon-lg {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #fff;
    box-shadow: 0 8px 20px rgba(99,102,241,0.3);
}

.upload-zone-v2 h5 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* ── File Queue ── */
.file-queue {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.file-queue-item {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.3s;
    position: relative;
}

.file-queue-item.processing { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,0.2); }
.file-queue-item.success,
.file-queue-item.created { border-color: var(--success); }
.file-queue-item.merged { border-color: var(--accent); }
.file-queue-item.duplicate { border-color: var(--warning); }
.file-queue-item.error { border-color: var(--danger); }

.file-queue-item .thumb {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: var(--body-bg);
}

.file-queue-item .file-info {
    padding: 0.75rem;
}

.file-queue-item .file-name {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.file-queue-item .file-status {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.file-queue-item .remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.file-queue-item:hover .remove-btn { opacity: 1; }

.file-queue-item .progress-bar-wrap {
    height: 3px;
    background: var(--card-border);
}

.file-queue-item .progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    width: 0%;
    transition: width 0.3s;
}

/* ── Bulk Summary ── */
.bulk-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.bulk-summary .summary-item {
    text-align: center;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--gradient-card);
    border: 1px solid var(--card-border);
}

.bulk-summary .summary-item .num {
    font-size: 1.75rem;
    font-weight: 800;
}

.bulk-summary .summary-item .lbl {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Tables ── */
.table-modern {
    margin: 0;
}

.table-modern thead th {
    background: var(--gradient-card);
    border-bottom: 1px solid var(--card-border);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    padding: 0.85rem 1.25rem;
    white-space: nowrap;
}

.table-modern tbody td {
    padding: 0.85rem 1.25rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.875rem;
}

.table-modern tbody tr:hover {
    background: var(--gradient-card);
}

.table-modern tbody tr:last-child td {
    border-bottom: none;
}

/* ── Charts ── */
.chart-container {
    position: relative;
    height: 280px;
}

/* ── Login Page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--sidebar-bg);
    overflow: hidden;
}

.login-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
    position: relative;
}

.login-left::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-primary);
    opacity: 0.08;
}

.login-left .hero-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
    position: relative;
}

.login-left .hero-sub {
    color: #94a3b8;
    font-size: 1.1rem;
    margin-top: 1rem;
    position: relative;
}

.login-left .hero-features {
    margin-top: 2.5rem;
    position: relative;
}

.login-left .hero-features .feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #cbd5e1;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.login-left .hero-features .feature i {
    color: var(--primary-light);
    font-size: 1.1rem;
}

.login-right {
    width: 480px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--body-bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-xl);
}

.login-card .login-logo {
    width: 56px;
    height: 56px;
    background: var(--gradient-primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 1.5rem;
}

.form-control-modern {
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.7rem 1rem;
    background: var(--body-bg);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control-modern:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
    background: var(--card-bg);
    color: var(--text-primary);
}

/* ── Card Image ── */
.card-image {
    max-width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    object-fit: contain;
}

/* ── Duplicate Alert ── */
.duplicate-panel {
    border-left: 4px solid var(--danger);
    background: rgba(239,68,68,0.05);
}

/* ── Quick Actions ── */
.quick-action {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
    background: var(--card-bg);
}

.quick-action:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
}

.quick-action .qa-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* ── Animations ── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeInUp 0.4s ease forwards;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.processing-pulse {
    animation: pulse 1.5s ease infinite;
}

/* ── Responsive ── */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .login-left { display: none; }
    .login-right { width: 100%; }

    .bulk-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 576px) {
    .page-content { padding: 1rem; }
    .stat-card-v2 .stat-value { font-size: 1.5rem; }
    .file-queue { grid-template-columns: 1fr 1fr; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
