/* === Variables === */
:root {
    --bg: #f5f6fa;
    --card: #fff;
    --primary: #3498db;
    --primary-dark: #2980b9;
    --secondary: #95a5a6;
    --text: #2c3e50;
    --border: #dfe6e9;
    --success: #27ae60;
    --error: #e74c3c;
    --warn: #e67e22;
    --purple: #9b59b6;
    --dark: #34495e;
    --log-bg: #1e272e;
    --log-text: #dfe6e9;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* === Layout === */
.app-layout {
    display: flex;
    height: calc(100vh - 40px);
    overflow: hidden;
}

.main-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    height: 100%;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
}

/* === Log Panel === */
.log-panel {
    width: 480px;
    min-width: 220px;
    max-width: 900px;
    height: 100%;
    background: var(--log-bg);
    color: var(--log-text);
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255,255,255,0.1);
    position: relative;
    flex-shrink: 0;
}

.log-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.15s;
}

.log-resize-handle:hover,
.log-resize-handle.dragging {
    background: rgba(52, 152, 219, 0.5);
}

.log-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-weight: 600;
    font-size: 0.9rem;
}

.log-clear-btn {
    background: none;
    border: none;
    color: var(--secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.log-clear-btn:hover { background: rgba(255,255,255,0.1); }

.log-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    font-family: "Consolas", "Monaco", monospace;
    font-size: 0.8rem;
    line-height: 1.6;
}

.log-entry {
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-bottom: 2px;
}

.log-entry-appear {
    animation: logAppear 0.3s ease-out;
}

@keyframes logAppear {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

.log-time { color: #636e72; }
.log-icon { margin: 0 0.2rem; }
.log-success .log-icon { color: #27ae60; }
.log-info .log-icon { color: #3498db; }
.log-warn .log-icon { color: #f1c40f; }
.log-error .log-icon { color: #e74c3c; }
.log-progress .log-icon { color: #e67e22; }

/* === Header === */
.header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.header p { margin: 0; color: var(--secondary); font-size: 0.95rem; }

/* === Steps Nav === */
.steps-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.step-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.step-btn:hover { background: var(--bg); }

.step-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* === Content === */
.content {
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 1.5rem;
}

.step-panel { display: none; }
.step-panel.active { display: block; animation: fadeIn 0.3s ease-out; }
.step-panel h2 { margin-top: 0; margin-bottom: 1rem; font-size: 1.25rem; }

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

/* === Card === */
.card {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafbfc;
}

.card h3 { margin-top: 0; margin-bottom: 0.75rem; font-size: 1rem; }

/* === Forms === */
.form-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

.form-row input[type="text"],
.form-row select {
    flex: 1;
    max-width: 300px;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

label {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

select, input[type="text"], input[type="number"] {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    min-width: 200px;
}

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    color: #fff;
    transition: all 0.2s;
}

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { filter: brightness(0.95); }

/* === Lists === */
#datasets-list, #models-list {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
}

#datasets-list .item, #models-list .item {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
}

#datasets-list .item:last-child, #models-list .item:last-child { border-bottom: none; }
#datasets-list .item:hover, #models-list .item:hover { background: var(--bg); }
#datasets-list .item.selected, #models-list .item.selected { background: #e8f4fc; font-weight: 500; }

.viz-container { margin-top: 1rem; min-height: 40px; }
.viz-container .loading { color: var(--secondary); font-style: italic; }

/* === Metric Cards === */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.metric-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    text-align: center;
    border-top: 3px solid var(--primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.metric-card-highlight { border-top-color: var(--error); box-shadow: 0 0 0 1px rgba(231, 76, 60, 0.2); }
.metric-card .value { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.metric-card .label { font-size: 0.8rem; color: var(--secondary); margin-top: 0.25rem; }

.metric-card-appear {
    animation: cardAppear 0.4s ease-out both;
}

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

/* === Progress Bar === */
.viz-progress-wrap {
    margin: 0.75rem 0;
    animation: fadeIn 0.3s ease-out;
}

.viz-progress-label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text);
}

.viz-progress-bar-bg {
    height: 28px;
    background: #ecf0f1;
    border-radius: 14px;
    overflow: hidden;
    position: relative;
}

.viz-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    border-radius: 14px;
    transition: width 0.4s ease;
    min-width: 0;
    position: relative;
}

.viz-progress-bar-fill::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,0.3) 50%,
        rgba(255,255,255,0) 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(200%); }
}

.viz-progress-done { background: linear-gradient(90deg, #27ae60, #2ecc71); }
.viz-progress-done::after { animation: none; }

.viz-progress-text {
    font-size: 0.82rem;
    color: var(--secondary);
    margin-top: 0.2rem;
    text-align: center;
}

/* === Charts === */
.chart-wrap {
    max-width: 360px;
    margin: 1rem 0;
    position: relative;
    height: 240px;
}

.chart-wrap-wide { max-width: 100%; height: 280px; }
.chart-wrap-tall { max-width: 100%; height: 320px; }
.chart-wrap-xtall { max-width: 100%; height: 500px; }

/* === Results Table === */
.results-table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.results-table th,
.results-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.results-table th { background: var(--bg); font-weight: 600; position: sticky; top: 0; z-index: 1; }
.results-table tr:last-child td { border-bottom: none; }
.results-table tr:hover td { background: #f8f9fa; }

.results-table .badge,
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 500;
}

.badge-fraud { background: #fdeaea; color: #c0392b; }
.badge-ok { background: #e8f8f5; color: #27ae60; }
.badge-warn { background: #fef5e7; color: #e67e22; }

.viz-row-fraud td { background: #fff5f5 !important; }

.badge-type {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #fff;
    background: var(--secondary);
}

.missing-val { color: #e74c3c; font-style: italic; }

/* === Metrics Bars === */
.metrics-bars { margin-top: 1rem; }

.metric-row { margin-bottom: 0.75rem; }

.metric-row-appear {
    animation: cardAppear 0.4s ease-out both;
}

.metric-row .name { font-size: 0.9rem; margin-bottom: 0.2rem; }

.metric-row .bar-bg {
    height: 24px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.metric-row .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #2ecc71);
    border-radius: 4px;
    transition: width 0.8s ease;
    min-width: 0;
    max-width: 100%;
}

.metric-row .val { font-size: 0.85rem; color: var(--secondary); margin-top: 0.15rem; }

/* === Confusion Matrix === */
.viz-cm { margin: 1rem 0; }
.viz-cm-title { font-weight: 600; margin-bottom: 0.5rem; }

.viz-cm-table {
    border-collapse: collapse;
    font-size: 0.9rem;
}

.viz-cm-table th,
.viz-cm-table td {
    padding: 0.5rem 1rem;
    text-align: center;
    border: 1px solid var(--border);
}

.viz-cm-table th { background: var(--bg); font-weight: 600; }
.viz-cm-label { background: var(--bg); font-weight: 600; }

.viz-cm-tn { background: #e8f8f5; color: #27ae60; font-size: 1.2rem; font-weight: 700; }
.viz-cm-tp { background: #e8f8f5; color: #27ae60; font-size: 1.2rem; font-weight: 700; }
.viz-cm-fp { background: #fdeaea; color: #e74c3c; font-size: 1.2rem; font-weight: 700; }
.viz-cm-fn { background: #fef5e7; color: #e67e22; font-size: 1.2rem; font-weight: 700; }

.viz-cm-cell small { display: block; font-size: 0.7rem; font-weight: 400; opacity: 0.7; }

/* === Suspicious Cards === */
.viz-top-suspicious { margin: 1rem 0; }

.viz-suspicious-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    margin-bottom: 0.5rem;
    background: #fff5f5;
    border: 1px solid #fccaca;
    border-radius: 6px;
    border-left: 4px solid #e74c3c;
}

.viz-suspicious-rank {
    font-size: 1.2rem;
    font-weight: 700;
    color: #e74c3c;
    min-width: 2rem;
}

.viz-suspicious-info { display: flex; gap: 1rem; align-items: center; flex: 1; }
.viz-suspicious-id { font-weight: 600; }
.viz-suspicious-prob { font-size: 1.1rem; font-weight: 700; color: #c0392b; margin-left: auto; }

/* === Suspicious Detail Cards (after labeling) === */
.viz-top-suspicious-detail { margin: 1.2rem 0; }

.viz-top-suspicious-title {
    font-size: 1rem;
    font-weight: 700;
    color: #c0392b;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.viz-suspicious-detail-card {
    background: #fff8f8;
    border: 1px solid #f5c6c6;
    border-left: 5px solid #e74c3c;
    border-radius: 8px;
    margin-bottom: 0.8rem;
    overflow: hidden;
    animation: cardAppear 0.35s ease-out both;
}

.viz-suspicious-detail-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: #fdeaea;
}

.viz-suspicious-rank-big {
    font-size: 1.4rem;
    font-weight: 800;
    color: #e74c3c;
    min-width: 2rem;
    text-align: center;
}

.viz-suspicious-score-big {
    font-size: 1.05rem;
    font-weight: 700;
    color: #c0392b;
    background: #fff;
    border: 2px solid #e74c3c;
    border-radius: 20px;
    padding: 0.15rem 0.7rem;
    margin-left: auto;
}

.viz-suspicious-detail-data {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.4rem 1rem;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
}

.viz-suspicious-detail-data span { color: var(--secondary); }
.viz-suspicious-detail-data strong { color: var(--text); }

.viz-suspicious-detail-metrics {
    padding: 0.5rem 1rem 0.7rem;
    border-top: 1px solid #f5c6c6;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.badge-triggered {
    display: inline-block;
    background: #fdeaea;
    color: #c0392b;
    border: 1px solid #f5c6c6;
    border-radius: 12px;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 500;
}

.viz-fraud-score-row {
    padding: 0.35rem 1rem 0;
    font-size: 0.85rem;
    color: var(--secondary);
}
.viz-fraud-score-row strong { color: #c0392b; }

.viz-triggered-count {
    padding: 0.25rem 1rem 0;
    font-size: 0.82rem;
    color: var(--secondary);
}
.viz-triggered-count strong { color: #e74c3c; }
.viz-triggered-count em { font-style: italic; color: #888; }

.viz-triggered-list {
    padding: 0.4rem 1rem 0.7rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.viz-triggered-badge {
    display: inline-block;
    background: #fdeaea;
    color: #c0392b;
    border: 1px solid #f5c6c6;
    border-radius: 12px;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 500;
}

/* === Architecture Diagram (SVG) === */
.viz-arch-svg {
    width: 100%;
    max-width: 780px;
    height: auto;
    margin: 0 auto;
    display: block;
}

/* === Timeline === */
.viz-timeline { padding: 0.5rem 0; }

.viz-timeline-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem 0;
    position: relative;
}

.viz-timeline-appear {
    animation: cardAppear 0.3s ease-out both;
}

.viz-timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--border);
    margin-top: 4px;
    flex-shrink: 0;
    position: relative;
}

.viz-timeline-dot.active { background: var(--primary); box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3); }

.viz-timeline-item:not(:last-child) .viz-timeline-dot::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 14px;
    width: 2px;
    height: calc(100% + 12px);
    background: var(--border);
}

.viz-timeline-time { font-size: 0.78rem; color: var(--secondary); font-family: monospace; }
.viz-timeline-desc { font-size: 0.88rem; }

/* === Misc === */
.card a.btn { margin-right: 0.5rem; margin-top: 0.5rem; }
#file-upload, #predict-file-input { display: block; margin: 0.5rem 0; }
.error { color: var(--error); }
.success { color: var(--success); }

/* === Responsive === */
@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .log-panel {
        width: 100%;
        min-width: 100%;
        height: 200px;
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
}
