/* ===== RESET & BASE ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #1a1a1a;
    --secondary: #4a4a4a;
    --muted: #8a8a8a;
    --light: #e5e5e5;
    --lighter: #f5f5f5;
    --bg: #fafafa;
    --white: #ffffff;
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--light);
}

.logo {
    font-size: 36px;
    line-height: 1;
}

.title-group h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.title-group p {
    font-size: 14px;
    color: var(--secondary);
    margin-top: 2px;
}

/* ===== STEP INDICATOR ===== */
.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 32px;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    opacity: 0.4;
    transition: var(--transition);
}

.step.active {
    opacity: 1;
}

.step.completed {
    opacity: 1;
}

.step-num {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition);
}

.step.active .step-num {
    background: var(--primary);
    color: var(--white);
}

.step.completed .step-num {
    background: var(--success);
    color: var(--white);
}

.step-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--secondary);
}

.step-line {
    width: 60px;
    height: 2px;
    background: var(--light);
    margin: 0 8px;
    margin-bottom: 22px;
}

/* ===== STEP PANELS ===== */
.step-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.step-panel.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
    border: 2px dashed var(--light);
    border-radius: var(--radius-lg);
    padding: 60px 24px;
    text-align: center;
    background: var(--white);
    transition: var(--transition);
    cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--lighter);
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.upload-zone h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 6px;
}

.upload-zone p {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 16px;
}

/* ===== BUTTONS ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--white);
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.btn-primary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--light);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--primary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: var(--lighter);
}

.btn-secondary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-ghost:hover {
    color: var(--primary);
    background: var(--lighter);
}

.btn-ghost:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== DATA PREVIEW ===== */
.data-preview {
    margin-top: 24px;
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--light);
    overflow: hidden;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: var(--lighter);
    border-bottom: 1px solid var(--light);
}

.preview-header h4 {
    font-size: 14px;
    font-weight: 600;
}

.badge {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--success-light);
    color: var(--success);
    font-weight: 600;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--secondary);
    background: var(--lighter);
    border-bottom: 1px solid var(--light);
    position: sticky;
    top: 0;
    white-space: nowrap;
}

.data-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--light);
    white-space: nowrap;
}

.data-table tr:hover td {
    background: var(--lighter);
}

.preview-actions {
    padding: 16px 20px;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--light);
}

/* ===== CONFIG GRID ===== */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.config-card {
    background: var(--white);
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.config-card.wide {
    grid-column: 1 / -1;
}

.config-card h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.config-card select,
.config-card input[type="range"] {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--light);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--primary);
    cursor: pointer;
}

.config-card select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%234a4a4a' viewBox='0 0 16 16'%3E%3Cpath d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    padding-right: 36px;
}

.config-card select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--accent);
}

.config-card input[type="range"] {
    padding: 0;
    margin-top: 8px;
}

.range-display {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
    margin-top: 8px;
}

.range-value {
    font-weight: 600;
    color: var(--primary);
}

.hint {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
}

.placeholder {
    font-size: 14px;
    color: var(--muted);
    padding: 12px 0;
    text-align: center;
    width: 100%;
}

/* Feature selector */
.feature-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.feature-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    background: var(--accent-light);
    color: var(--accent);
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.feature-tag:hover {
    opacity: 0.8;
}

.feature-tag:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.feature-tag.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--white);
}

.feature-tag .check {
    display: none;
}

.feature-tag.selected .check {
    display: inline;
}

/* ===== PROGRESS ===== */
.progress-area {
    margin-bottom: 20px;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--light);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.progress-text {
    text-align: center;
    font-size: 13px;
    color: var(--secondary);
    margin-top: 10px;
}

/* ===== CONFIG ACTIONS ===== */
.config-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
}

/* ===== METRICS BAR ===== */
.metrics-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--white);
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
}

.metric-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.metric-label {
    font-size: 12px;
    color: var(--secondary);
    margin-top: 4px;
    font-weight: 500;
}

/* ===== RESULTS GRID ===== */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.plot-card {
    background: var(--white);
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.plot-card.wide {
    grid-column: 1 / -1;
}

.plot-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--secondary);
}

.plot-card canvas {
    width: 100% !important;
    height: 300px !important;
    max-height: 350px;
}

/* Heatmap specific */
#plot-heatmap {
    overflow-x: auto;
}

.heatmap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.heatmap-table th {
    padding: 8px 10px;
    font-weight: 600;
    color: var(--secondary);
    background: var(--lighter);
    border: 1px solid var(--light);
    text-align: center;
    white-space: nowrap;
}

.heatmap-table td {
    padding: 8px 10px;
    border: 1px solid var(--light);
    text-align: center;
    font-weight: 500;
    color: var(--primary);
    min-width: 60px;
}

.heatmap-table td:first-child,
.heatmap-table th:first-child {
    text-align: left;
    font-weight: 600;
    background: var(--lighter);
    position: sticky;
    left: 0;
    z-index: 1;
}

.heatmap-row-label {
    font-size: 11px;
    color: var(--secondary);
}

/* ===== SEGMENTS ===== */
.segments-section {
    margin-bottom: 24px;
}

.segments-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.segment-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.segment-card {
    background: var(--white);
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: var(--transition);
}

.segment-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.segment-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.segment-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.segment-name {
    font-size: 15px;
    font-weight: 600;
}

.segment-count {
    font-size: 12px;
    color: var(--muted);
    margin-left: auto;
}

.segment-stat {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
    border-bottom: 1px solid var(--lighter);
}

.segment-stat:last-child {
    border-bottom: none;
}

.segment-stat .stat-label {
    color: var(--secondary);
}

.segment-stat .stat-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ===== RESULTS ACTIONS ===== */
.results-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 24px;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--white);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    background: var(--danger);
}

/* ===== UTILITIES ===== */
.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 16px 12px 40px;
    }

    .title-group h1 {
        font-size: 20px;
    }

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

    .results-grid {
        grid-template-columns: 1fr;
    }

    .plot-card.wide {
        grid-column: 1;
    }

    .config-actions {
        flex-direction: column;
        gap: 12px;
    }

    .config-actions .btn-ghost {
        order: 2;
    }

    .results-actions {
        flex-direction: column;
    }

    .results-actions button {
        width: 100%;
        justify-content: center;
    }

    .segment-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .step-line {
        width: 30px;
    }

    .step-label {
        font-size: 10px;
    }

    .metrics-bar {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .metric-card {
        padding: 14px 10px;
    }

    .metric-value {
        font-size: 22px;
    }

    .plot-card canvas {
        height: 250px !important;
    }
}
