/* Pretty Cash theme layer: semantic tokens, a dark palette, and the expense overview dashboard.
   Loaded after app.css so it can retint the components app.css paints with literal colours. */

:root {
    --surface: #ffffff;
    --surface-2: #fbfcfd;
    --surface-3: #f5f6f8;
    --page: #f6f7f9;
    --text: #243047;
    --text-2: #657184;
    --text-3: #97a0ac;
    --edge: #eaecef;
    --edge-2: #e1e5eb;
    --accent: #1361e4;
    --ok: #219778;
    --warn: #0a6ba6;
    --bad: #cb6462;
    --info: #4d8fd6;
    --violet: #8573c9;
    --grid: #eff1f4;
    --shadow: 0 1px 3px #17223810;
}

/* Keep checkbox and radio labels together inside full-width grid fields. */
.inline-check {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: auto;
    max-width: 100%;
    line-height: 1.6;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    vertical-align: top;
}
.inline-check input[type='checkbox'],
.inline-check input[type='radio'] {
    flex: 0 0 16px;
    width: 16px;
    min-width: 16px;
    max-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
}

.avatar { overflow: hidden; }
.avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

[data-theme='dark'] {
    --surface: #101c30;
    --surface-2: #14233b;
    --surface-3: #1a2c48;
    --page: #0a1524;
    --navy: #0d1a2d;
    --navy-light: #16263f;
    --text: #e6edf7;
    --text-2: #a9bcd4;
    --text-3: #7d93b0;
    --edge: #1f3355;
    --edge-2: #264064;
    --line: #1f3355;
    --bg: #0a1524;
    --ink: #e6edf7;
    --muted: #8aa0bd;
    --peach: #11284a;
    --ok: #35c397;
    --warn: #57bef2;
    --bad: #f0807c;
    --info: #64a5ec;
    --violet: #a793e8;
    --grid: #1c2f4d;
    --shadow: 0 1px 3px #00000055;
    color-scheme: dark;
}

/* ---- retint the components app.css paints with literal colours ---- */

[data-theme='dark'] body { background: var(--page); color: var(--text); }
[data-theme='dark'] .sidebar { background: var(--navy); border-right: 1px solid var(--edge); }
[data-theme='dark'] .topbar { background: var(--surface); border-bottom-color: var(--edge); }
[data-theme='dark'] .breadcrumb strong { color: var(--text); }
[data-theme='dark'] .panel { background: var(--surface); border-color: var(--edge); }
[data-theme='dark'] .panel-title { color: var(--text); }
[data-theme='dark'] .stat-card { background: var(--surface); border-color: var(--edge); }
[data-theme='dark'] .stat-number { color: var(--text); }
[data-theme='dark'] .page-heading h1 { color: var(--text); }
[data-theme='dark'] .form-section-title,
[data-theme='dark'] .settings-panel h3,
[data-theme='dark'] .summary-panel h3,
[data-theme='dark'] .empty-state h3,
[data-theme='dark'] .empty-state h2,
[data-theme='dark'] .route-card h3,
[data-theme='dark'] .route-card h2,
[data-theme='dark'] .modal-head h2,
[data-theme='dark'] .success-panel h2 { color: var(--text); }
[data-theme='dark'] th { background: var(--surface-2); color: var(--text-3); border-bottom-color: var(--edge); }
[data-theme='dark'] td { color: var(--text-2); border-bottom-color: var(--edge); }
[data-theme='dark'] .amount { color: var(--text); }
[data-theme='dark'] .doc-number,
[data-theme='dark'] .doc-name { color: var(--text-2); }
[data-theme='dark'] input,
[data-theme='dark'] select,
[data-theme='dark'] textarea { background: var(--surface-2); border-color: var(--edge-2); color: var(--text); }
[data-theme='dark'] input[type='file'] { background: var(--surface-3); }
[data-theme='dark'] input::placeholder,
[data-theme='dark'] textarea::placeholder { color: var(--text-3); }
[data-theme='dark'] label { color: var(--text-2); }
[data-theme='dark'] .btn { background: var(--surface-2); border-color: var(--edge-2); color: var(--text-2); }
[data-theme='dark'] .btn:hover { background: var(--surface-3); border-color: var(--edge-2); }
[data-theme='dark'] .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme='dark'] .btn.soft { background: #11284a; border-color: #1f3c68; color: #6fb4ff; }
[data-theme='dark'] .btn.danger { background: #3b1d1f; color: #f5908c; border-color: #55282b; }
[data-theme='dark'] .btn.dark { background: var(--surface-3); border-color: var(--edge-2); color: var(--text); }
[data-theme='dark'] .icon-btn:hover { background: var(--surface-3); }
[data-theme='dark'] .modal { background: var(--surface); box-shadow: 0 20px 80px #00000088; }
[data-theme='dark'] .modal-overlay { background: #040913bb; }
[data-theme='dark'] .detail-meta { background: var(--surface-2); }
[data-theme='dark'] .detail-meta strong { color: var(--text); }
[data-theme='dark'] .detail-flow span { background: var(--surface-3); color: var(--text-2); }
[data-theme='dark'] .detail-flow span.done { background: #123a2c; color: #4cc39c; }
[data-theme='dark'] .summary-note,
[data-theme='dark'] .audit-json { background: var(--surface-2); color: var(--text-2); }
[data-theme='dark'] .expense-item { border-color: var(--edge); }
[data-theme='dark'] .route-box { background: var(--surface-2); border-color: var(--edge); }
[data-theme='dark'] .passenger-box { border-top-color: var(--edge); }
[data-theme='dark'] .passenger-box .field-note strong { color: var(--text); }
[data-theme='dark'] .toolbar,
[data-theme='dark'] .tabs,
[data-theme='dark'] .table-foot,
[data-theme='dark'] .panel-bottom-link,
[data-theme='dark'] .setting-row,
[data-theme='dark'] .category-row,
[data-theme='dark'] .quick-action,
[data-theme='dark'] .audit-item,
[data-theme='dark'] .form-footer { border-color: var(--edge); }
[data-theme='dark'] .pending-item { border-bottom-color: var(--edge); }
[data-theme='dark'] .pending-item strong,
[data-theme='dark'] .pending-item .count,
[data-theme='dark'] .quick-action strong,
[data-theme='dark'] .setting-row strong,
[data-theme='dark'] .audit-content strong { color: var(--text); }
[data-theme='dark'] .segment { background: var(--surface-3); }
[data-theme='dark'] .segment button.active { background: var(--surface); color: var(--text); }
[data-theme='dark'] .tabs button.active { color: var(--accent); }
[data-theme='dark'] .tabs button span { background: var(--surface-3); color: var(--text-3); }
.tabs button span.alert, .tabs button.active span.alert { background: #0b2c41; color: #57bef2; }
[data-theme='dark'] .info-banner { background: #14263f; border-color: #21395c; color: #9dbbe4; }
[data-theme='dark'] .notice { background: #0c2a3f; border-color: #184263; color: #86c8ef; }
[data-theme='dark'] .notice .notice-icon { background: #12374f; color: #57bef2; }
[data-theme='dark'] .notice strong { color: #a4d8f7; }
[data-theme='dark'] .form-error { background: #3a1c1d; color: #f3908b; }
[data-theme='dark'] .chart-grid { stroke: var(--grid); }
[data-theme='dark'] .chart-label { fill: var(--text-3); }
[data-theme='dark'] .chart-total { color: var(--text); }
[data-theme='dark'] .chart-comparison { background: #123a2c; color: #4cc39c; }
[data-theme='dark'] .badge.amber { color: #57bef2; background: #0b2c41; }
[data-theme='dark'] .badge.blue { color: #7fb0ea; background: #142943; }
[data-theme='dark'] .badge.purple { color: #ab94ec; background: #241d45; }
[data-theme='dark'] .badge.green { color: #44bd9c; background: #10332a; }
[data-theme='dark'] .badge.gray { color: #9aa9bd; background: #1d2c43; }
[data-theme='dark'] .badge.red { color: #f0807c; background: #38191b; }
[data-theme='dark'] .line-state { background: #1d2c43; color: #7d8ba1; }
[data-theme='dark'] .line-state.on { background: #10332a; color: #44bd9c; }
[data-theme='dark'] .line-state.quiet { background: #3a2c10; color: #d9a442; }
[data-theme='dark'] .soft-icon { background: #11284a; color: #6fb4ff; }
[data-theme='dark'] .soft-icon.purple { background: #211c3f; color: #a793e8; }
[data-theme='dark'] .soft-icon.blue { background: #142943; color: #79a8e0; }
[data-theme='dark'] .soft-icon.green { background: #10332a; color: #44bd9c; }
[data-theme='dark'] .soft-icon.coral { background: #11284a; color: #6fb4ff; }
[data-theme='dark'] .line-card { background: #102b22; border-color: #1c4536; }
[data-theme='dark'] .line-card strong { color: #7fd6b2; }
[data-theme='dark'] .line-card .btn { background: var(--surface-2); border-color: #1c4536; color: #6cc9a4; }
[data-theme='dark'] .app-footer { border-top-color: var(--edge); }
[data-theme='dark'] .app-version { background: #1d2c43; color: #8b97ab; }
[data-theme='dark'] .login-page { background: var(--surface); }
[data-theme='dark'] .login-layout .brand { color: var(--text); }
[data-theme='dark'] .login-box h2 { color: var(--text); }
[data-theme='dark'] .login-box input { background: var(--surface-2); }
[data-theme='dark'] .login-box .line-login { background: #102b22; border-color: #1c4536; color: #6cc9a4; }
[data-theme='dark'] .login-or:before,
[data-theme='dark'] .login-or:after { background: var(--edge); }
[data-theme='dark'] .step-number { background: var(--surface-2); border-color: var(--edge-2); color: var(--text-2); }
[data-theme='dark'] .stepper li.complete .step-number { background: #10332a; border-color: #10332a; color: #44bd9c; }
[data-theme='dark'] .success-circle { background: #10332a; color: #44bd9c; }
[data-theme='dark'] .alert-circle { background: #3a1a19; color: #ef8a82; }
[data-theme='dark'] .alert-panel h2 { color: var(--text); }
[data-theme='dark'] .alert-panel .alert-hint { background: #331a19; color: #eda49d; }
[data-theme='dark'] .print-preview { border-color: var(--edge); }

.theme-toggle .icon { width: 17px; height: 17px; }

/* ---- expense overview dashboard ---- */

.dash-bar {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--edge);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 18px;
}
.dash-title { display: flex; align-items: center; gap: 13px; margin-right: auto; }
.dash-title .soft-icon { height: 42px; width: 42px; border-radius: 10px; }
.dash-title h1 { font-size: 21px; font-weight: 600; margin: 0; letter-spacing: -.4px; color: var(--text); }
.dash-title p { margin: 2px 0 0; font-size:var(--fs-2xs); letter-spacing: 1.6px; color: var(--text-3); font-family: Inter, sans-serif; }
.dash-filter { display: flex; flex-direction: column; gap: 5px; }
.dash-filter label { font-size:var(--fs-xs); color: var(--text-3); margin: 0; }
.dash-filter select { min-width: 132px; padding: 7px 10px; font-size:var(--fs-sm); }

/* นับจำนวนการ์ดเอง ไม่ล็อกไว้ที่ 4 ช่อง เพราะตอนเหลือ 3 ใบ ช่องที่สี่กลายเป็นที่ว่างข้างขวา */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card {
    border: 1px solid var(--edge);
    border-radius: 12px;
    padding: 18px 20px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 11px;
}
.kpi-head { display: flex; align-items: center; gap: 13px; }
.kpi-head .kpi-icon {
    height: 44px; width: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.kpi-head .kpi-icon .icon { width: 21px; height: 21px; }
.kpi-label { font-size:var(--fs-md); color: var(--text-2); font-weight: 500; }
.kpi-value { font-family: Inter, var(--thai); font-size: 30px; font-weight: 600; letter-spacing: -1.2px; color: var(--text); line-height: 1.25; }
.kpi-value .kpi-unit { font-family: var(--thai); font-size:var(--fs-md); font-weight: 400; color: var(--text-3); letter-spacing: 0; margin-left: 7px; }
.kpi-delta { font-size:var(--fs-xs); color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi-delta b { font-family: Inter, sans-serif; font-weight: 600; }
.kpi-delta.up b { color: var(--ok); }
.kpi-delta.down b { color: var(--bad); }
.kpi-card.blue { background: linear-gradient(150deg, #123a6b22, transparent 70%); border-color: #1c4a8433; }
.kpi-card.blue .kpi-icon { background: #14355e; color: #7fb0ea; }
.kpi-card.green { background: linear-gradient(150deg, #10593f22, transparent 70%); border-color: #17795433; }
.kpi-card.green .kpi-icon { background: #12402f; color: #4cc39c; }
.kpi-card.amber { background: linear-gradient(150deg, #0b5c8a22, transparent 70%); border-color: #127fb833; }
.kpi-card.amber .kpi-icon { background: #12374f; color: #54bdf2; }
.kpi-card.violet { background: linear-gradient(150deg, #4a2b8022, transparent 70%); border-color: #5f39a333; }
.kpi-card.violet .kpi-icon { background: #2c2350; color: #a793e8; }

.dash-row { display: grid; gap: 18px; margin-bottom: 18px; }
.dash-row.three { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1.1fr) minmax(0, .95fr); }
.dash-row.two { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.dash-row.one { grid-template-columns: minmax(0, 1fr); }
.dash-panel { background: var(--surface); border: 1px solid var(--edge); border-radius: 12px; padding: 20px; overflow: hidden; }
.dash-panel > h2 { font-size:var(--fs-lg); font-weight: 600; margin: 0 0 4px; color: var(--text); }
.dash-panel > p.dash-sub { font-size:var(--fs-xs); color: var(--text-3); margin: 0 0 16px; }
.dash-legend { display: flex; gap: 16px; font-size:var(--fs-xs); color: var(--text-2); margin-left: auto; }
.dash-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dash-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dash-panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.dash-panel-head h2 { margin: 0; font-size:var(--fs-lg); font-weight: 600; color: var(--text); }

.dash-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.dash-axis { fill: var(--text-3); font-family: Inter, var(--thai); font-size:var(--fs-2xs); }
.dash-gridline { stroke: var(--grid); stroke-width: 1; }
.dash-barlabel { fill: var(--text-2); font-family: Inter, sans-serif; font-size:var(--fs-2xs); }

.donut-wrap { display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap; }
.donut-wrap svg { flex: 0 0 220px; width: 220px; max-width: 100%; height: auto; aspect-ratio: 1; }
.donut-track { stroke: var(--surface-3); }
.donut-center-label { fill: var(--text-2); font-size: 10px; font-weight: 500; }
.donut-center-value { fill: var(--text); font-family: Inter, sans-serif; font-size:var(--fs-base); font-weight: 600; }
.donut-center-unit { fill: var(--text-2); font-size:var(--fs-2xs); }
.donut-legend { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 9px; }
.donut-legend div { display: flex; align-items: center; gap: 9px; font-size:var(--fs-xs); color: var(--text-2); }
.donut-legend i { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.donut-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.donut-legend b { margin-left: auto; font-family: Inter, sans-serif; font-weight: 500; color: var(--text); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 6px; }
.donut-legend b span { white-space: nowrap; }
.donut-legend .donut-legend-percent { color: var(--text-2); font-weight: 600; }
.donut-label { pointer-events: none; }
.donut-percent-badge { fill: var(--surface); stroke: var(--edge); stroke-width: .6px; }
.donut-percent { fill: var(--text); stroke: none; font-family: Inter, sans-serif; font-size: 11px; font-weight: 600; }

.rank-list { display: flex; flex-direction: column; gap: 13px; }
.rank-row { display: flex; align-items: center; gap: 11px; font-size:var(--fs-xs); color: var(--text-2); }
.rank-row .rank-no {
    width: 20px; height: 20px; border-radius: 6px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-3); color: var(--text-3);
    font-family: Inter, sans-serif; font-size:var(--fs-2xs);
}
.rank-row .rank-name { width: 74px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .rank-track { flex: 1; height: 15px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.rank-row .rank-fill { display: block; height: 100%; border-radius: 4px; background: var(--info); }
.rank-row .rank-value { font-family: Inter, sans-serif; font-size:var(--fs-xs); color: var(--text); white-space: nowrap; }

.dash-table { width: 100%; border-collapse: collapse; }
.dash-table th { background: transparent; border-bottom: 1px solid var(--edge); color: var(--text-3); font-size:var(--fs-2xs); padding: 9px 12px; text-align: right; }
.dash-table th:first-child { text-align: left; }
.dash-table td { border-bottom: 1px solid var(--edge); font-size:var(--fs-xs); padding: 10px 12px; text-align: right; color: var(--text-2); font-family: Inter, sans-serif; }
.dash-table td:first-child { text-align: left; font-family: var(--thai); color: var(--text); }
.dash-table tr:last-child td { border-bottom: 0; }
.dash-table tfoot td { border-top: 1px solid var(--edge-2); border-bottom: 0; color: var(--info); font-weight: 600; }
.dash-table .grand { color: var(--info); font-weight: 600; }

.dash-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 4px; flex-wrap: wrap; }
.dash-foot .dash-foot-title { font-size:var(--fs-base); font-weight:700; }

@media (max-width: 1250px) {
    /* ไม่บังคับสองช่องแล้ว ปล่อยให้ auto-fit ลดจำนวนคอลัมน์เองตามที่ว่างจริง จะได้ไม่เหลือใบโดด */
    .dash-row.three, .dash-row.two, .dash-row.one { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .dash-bar { padding: 14px; gap: 12px; }
    .dash-filter select { min-width: 0; width: 100%; }
    .dash-filter { flex: 1 1 140px; }
    .kpi-value { font-size: 26px; }
    .donut-wrap svg { flex-basis: 208px; width: 208px; }
}
