:root {
    --purple-900: #2E1065;
    --purple-800: #4C1D95;
    --purple-700: #6D28D9;
    --purple-600: #7C3AED;
    --purple-500: #8B5CF6;
    --purple-200: #DDD6FE;
    --purple-100: #EDE9FE;
    --purple-50:  #F7F5FE;
    --white: #FFFFFF;
    --text: #201A34;
    --text-muted: #6E6784;
    --border: #E9E4F7;
    --success: #15803D;
    --success-bg: #EFFCF3;
    --danger: #B91C1C;
    --danger-bg: #FEF1F1;
    --radius: 8px;
    --sidebar-w: 232px;
    --sidebar-w-collapsed: 72px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--purple-50);
    color: var(--text);
    font-size: 13.5px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a.link { color: var(--purple-700); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--purple-900) 0%, var(--purple-700) 45%, var(--purple-50) 45%, var(--purple-50) 100%);
}
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
    background: var(--white);
    border-radius: 14px;
    padding: 34px 30px;
    box-shadow: 0 20px 50px rgba(46, 16, 101, 0.25);
    border: 1px solid var(--border);
}
.login-mark {
    width: 46px; height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--purple-700), var(--purple-500));
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}
.login-mark svg { width: 24px; height: 24px; }
.login-title { font-size: 19px; margin: 0 0 4px; text-align: center; font-weight: 800; }
.login-sub { text-align: center; color: var(--text-muted); margin: 0 0 22px; font-size: 13px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; margin: 14px 0 5px; color: var(--text-muted); }

input[type=email], input[type=password], input[type=text], input[type=date], input[type=file], select.input-select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13.5px;
    background: var(--white);
    color: var(--text);
    font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--purple-500); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { background: var(--purple-50); border-color: var(--purple-200); }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-primary { background: var(--purple-700); color: #fff; border-color: var(--purple-700); }
.btn-primary:hover { background: var(--purple-800); border-color: var(--purple-800); }
.btn-outline { background: var(--white); }
.btn-block { width: 100%; margin-top: 20px; justify-content: center; }
.btn-remove { color: var(--danger); border-color: var(--border); }
.btn[disabled] { opacity: 0.42; cursor: not-allowed; }

.alert { padding: 10px 13px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #F8C9C9; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #BEEACB; }
.alert-info { background: var(--purple-50); color: var(--purple-800); border: 1px solid var(--purple-200); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: linear-gradient(190deg, var(--purple-900) 0%, var(--purple-800) 55%, var(--purple-700) 100%);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    z-index: 40;
    transition: width 0.18s ease;
    overflow-x: hidden;
}
.sidebar-top { display: flex; align-items: center; gap: 4px; padding: 0 2px 18px; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.14); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-mark {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: rgba(255,255,255,0.14);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { line-height: 1.25; overflow: hidden; white-space: nowrap; }
.brand-text strong { display: block; color: #fff; font-size: 13.5px; font-weight: 700; }
.brand-text span { display: block; color: rgba(255,255,255,0.55); font-size: 11px; }

.collapse-btn {
    width: 26px; height: 26px;
    border-radius: 7px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.collapse-btn:hover { background: rgba(255,255,255,0.2); }
.collapse-btn svg { width: 14px; height: 14px; transition: transform 0.18s; }

.nav-section-label {
    color: rgba(255,255,255,0.4);
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 14px 10px 6px;
    white-space: nowrap;
    overflow: hidden;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: rgba(255,255,255,0.72);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.nav-item.active { background: #fff; color: var(--purple-700); font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.nav-item.active svg { opacity: 1; }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; }
.nav-item .count {
    margin-left: auto;
    font-size: 10.5px;
    background: rgba(255,255,255,0.16);
    color: #fff;
    padding: 1px 7px;
    border-radius: 20px;
    font-weight: 700;
    flex-shrink: 0;
}
.nav-item.active .count { background: var(--purple-100); color: var(--purple-700); }

.sidebar-spacer { flex: 1; }

.sidebar-user {
    border-top: 1px solid rgba(255,255,255,0.14);
    padding-top: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 2px;
    overflow: hidden;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: rgba(255,255,255,0.16);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info { line-height: 1.3; overflow: hidden; white-space: nowrap; }
.sidebar-user-info strong { display: block; font-size: 12px; color: #fff; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.sidebar-user-info a { font-size: 11px; color: rgba(255,255,255,0.55); }
.sidebar-user-info a:hover { color: #fff; }

/* ---------- Collapsed (desktop icon-only) state ---------- */
html.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
html.sidebar-collapsed .brand-text,
html.sidebar-collapsed .nav-section-label,
html.sidebar-collapsed .nav-item .label,
html.sidebar-collapsed .nav-item .count,
html.sidebar-collapsed .sidebar-user-info { display: none; }
html.sidebar-collapsed .sidebar-top { justify-content: center; }
html.sidebar-collapsed .collapse-btn { transform: none; }
html.sidebar-collapsed .collapse-btn svg { transform: rotate(180deg); }
html.sidebar-collapsed .nav-item { justify-content: center; }
html.sidebar-collapsed .sidebar-user { justify-content: center; }
html.sidebar-collapsed .brand { justify-content: center; }

/* ---------- Mobile backdrop ---------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 10, 40, 0.45);
    z-index: 35;
}
.sidebar-backdrop.show { display: block; }
.mobile-menu-btn { display: none; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { margin-left: var(--sidebar-w); min-height: 100vh; transition: margin-left 0.18s ease; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 28px 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-header-left { display: flex; align-items: center; gap: 12px; }
.page-header h1 { font-size: 19px; margin: 0 0 3px; letter-spacing: -0.2px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 12.5px; }
.header-actions { display: flex; gap: 10px; }

.content { padding: 0 28px 32px; }

/* ============================================================
   DASHBOARD TOOLBAR / PANELS
   ============================================================ */
.toolbar-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(46, 16, 101, 0.03);
}
.dash-toolbar-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.input-search {
    flex: 1;
    min-width: 200px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13.5px;
    background: var(--purple-50);
    font-family: inherit;
}
.spacer { flex: 1; }
.result-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 8px;
    padding: 14px;
}
.panel.hidden { display: none; }
.panel-title { font-weight: 700; font-size: 11.5px; color: var(--purple-700); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }

.columns-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px 14px; }
.chk-item { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.chk-item input { accent-color: var(--purple-700); width: 15px; height: 15px; }

.filter-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row .input-select { flex: 0 0 220px; }
.filter-row .input-value, .filter-row .filter-value { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-family: inherit; }
.filter-actions { display: flex; gap: 8px; }
.date-range-block { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }
.date-range-row { display: flex; gap: 18px; flex-wrap: wrap; }
.date-range-row label { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.date-range-row input { width: auto; }

/* ============================================================
   TABLE
   ============================================================ */
.table-scroll {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto;
    max-height: 66vh;
    box-shadow: 0 1px 2px rgba(46, 16, 101, 0.03);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.data-table thead th {
    position: sticky;
    top: 0;
    background: var(--purple-50);
    text-align: left;
    padding: 0;
    font-weight: 700;
    color: var(--purple-800);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    z-index: 5;
    overflow: hidden;
}
.data-table thead th .th-label {
    display: block;
    padding: 10px 16px 10px 14px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table thead th:hover .th-label { background: var(--purple-100); }
.data-table thead th.sorted-asc .th-label::after { content: ' \25B2'; font-size: 8px; }
.data-table thead th.sorted-desc .th-label::after { content: ' \25BC'; font-size: 8px; }
.col-resize-handle {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 6;
}
.col-resize-handle:hover, body.col-resizing .col-resize-handle { background: var(--purple-500); }
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing * { user-select: none; }
.data-table tbody td {
    padding: 9px 14px;
    border-bottom: 1px solid #F3F0FB;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table tbody tr:hover { background: var(--purple-50); }
.loading-cell { text-align: center; padding: 34px; color: var(--text-muted); }

.pagination-bar { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.page-info { font-size: 12.5px; color: var(--text-muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-purple { background: var(--purple-100); color: var(--purple-700); }

/* ============================================================
   UPLOAD / MAPPING
   ============================================================ */
.card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 22px; max-width: 720px; margin: 0 auto; box-shadow: 0 1px 2px rgba(46, 16, 101, 0.03); }
.card h2 { margin-top: 0; font-size: 16px; }
.type-choice { display: flex; gap: 12px; margin: 14px 0 18px; }
.type-card {
    flex: 1;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}
.type-card:hover { border-color: var(--purple-200); }
.type-card.selected { border-color: var(--purple-600); background: var(--purple-50); }
.type-card h3 { margin: 6px 0 4px; font-size: 14px; }
.type-card p { margin: 0; font-size: 12px; color: var(--text-muted); }

.mapping-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.mapping-table th, .mapping-table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.mapping-table th { color: var(--purple-800); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.mapping-table .src-col { font-weight: 600; }
.mapping-table .sample { color: var(--text-muted); font-size: 11.5px; }
.mapping-table select { width: 100%; }

.progress-wrap { margin-top: 18px; }
.progress-bar-outer { background: var(--purple-100); border-radius: 20px; height: 18px; overflow: hidden; }
.progress-bar-inner { background: linear-gradient(90deg, var(--purple-600), var(--purple-700)); height: 100%; width: 0%; transition: width 0.25s; }
.progress-label { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; text-align: center; }

table.preview-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
table.preview-table th, table.preview-table td { border: 1px solid var(--border); padding: 5px 7px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
table.preview-table th { background: var(--purple-50); color: var(--purple-800); }

.step-indicator { display: flex; gap: 6px; margin-bottom: 20px; font-size: 12px; color: var(--text-muted); }
.step-indicator .step.active { color: var(--purple-700); font-weight: 700; }

.hidden { display: none !important; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        width: var(--sidebar-w);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    html.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
    html.sidebar-collapsed .sidebar .brand-text,
    html.sidebar-collapsed .sidebar .nav-section-label,
    html.sidebar-collapsed .sidebar .nav-item .label,
    html.sidebar-collapsed .sidebar .nav-item .count,
    html.sidebar-collapsed .sidebar .sidebar-user-info { display: block; }
    html.sidebar-collapsed .sidebar .nav-item,
    html.sidebar-collapsed .sidebar .brand,
    html.sidebar-collapsed .sidebar .sidebar-user { justify-content: flex-start; }
    .main, html.sidebar-collapsed .main { margin-left: 0; }
    .mobile-menu-btn { display: inline-flex !important; }
    .page-header { padding: 16px 16px 12px; }
    .content { padding: 0 16px 24px; }
    .type-choice { flex-direction: column; }
}
