/* =============================================================
   Tourist & Flight — dashboard.css
   ============================================================= */
:root {
    --bg: #f0f9ff;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #0ea5e9;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
    --radius: 18px;
}
* { box-sizing: border-box; font-family: 'Sarabun', system-ui, sans-serif; }
html, body { margin: 0; padding: 0; }
body {
    background: radial-gradient(1200px 600px at 100% -10%, #bae6fd 0%, transparent 55%),
                radial-gradient(900px 500px at -10% 0%, #a7f3d0 0%, transparent 45%), var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ── Topbar ── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; padding: 18px 26px;
    background: linear-gradient(120deg, #0369a1, #0ea5e9 45%, #14b8a6);
    color: #fff; box-shadow: var(--shadow);
}
.topbar .tb-title { display: flex; align-items: center; gap: 14px; }
.topbar .tb-logo {
    width: 46px; height: 46px; border-radius: 14px; background: rgba(255, 255, 255, .18);
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.topbar h1 { font-size: 1.35rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.topbar .tb-sub { font-size: .82rem; opacity: .85; margin-top: 2px; }
.topbar .tb-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .8rem; }
.tb-pill { background: rgba(255, 255, 255, .16); padding: 7px 14px; border-radius: 999px; font-weight: 600; }
.tb-pill a { color: #fff; text-decoration: none; }
.tb-pill.warn { background: rgba(251, 191, 36, .9); color: #422006; }

.page { max-width: 1480px; margin: 0 auto; padding: 22px 18px 60px; }

/* ── Filter bar ── */
.filterbar {
    display: flex; align-items: flex-end; gap: 22px; flex-wrap: wrap;
    background: var(--card); border-radius: var(--radius); padding: 16px 20px;
    box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 18px;
}
.fb-group { display: flex; flex-direction: column; gap: 7px; }
.fb-label { color: var(--muted); font-size: .76rem; font-weight: 600; }
.fb-group .fb-input, .fb-group .fb-dash { display: inline-block; }
.fb-group:has(.fb-input + .fb-dash) { flex-direction: row; align-items: center; gap: 8px; }
.fb-input {
    font-family: inherit; font-size: .86rem; color: var(--ink);
    padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px;
    background: #f8fafc; outline: none; transition: border-color .15s, box-shadow .15s;
}
.fb-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,165,233,.12); }
.fb-select { min-width: 170px; cursor: pointer; }
.fb-dash { color: var(--muted); }
.fb-chips { display: flex; gap: 6px; }
.fb-chip {
    font-family: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
    padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px;
    background: #f8fafc; color: var(--muted); transition: all .15s;
}
.fb-chip:hover { border-color: var(--brand); color: var(--brand); }
.fb-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.fb-reset {
    font-family: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
    margin-left: auto; padding: 9px 16px; border: 1px solid var(--line); border-radius: 10px;
    background: #fff; color: var(--muted); transition: all .15s;
}
.fb-reset:hover { border-color: #ef4444; color: #ef4444; }
.fb-note { flex-basis: 100%; margin: 4px 0 0; color: var(--muted); font-size: .73rem; line-height: 1.5; }
.fb-note b { color: var(--brand); font-weight: 700; }

/* ── Cross-filter chips (จากการคลิกกราฟ) ── */
.xf-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.xf-chips .xf-lead { color: var(--muted); font-size: .8rem; font-weight: 600; }
.xf-chip {
    font-family: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
    padding: 6px 12px; border: 1px solid #bae6fd; border-radius: 999px;
    background: #e0f2fe; color: #0369a1; transition: all .15s;
}
.xf-chip:hover { background: #bae6fd; }
.xf-chip b { margin-left: 3px; opacity: .7; }
.xf-clear {
    font-family: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
    padding: 6px 12px; border: none; border-radius: 999px; background: transparent; color: #ef4444;
    text-decoration: underline;
}
.xf-clear:hover { color: #b91c1c; }

/* ── KPI ── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
    background: var(--card); border-radius: var(--radius); padding: 20px 22px;
    box-shadow: var(--shadow); border: 1px solid var(--line); position: relative;
}
.kpi::before {
    content: ''; position: absolute; right: 10px; top: 10px;
    width: 64px; height: 64px; border-radius: 50%; opacity: .12; background: var(--accent, var(--brand));
    pointer-events: none;
}
.kpi .info-btn { top: 14px; right: 14px; }
.kpi .info-pop { top: 40px; }
.kpi .kpi-icon { font-size: 1.5rem; }
.kpi .kpi-label { color: var(--muted); font-size: .85rem; margin: 10px 0 4px; }
.kpi .kpi-value { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; }
.kpi .kpi-foot { color: var(--muted); font-size: .76rem; margin-top: 4px; }

/* ── Cards ── */
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }
.card {
    background: var(--card); border-radius: var(--radius); padding: 18px 20px;
    box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 16px;
}
.card { position: relative; }
.card h2 { font-size: 1.02rem; font-weight: 700; margin: 0 0 2px; display: flex; align-items: center; gap: 8px; padding-right: 34px; }
.click-badge {
    font-size: .68rem; font-weight: 600; color: #0369a1; background: #e0f2fe;
    padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}

/* ── Route map (Leaflet) ── */
.route-map {
    height: 440px; width: 100%; border-radius: 12px; overflow: hidden;
    border: 1px solid var(--line); background: #eef6fb;
}
.route-map .leaflet-container { font-family: 'Sarabun', sans-serif; background: #eef6fb; }
.map-sub { font-size: .72rem; font-weight: 600; color: var(--muted); }
.route-pop b { color: var(--brand); }
.route-pop .rp-n { color: var(--muted); font-size: .78rem; }
.card .card-sub { color: var(--muted); font-size: .8rem; margin: 0 0 14px; }

/* ── Info "!" tooltip (มุมบนขวาของ card) ── */
.info-btn {
    position: absolute; top: 16px; right: 16px; z-index: 5;
    width: 22px; height: 22px; border-radius: 50%; border: none; cursor: help;
    background: #e0f2fe; color: #0369a1; font-weight: 800; font-size: .82rem; font-family: inherit;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, transform .15s;
}
.info-btn:hover, .info-btn:focus-visible { background: var(--brand); color: #fff; transform: scale(1.1); outline: none; }
.info-pop {
    position: absolute; top: 44px; right: 12px; z-index: 20; width: 280px; max-width: calc(100vw - 48px);
    background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 13px 15px;
    box-shadow: 0 8px 28px rgba(15,23,42,.28); font-size: .78rem; line-height: 1.55;
    opacity: 0; visibility: hidden; transform: translateY(-4px); transition: all .16s ease;
    pointer-events: none;
}
.info-pop::before {
    content: ''; position: absolute; top: -6px; right: 16px;
    border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 7px solid #0f172a;
}
.info-btn:hover + .info-pop, .info-btn:focus-visible + .info-pop, .info-pop:hover {
    opacity: 1; visibility: visible; transform: translateY(0); pointer-events: auto;
}
.info-pop .ip-what { display: block; margin-bottom: 7px; }
.info-pop .ip-goal { display: block; color: #7dd3fc; }
.info-pop .ip-goal::before { content: '🎯 '; }
.info-pop .ip-what::before { content: '📊 '; }

/* ── Direction toggle (ขาเข้า/ขาออก/รวม) ── */
.dir-toggle { display: inline-flex; gap: 4px; margin: 0 0 12px; padding: 3px; background: #f1f5f9; border-radius: 999px; }
.dir-toggle button {
    font-family: inherit; font-size: .76rem; font-weight: 600; cursor: pointer;
    padding: 5px 13px; border: none; border-radius: 999px; background: transparent; color: var(--muted);
    transition: all .15s;
}
.dir-toggle button:hover { color: var(--brand); }
.dir-toggle button.active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(15,23,42,.1); }
.card .chart-box { position: relative; height: 300px; }
.card .chart-box.tall { height: 340px; }

/* ── Scrollable bar chart (แสดงทุกแท่ง + เลื่อนดู) ── */
.card .chart-scroll { height: 360px; overflow-y: auto; overflow-x: hidden; margin-right: -6px; padding-right: 6px; }
.card .chart-scroll-inner { position: relative; min-height: 100%; }
/* scrollbar บางๆ */
.card .chart-scroll::-webkit-scrollbar { width: 8px; }
.card .chart-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.card .chart-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.card .chart-scroll::-webkit-scrollbar-track { background: transparent; }

/* ── Heatmap ── */
.heat-wrap { overflow-x: auto; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: .68rem; width: 100%; }
.heat th { color: var(--muted); font-weight: 600; padding: 3px; text-align: center; border-bottom: 1px solid var(--line); }
.heat td { padding: 0; }
.heat td.lbl { color: var(--muted); font-weight: 600; padding: 3px 8px; white-space: nowrap; border-right: 1px solid var(--line); }
.heat td .cell {
    min-width: 22px; height: 24px; border-radius: 4px; text-align: center; font-size: .62rem;
    line-height: 24px; border: 1px solid rgba(148,163,184,.25);
}
.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.heat-legend .hl-label { color: var(--muted); font-size: .72rem; font-weight: 500; }
.heat-legend .hl-bar {
    width: 120px; height: 12px; border-radius: 6px; border: 1px solid rgba(148,163,184,.25);
    background: linear-gradient(90deg, rgba(14,165,233,.12), rgba(14,165,233,1));
}

/* ── Table / Board ── */
table.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.tbl th, table.tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr:hover td { background: #f8fafc; }
.board-wrap { max-height: 460px; overflow-y: auto; }
.dir-pill { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 700; }
.dir-arr { background: #dcfce7; color: #166534; }
.dir-dep { background: #fee2e2; color: #991b1b; }
.st { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.st-ok { background: #dcfce7; color: #166534; }
.st-go { background: #dbeafe; color: #1e40af; }
.st-wait { background: #fef9c3; color: #854d0e; }
.st-bad { background: #fee2e2; color: #991b1b; }
.st-mut { background: #f1f5f9; color: #475569; }

.empty-note { color: var(--muted); font-size: .85rem; padding: 30px; text-align: center; }

@media (max-width: 980px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .cols-2 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}
