/* 
  Data Refine - Main Styles
  
  Tokens:
  - --bg-page: Application background gradient
  - --surface-*: Layer colors (glassmorphism/neumorphism base)
  - --accent: Primary brand color
  - --text-*: Typography colors
  
  supports Light/Dark mode via body.dark-mode class.
*/

/* ======================== ROOT TOKENS ======================== */
:root {
    --bg-page: linear-gradient(180deg, #6fb0e6 0%, #c6def7 100%);
    --surface-1: rgba(255, 255, 255, 0.94);
    --surface-2: #ffffff;
    --surface-3: #f2f6fb;

    --text-primary: #123043;
    --text-muted: #6b7785;
    --accent: #3175bd;
    --accent-strong: #2b66a7;
    --success: #36b37e;

    --card-border: rgba(34, 60, 84, 0.06);
    --control-border: rgba(18, 48, 67, 0.12);
    --focus-ring: rgba(49, 117, 189, 0.25);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.08);
}

/* ======================== DARK MODE TOKENS ======================== */
body.dark-mode {
    --bg-page: linear-gradient(180deg, #0e2130 0%, #12202a 100%);
    --surface-1: rgba(18, 26, 34, 0.72);
    --surface-2: rgba(18, 26, 34, 0.86);
    --surface-3: rgba(255, 255, 255, 0.03);

    --text-primary: #e6eef6;
    --text-muted: #9aa7b6;
    --accent: #4a90e2;
    --accent-strong: #3b78c5;

    --card-border: rgba(255, 255, 255, 0.06);
    --control-border: rgba(255, 255, 255, 0.08);
    --focus-ring: rgba(74, 144, 226, 0.22);
}

/* ======================== BASE RESET ======================== */
* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-page);
    background-repeat: no-repeat;
    background-size: cover;
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    padding: 20px;
    display: block;
    overflow-y: auto;
}

/* ======================== FOOTER ======================== */
footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ======================== GLASS CONTAINERS ======================== */
.glass-container {
    background: var(--surface-1);
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    width: 100%;
    max-width: 1100px;
    margin: 20px auto;
}

/* ======================== CONFIG SCREEN ======================== */
#config-ui {
    max-width: 520px;
    width: 100%;
    margin: 28px auto;
    padding: 18px;
}

/* ======================== HEADERS ======================== */
.main-header,
.config-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
    position: relative;
}

.logo-wrap {
    position: absolute;
    left: 0;
}

.logo-img {
    height: 44px;
    max-width: 120px;
}

.centered-header-text {
    text-align: center;
    width: 100%;
}

/* ======================== MAIN UI WRAPPER ======================== */
#main-ui {
    max-width: 1100px;
    width: 100%;
    margin: 18px auto;
    padding: 18px;
}

#main-ui .neumorphic-card {
    width: 100%;
}

/* ======================== GRID LAYOUT ======================== */
#main-ui>.row {
    display: block;
}

@media (min-width: 1000px) {
    #main-ui>.row {
        display: grid;
        grid-template-columns: 44% 54%;
        gap: 24px;
        align-items: start;
    }
}

/* ======================== CARDS ======================== */
.neumorphic-card {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 18px;
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
    transition: transform .22s ease, box-shadow .22s ease;
}

.neumorphic-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

/* ======================== CARD HEADERS ======================== */
.card-header {
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
}

/* ======================== FORM ======================== */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.95rem;
}

/* ======================== INPUTS ======================== */
.form-control,
.form-select {
    appearance: none;
    background-color: var(--surface-3);
    color: var(--text-primary);
    border-radius: 10px;
    border: 1px solid var(--control-border);
    padding: 10px 14px;
    width: 100%;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border .2s ease, box-shadow .2s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-control::placeholder {
    color: var(--text-muted);
}

/* ======================== DROPDOWNS ======================== */
.form-select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%233175bd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 16px 12px;
    padding-right: 2.5rem;
    border-radius: 12px;
}

body.dark-mode .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%234a90e2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

.form-select option {
    background: var(--surface-2);
    color: var(--text-primary);
}

body.dark-mode .form-select option {
    background: #121a22;
    color: var(--text-primary);
}

/* ======================== MULTI SELECT ======================== */
#refColumns {
    border-radius: 12px;
    padding: 8px;
    min-height: 120px;
    width: 100%;
}

#refColumns option {
    padding: 8px 10px;
    border-radius: 8px;
    margin: 4px 0;
}

#refColumns option:checked {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: white;
}

/* ======================== BUTTONS ======================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: white;
    border: none;
}

.btn-secondary {
    background: var(--surface-3);
    color: var(--text-muted);
    border: 1px solid var(--control-border);
}

/* ======================== CHECKBOX GRID ======================== */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.checkbox-item {
    padding: 10px;
    border-radius: 8px;
    background: var(--surface-1);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.18s ease;
}

.checkbox-item:hover {
    background: var(--surface-3);
    transform: translateY(-1px);
}

.checkbox-item:active {
    transform: scale(0.98);
}

/* ======================== PROGRESS BAR (FIXED) ======================== */
.progress-container {
    width: 100%;
    background: var(--surface-3);
    border-radius: 999px;
    height: 20px;
    margin-top: 12px;
    border: 1px solid var(--control-border);
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(135deg, var(--success), #2bb673);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 600;
    font-size: 12px;
    transition: width 0.35s ease;
}

/* ======================== HEADINGS ======================== */
#mainTitle {
    color: var(--accent);
    font-weight: 800;
    letter-spacing: 0.6px;
}

#subTitle {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 1rem;
    margin-top: 6px;
}

/* ======================== LIGHT MODE CARD DEPTH ======================== */
body:not(.dark-mode) .neumorphic-card {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

/* ======================== THEME TOGGLE (RESTORED) ======================== */
.theme-switch-wrapper-fixed {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1200;
}

.theme-switch {
    display: inline-block;
    height: 30px;
    width: 58px;
    position: relative;
}

.theme-switch input {
    display: none;
}

.slider {
    position: relative;
    display: block;
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: linear-gradient(to right, #ffe259 0%, #ffa751 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
    transition: all .28s ease;
    cursor: pointer;
}

.slider:before {
    content: "";
    position: absolute;
    left: 4px;
    top: 4px;
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}

.theme-switch .bi {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    z-index: 2;
    pointer-events: none;
}

.icon-moon {
    left: 8px;
    color: rgba(0, 0, 0, .4);
    opacity: 0;
}

.icon-sun {
    right: 8px;
    color: #fff;
    opacity: 1;
}

input:checked+.slider {
    background: linear-gradient(to right, #141e30 0%, #243b55 100%);
    border-color: rgba(255, 255, 255, 0.2);
}

input:checked+.slider:before {
    transform: translateX(28px);
    background: var(--accent);
}

input:checked+.slider .icon-moon {
    opacity: 1;
    color: #f7d97c;
}

input:checked+.slider .icon-sun {
    opacity: 0;
}

/* ===================== SLIDER (RANGE INPUT) FIX ===================== */
input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-3);
    border-radius: 6px;
    outline: none;
    border: 1px solid var(--control-border);
}

/* Track */
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    border-radius: 6px;
}

/* Thumb */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface-1);
    border: 2px solid var(--accent);
    cursor: pointer;
    margin-top: -6px;
    /* centers the thumb */
    transition: 0.2s ease;
}

/* Thumb hover */
input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--accent);
    border-color: var(--accent-strong);
}

/* Firefox support */
input[type="range"]::-moz-range-track {
    height: 6px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    border-radius: 6px;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface-1);
    border: 2px solid var(--accent);
    cursor: pointer;
}

.drop-zone {
    background: var(--surface-2);
    border: 2px dashed var(--accent);
    padding: 22px 20px;
    margin-bottom: 20px;
    border-radius: 18px;
    text-align: center;
    cursor: pointer;
    transition: all .25s ease;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.06);
}

.drop-zone.dragover {
    background: var(--accent);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    transform: scale(1.01);
}

body.dark-mode .drop-zone {
    border-color: var(--accent-strong);
}

.browse-text {
    display: block;
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.icon-upload {
    font-size: 32px;
    margin-bottom: 12px;
    color: var(--accent);
    transition: .25s ease;
    opacity: 0.9;
}

.drop-zone.dragover .icon-upload {
    color: white;
    transform: translateY(-3px);
}

/* ======================== KPI BOXES ======================== */
.kpi-box {
    background: var(--surface-3);
    border: 1px solid var(--control-border);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
}

.kpi-box.total {
    border-color: var(--accent);
    background: rgba(49, 117, 189, 0.1);
}

.kpi-box.processed {
    border-color: #6404ff;
    background: rgba(100, 4, 255, 0.1);
}

.kpi-box.avg-conf {
    border-color: #e83e8c;
    background: rgba(232, 62, 140, 0.1);
}

/* --- Table Styling --- */
.custom-table {
    width: 100%;
    max-width: 380px;
    margin: 10px auto;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--control-border);
    border-radius: 10px;
    overflow: hidden;
}

.custom-table th,
.custom-table td {
    padding: 8px 16px;
    /* Balanced padding */
    border: none;
    /* Remove default borders */
    border-bottom: 1px solid var(--control-border);
    text-align: left;
    font-size: 0.85rem;
}

.custom-table th {
    background: var(--surface-3);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

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

.custom-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.kpi-box.success {
    border-color: var(--success);
    background: rgba(54, 179, 126, 0.1);
}

.kpi-box.warning {
    border-color: #ffab00;
    background: rgba(255, 171, 0, 0.1);
}

.kpi-box.error {
    border-color: #ff5630;
    background: rgba(255, 86, 48, 0.1);
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ======================== CUSTOM DROPDOWN (JS REPLACEMENT) ======================== */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select-wrapper select {
    display: none;
    /* Native select is hidden */
}

/* The Trigger (Closed State) */
.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--surface-3);
    color: var(--text-primary);
    border: 1px solid var(--control-border);
    border-radius: 12px;
    padding: 8px 12px;
    /* Reduced padding */
    font-size: 0.95rem;
    /* Match input size */
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 38px;
    /* Reduced min-height */
}

.custom-select-trigger:hover {
    border-color: var(--accent);
}

/* Arrow Icon */
.custom-select-trigger::after {
    content: '';
    width: 14px;
    /* Slightly smaller arrow */
    height: 16px;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%233175bd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: transform 0.3s ease;
    margin-left: 10px;
}

body.dark-mode .custom-select-trigger::after {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%234a90e2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

/* Rotate arrow when open */
.custom-select-wrapper.open .custom-select-trigger::after {
    transform: rotate(180deg);
}

.custom-select-wrapper.open .custom-select-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* The Options List (Open State) */
.custom-options {
    position: absolute;
    display: block;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-1);
    border: 1px solid var(--accent);
    border-top: none;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25);
    max-height: 250px;
    overflow-y: auto;
    padding: 4px;
    /* Reduced padding */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.custom-select-wrapper.open .custom-options {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transform: translateY(0);
}

/* Individual Option */
.custom-option {
    display: block;
    padding: 8px 12px;
    /* Reduced padding */
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    /* Inner radius for items */
    transition: background 0.15s ease;
    margin-bottom: 2px;
}

.custom-option:hover {
    background: var(--surface-3);
    color: var(--accent);
}

.custom-option.selected {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: white;
}

/* Scrollbar for options */
.custom-options::-webkit-scrollbar {
    width: 6px;
}

.custom-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-options::-webkit-scrollbar-thumb {
    background: var(--control-border);
    border-radius: 10px;
}

.custom-options::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}