:root, [data-theme="light"] {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --table-header-bg: #f8fafc;
    --table-row-border: #f1f5f9;
    --row-finished: #d1fae5;
    --row-failed: #fee2e2;
    --row-disabled: #e5e7eb;
    --row-deleted: #fce7f3;
    --row-mdm-completed: #dbeafe;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #3b82f6;
    --sidebar-text: #64748b;
    --sidebar-text-active: #e2e8f0;
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --table-header-bg: #1e293b;
    --table-row-border: #334155;
    --row-finished: #064e3b;
    --row-failed: #7f1d1d;
    --row-disabled: #374151;
    --row-deleted: #831843;
    --row-mdm-completed: #1e3a8a;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    background: var(--body-bg);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
}

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.025em;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.sidebar-brand:hover { color: #fff; text-decoration: none; }

.sidebar-brand svg {
    flex-shrink: 0;
}

.sidebar-section {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.8125rem;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.sidebar-nav a.active {
    background: rgba(37, 99, 235, 0.12);
    color: var(--sidebar-text-active);
    border-left-color: var(--sidebar-active);
    font-weight: 500;
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.75rem;
}

.sidebar-footer .user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #cbd5e1;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.user-info { line-height: 1.3; }
.user-info .name { font-weight: 500; color: #e2e8f0; }
.user-info .role { color: #64748b; font-size: 0.675rem; }

/* --- Dark mode toggle --- */
.btn-dark-mode {
    background: none;
    border: 1px solid #475569;
    border-radius: 0.25rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px 6px;
    display: flex;
    align-items: center;
}
.btn-dark-mode:hover { color: #e2e8f0; border-color: #64748b; }

/* --- Mobile sidebar --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.sidebar-overlay.active { display: block; }

.btn-hamburger {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
    display: none;
}

/* --- Main content --- */
.main-content {
    margin-left: 240px;
    flex: 1;
    min-width: 0;
}

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h1 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.topbar .breadcrumb-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.company-logo {
    display: flex;
    align-items: center;
}

.company-logo img {
    height: 32px;
    width: auto;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.company-logo img:hover {
    opacity: 1;
}

/* --- Global Time Filter --- */
.global-time-filter {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 57px; /* Below topbar */
    z-index: 49;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.time-filter-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.time-filter-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.time-filter-label svg {
    color: var(--primary);
}

.time-filter-select {
    width: auto;
    min-width: 160px;
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
}

.custom-date-range {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.date-input {
    width: auto;
    min-width: 140px;
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
}

.date-separator {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.time-filter-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--success);
    padding: 0.25rem 0.625rem;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 4px;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .global-time-filter {
        top: 0;
        position: relative;
    }

    .time-filter-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .time-filter-select,
    .date-input {
        width: 100%;
    }
}

.content-area {
    padding: 1.5rem;
}

/* --- Stats cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    text-align: center;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-done .stat-value { color: var(--success); }
.stat-active .stat-value { color: var(--primary); }
.stat-failed .stat-value { color: var(--danger); }
.stat-disabled .stat-value { color: var(--text-secondary); }

/* --- Cards --- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
}

/* --- Home cards --- */
.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.home-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    transition: box-shadow 0.15s, border-color 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.home-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
    color: inherit;
    text-decoration: none;
}

.home-card .card-icon {
    width: 36px;
    height: 36px;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.home-card .card-icon.view { background: #eff6ff; color: var(--primary); }
.home-card .card-icon.action { background: #f0fdf4; color: var(--success); }

[data-theme="dark"] .home-card .card-icon.view { background: #1e3a5f; }
[data-theme="dark"] .home-card .card-icon.action { background: #14532d; }

.home-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
}

.home-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.toolbar .form-select,
.toolbar .form-control {
    font-size: 0.8125rem;
    height: 2rem;
    padding: 0.25rem 0.5rem;
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border);
}

.toolbar .btn {
    font-size: 0.8125rem;
    height: 2rem;
    padding: 0.25rem 0.75rem;
}

.toolbar .row-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.auto-refresh-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}
.auto-refresh-toggle input { cursor: pointer; }
.auto-refresh-toggle input:checked ~ svg { color: var(--success); }

/* --- Column picker --- */
.column-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.75rem;
}
.column-picker label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    white-space: nowrap;
    color: var(--text-primary);
}

/* --- Color legend --- */
.color-legend {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.75rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}
.legend-color {
    width: 20px;
    height: 14px;
    border-radius: 0.25rem;
    flex-shrink: 0;
    border: 1px solid var(--border);
}
.legend-finished {
    background: var(--row-finished);
}
.legend-failed {
    background: var(--row-failed);
}
.legend-progress {
    background: var(--card-bg);
}
.legend-disabled {
    background: var(--row-disabled);
}
.legend-deleted {
    background: var(--row-deleted);
}
.legend-mdm-completed {
    background: var(--row-mdm-completed);
}
.legend-label {
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- Interactive legend (clickable status filter) --- */
.clickable-legend-item {
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.15s, opacity 0.15s;
    user-select: none;
}

.clickable-legend-item:hover {
    background: var(--table-row-border);
}

.clickable-legend-item.legend-selected {
    opacity: 1;
}

.clickable-legend-item.legend-unselected {
    opacity: 0.35;
}

.clickable-legend-item.legend-unselected:hover {
    opacity: 0.6;
}

/* --- Data table --- */
.data-table-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table thead th {
    background: var(--table-header-bg);
    border-bottom: 2px solid var(--border);
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table thead th a {
    color: var(--text-secondary);
    text-decoration: none;
}

.data-table thead th a:hover {
    color: var(--primary);
}

.data-table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--table-row-border);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    filter: brightness(0.95);
}

[data-theme="dark"] .data-table tbody tr:hover {
    filter: brightness(1.15);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Row status colors --- */
.data-table tbody tr.row-finished {
    background: var(--row-finished);
}

.data-table tbody tr.row-failed {
    background: var(--row-failed);
}

.data-table tbody tr.row-disabled {
    background: var(--row-disabled);
}

.data-table tbody tr.row-deleted {
    background: var(--row-deleted);
    text-decoration: line-through;
    opacity: 0.85;
}

.data-table tbody tr.row-mdm-completed {
    background: var(--row-mdm-completed);
}

.data-table tbody tr.row-progress {
    position: relative;
}


/* Status indicators */
.status-indicator {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    vertical-align: middle;
}

/* In-progress indicator (animated dots) */
.progress-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

.progress-indicator .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
    animation: dot-pulse 1.4s infinite ease-in-out both;
}

.progress-indicator .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.progress-indicator .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.progress-indicator .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes dot-pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Success/Finished indicator */
.success-indicator {
    color: #22c55e;
}

/* Failed indicator */
.failed-indicator {
    color: #ef4444;
}

/* Disabled indicator */
.disabled-indicator {
    color: #94a3b8;
}

/* --- Top scrollbar mirror --- */
.scroll-top-mirror {
    overflow-x: auto;
    overflow-y: hidden;
    height: 12px;
    border-bottom: 1px solid var(--border);
}

.scroll-top-mirror > div {
    height: 1px;
}

/* --- Pagination --- */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--table-header-bg);
}

.pagination {
    margin: 0;
}

.pagination .page-link {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    color: var(--text-secondary);
    border-color: var(--border);
    background: var(--card-bg);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* --- Form --- */
.proc-form {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    max-width: 640px;
}

.proc-form .form-label {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.proc-form .form-text {
    font-size: 0.75rem;
}

.proc-form .form-control,
.proc-form .form-select {
    font-size: 0.8125rem;
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border);
}

.proc-form .required-mark {
    color: var(--danger);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* --- Alerts --- */
.alert {
    font-size: 0.8125rem;
    border-radius: 0.375rem;
    padding: 0.6rem 1rem;
}

/* --- Toast notifications --- */
.toast-notification {
    background: var(--primary);
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* --- Modal dark mode --- */
[data-theme="dark"] .modal-content {
    background: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border);
}

/* --- Migration Type Selection Modal --- */
.migration-type-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.migration-type-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--card-bg);
    border: 1.5px solid var(--border);
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s ease;
    cursor: pointer;
}

.migration-type-option:hover {
    background: var(--table-row-border);
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
    text-decoration: none;
    color: var(--text-primary);
    transform: translateY(-1px);
}

.migration-type-icon {
    width: 44px;
    height: 44px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.migration-type-content {
    flex: 1;
    min-width: 0;
}

.migration-type-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.migration-type-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 0.375rem;
}

.migration-type-badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--table-row-border);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.migration-type-arrow {
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.migration-type-option:hover .migration-type-arrow {
    color: var(--primary);
    transform: translateX(3px);
}

[data-theme="dark"] .migration-type-option:hover {
    background: var(--sidebar-hover);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

/* --- Responsive --- */
.table-responsive {
    overflow-x: auto;
    max-height: calc(100vh - 220px);
}

@media (max-width: 1200px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; }
    .content-area { padding: 1rem; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .content-area { padding: 0.75rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .form-select,
    .toolbar .form-control { width: 100% !important; }
    .btn-hamburger { display: block; }
}
