/* se-tracking dashboard styles. Dark theme matching se-report. */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'IBM Plex Sans Thai', 'Segoe UI', Tahoma, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

button { font-family: inherit; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: 280px; min-width: 280px;
    background: #1e293b;
    border-right: 1px solid #334155;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid #334155;
}
.sidebar-header h2 {
    font-size: 18px; font-weight: 700;
    color: #f1f5f9;
}
.sidebar-header .version {
    font-size: 11px; color: #64748b;
    font-family: 'IBM Plex Mono', monospace;
    margin-top: 4px;
}
.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid #334155;
}
.sidebar-section h3 {
    font-size: 11px; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 1px;
    margin-bottom: 12px;
}
.sidebar-section label {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; cursor: pointer;
    padding: 6px 8px; border-radius: 6px;
    color: #cbd5e1;
}
.sidebar-section label:hover { background: #334155; }
.sidebar-section input[type=checkbox] { accent-color: #3b82f6; }
.sidebar-section input[type=text] {
    width: 100%;
    padding: 8px 12px;
    background: #0f172a;
    border: 1px solid #475569;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 13px;
}
.sidebar-section input[type=text]:focus {
    outline: none; border-color: #3b82f6;
}

/* ── Main ────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex; flex-direction: column;
    overflow: hidden;
}

/* ── Toolbar ─────────────────────────────────────────────────────── */
.toolbar {
    padding: 14px 24px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    display: flex; align-items: center;
    gap: 12px; flex-wrap: wrap;
}
.toolbar h1 {
    font-size: 18px; font-weight: 700;
    color: #f1f5f9;
    margin-right: auto;
}
.toolbar input[type=date] {
    padding: 7px 12px;
    background: #0f172a;
    border: 1px solid #475569;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 13px;
}
.toolbar input[type=date]::-webkit-calendar-picker-indicator { filter: invert(0.7); }

/* Pill group (วัน/เดือน/ปี) */
.pill-group { display: flex; }
.pill-group input { display: none; }
.pill-group label {
    padding: 7px 14px; font-size: 13px; cursor: pointer;
    background: #0f172a; border: 1px solid #475569; color: #94a3b8;
    transition: all 0.15s;
}
.pill-group label:first-of-type { border-radius: 8px 0 0 8px; }
.pill-group label:last-of-type { border-radius: 0 8px 8px 0; border-left: none; }
.pill-group label:not(:first-of-type):not(:last-of-type) { border-left: none; }
.pill-group input:checked + label {
    background: #3b82f6; border-color: #3b82f6; color: #fff;
}

/* Buttons */
.btn {
    padding: 7px 18px;
    border: 1px solid #475569;
    border-radius: 8px;
    background: #0f172a;
    color: #cbd5e1;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn:hover { background: #1e293b; color: #e2e8f0; }
.btn-primary {
    background: #a855f7;
    border-color: #a855f7;
    color: #fff;
    font-weight: 600;
}
.btn-primary:hover { background: #9333ea; border-color: #9333ea; }
.btn-success {
    border-color: #22c55e;
    color: #22c55e;
}
.btn-success:hover { background: #064e3b; color: #4ade80; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Content ─────────────────────────────────────────────────────── */
.content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* ── Stats cards ─────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 18px 20px;
    position: relative;
}
.stat-card.k1 { border-left: 4px solid #3b82f6; }
.stat-card.k2 { border-left: 4px solid #22c55e; }
.stat-card.k3 { border-left: 4px solid #f59e0b; }
.stat-card.k4 { border-left: 4px solid #ef4444; }
.stat-card h4 {
    font-size: 12px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.stat-card .count {
    font-size: 28px;
    font-weight: 700;
    color: #f1f5f9;
    font-family: 'IBM Plex Mono', monospace;
}
.stat-card .meta {
    font-size: 11px;
    color: #64748b;
    margin-top: 6px;
}
.stat-card .meta.dropoff { color: #f59e0b; }

/* ── Charts ──────────────────────────────────────────────────────── */
.chart-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 16px;
    margin-bottom: 24px;
}
.chart-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 18px 20px;
}
.chart-card h3 {
    font-size: 13px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}
.chart-card .chart-canvas {
    position: relative;
    height: 240px;
}

/* ── Table ───────────────────────────────────────────────────────── */
.table-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    overflow: hidden;
}
.table-header {
    padding: 14px 20px;
    border-bottom: 1px solid #334155;
    display: flex; align-items: center; gap: 12px;
}
.table-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: #f1f5f9;
}
.table-header .count {
    margin-left: auto;
    font-size: 12px;
    color: #94a3b8;
    font-family: 'IBM Plex Mono', monospace;
}
.table-wrap {
    overflow-x: auto;
    max-height: 60vh;
    overflow-y: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    position: sticky; top: 0;
    background: #0f172a;
    border-bottom: 1px solid #334155;
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
thead th:hover { color: #e2e8f0; }
thead th.numeric { text-align: right; }
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #1e293b;
    color: #cbd5e1;
}
tbody td.numeric { text-align: right; font-family: 'IBM Plex Mono', monospace; }
tbody tr:hover { background: #283447; }
tbody tr.clickable { cursor: pointer; }

/* Stage cells */
.stage-cell { text-align: center; min-width: 40px; }
.stage-cell .icon {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
}
.stage-cell .icon.done { background: #064e3b; color: #4ade80; }
.stage-cell .icon.miss { color: #475569; }
.stage-cell .icon.warn { background: #422006; color: #facc15; }

/* Status badge */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.status-badge.s1 { background: #1e3a8a40; color: #93c5fd; border: 1px solid #3b82f660; }
.status-badge.s2 { background: #14532d40; color: #86efac; border: 1px solid #22c55e60; }
.status-badge.s3 { background: #78350f40; color: #fcd34d; border: 1px solid #f59e0b60; }
.status-badge.s4 { background: #7f1d1d40; color: #fca5a5; border: 1px solid #ef444460; }
.status-badge.s0 { background: #1e293b; color: #64748b; border: 1px solid #334155; }

/* ── Footer / sync status strip ──────────────────────────────────── */
.sync-strip {
    display: flex; gap: 12px;
    padding: 12px 20px;
    background: #1e293b;
    border-top: 1px solid #334155;
    font-size: 12px;
    color: #94a3b8;
    overflow-x: auto;
}
.sync-strip .pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #0f172a;
    border: 1px solid #334155;
    white-space: nowrap;
}
.sync-strip .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #475569;
}
.sync-strip .dot.ok { background: #22c55e; }
.sync-strip .dot.err { background: #ef4444; }
.sync-strip .dot.running { background: #facc15; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ── Progress ────────────────────────────────────────────────────── */
.progress-overlay {
    display: none;
    position: fixed; bottom: 24px; right: 24px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 14px 18px;
    min-width: 320px;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.progress-overlay.active { display: block; }
.progress-overlay h4 {
    font-size: 13px; color: #f1f5f9;
    margin-bottom: 10px;
}
.progress-overlay .line {
    font-size: 12px; color: #94a3b8;
    margin: 4px 0; font-family: 'IBM Plex Mono', monospace;
}
.progress-overlay .line .ok { color: #4ade80; }
.progress-overlay .line .err { color: #f87171; }

/* ── Detail page ─────────────────────────────────────────────────── */
.detail-wrap {
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
}
.detail-wrap .back-link {
    display: inline-block;
    margin-bottom: 16px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 13px;
}
.detail-wrap .back-link:hover { color: #e2e8f0; }
.detail-wrap h1 {
    font-size: 22px;
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 4px;
}
.detail-wrap .sub {
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 24px;
    font-family: 'IBM Plex Mono', monospace;
}
.stage-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    margin-bottom: 16px;
    overflow: hidden;
}
.stage-card .stage-header {
    padding: 14px 20px;
    border-bottom: 1px solid #334155;
    display: flex; align-items: center; gap: 12px;
}
.stage-card .stage-header.empty { opacity: 0.55; }
.stage-card .stage-header h3 {
    font-size: 14px; font-weight: 600;
    color: #f1f5f9;
}
.stage-card .stage-header .meta {
    margin-left: auto;
    font-size: 12px;
    color: #94a3b8;
    font-family: 'IBM Plex Mono', monospace;
}
.stage-card .stage-body {
    padding: 16px 20px;
}
.stage-card .grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 24px;
}
.stage-card .grid .lbl {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stage-card .grid .val {
    font-size: 13px;
    color: #e2e8f0;
    margin-top: 2px;
}
.stage-card pre {
    background: #0f172a;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 12px;
    font-family: 'IBM Plex Mono', monospace;
}

/* ── Filter row helpers ──────────────────────────────────────────── */
.input-group { display: flex; gap: 8px; align-items: center; }
.toolbar-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.muted { color: #64748b; }

/* ── Upload Modal ───────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
}
.modal-box {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    width: 90%; max-width: 720px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid #334155;
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 {
    font-size: 16px; font-weight: 700; color: #f1f5f9;
}
.modal-close {
    background: none; border: none; color: #64748b;
    font-size: 22px; cursor: pointer;
}
.modal-close:hover { color: #e2e8f0; }
.modal-body { padding: 20px 24px; }

.dropzone {
    border: 2px dashed #475569;
    border-radius: 10px;
    padding: 32px 20px;
    text-align: center;
    color: #cbd5e1;
    transition: all 0.2s;
}
.dropzone.dragover {
    border-color: #3b82f6;
    background: #1e3a8a30;
}
.dropzone label.btn-primary { display: inline-block; padding: 8px 20px; }

.upload-result {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 8px;
    font-size: 13px;
}
.upload-result.ok { border-left: 4px solid #22c55e; }
.upload-result.err { border-left: 4px solid #ef4444; }
.upload-result .name { font-weight: 600; color: #e2e8f0; }
.upload-result .stats { margin-top: 4px; color: #94a3b8; font-size: 12px; font-family: 'IBM Plex Mono', monospace; }
.upload-result .err-msg { color: #f87171; font-size: 12px; margin-top: 4px; }

.upload-history {
    font-size: 12px;
    color: #94a3b8;
    max-height: 200px;
    overflow-y: auto;
}
.upload-history table { width: 100%; }
.upload-history th, .upload-history td {
    padding: 6px 8px; text-align: left; border-bottom: 1px solid #1e293b;
}
.upload-history th { color: #64748b; font-weight: 600; font-size: 11px; text-transform: uppercase; }
.upload-history .num { font-family: 'IBM Plex Mono', monospace; text-align: right; }
