:root {
    --ink: #10201d;
    --muted: #64706d;
    --line: #d9e1de;
    --paper: #ffffff;
    --canvas: #f4f7f6;
    --sidebar: #13211f;
    --green: #087f6b;
    --amber: #b76b00;
    --red: #c13f35;
    --blue: #286a9b;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); font-family: Tahoma, "Noto Sans Thai", sans-serif; font-size: 14px; letter-spacing: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; letter-spacing: 0; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 16px 20px; display: flex; flex-direction: column; background: var(--sidebar); color: #f7fbfa; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 30px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 6px; background: #f2bd3f; color: #11201d; font-weight: 800; }
.brand strong, .brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { font-size: 15px; }.brand small { margin-top: 3px; color: #b9ccc7; font-size: 11px; }
.sidebar-nav { display: grid; gap: 7px; }
.nav-item { min-height: 42px; display: flex; align-items: center; gap: 12px; padding: 0 14px; border-radius: 6px; color: #a8bbb6; }
.nav-item:hover { background: #1d302c; color: white; }.nav-item.is-active { background: #243733; color: white; }.nav-item.is-muted { opacity: .62; }
.nav-symbol { width: 14px; color: #5fc9b1; text-align: center; }
.sidebar-foot { margin-top: auto; padding: 18px 8px 0; border-top: 1px solid #29403b; display: flex; align-items: center; gap: 9px; }
.sidebar-foot strong { font-size: 12px; }.sidebar-foot small { margin-top: 3px; color: #8ea9a3; font-size: 10px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #48c79f; box-shadow: 0 0 0 4px rgba(72,199,159,.12); }

.main-content { min-width: 0; padding: 32px 42px 48px; }
.topbar { min-height: 84px; display: flex; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; align-items: flex-start; gap: 18px; flex-wrap: wrap; }
.cost-section { margin: 22px 0; padding: 20px; border: 1px solid var(--line); background: white; }
.cost-heading h2 { margin: 0 0 8px; font-size: 18px; }
.cost-heading p, .cost-footnote { color: var(--muted); font-size: 12px; line-height: 1.6; }
.cost-cards { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.cost-cards > div { padding: 16px; background: #f2f7f5; border-left: 3px solid #087f6b; }
.cost-cards span, .cost-cards strong { display: block; }
.cost-cards span { color: var(--muted); font-size: 12px; }.cost-cards strong { margin-top: 8px; font-size: 21px; overflow-wrap: anywhere; }
.cost-notice { padding: 10px 13px; background: #fff6df; color: #765c25; font-size: 12px; line-height: 1.6; }
.monthly-costs summary { cursor: pointer; padding: 10px 0; font-size: 13px; font-weight: bold; }
.cost-table-frame { overflow: auto; max-height: 300px; }
.cost-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.cost-table th, .cost-table td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cost-table th:first-child { text-align: left; }.cost-table thead th { position: sticky; top: 0; background: #e9f0ee; }.cost-table .selected-month { background: #e5f4ef; }.cost-table a { color: #076955; }
.finance-filters { display: flex; align-items: end; gap: 12px; margin: 22px 0; }.finance-filters button { border: 0; cursor: pointer; min-height: 40px; }
.source-breakdown { font-size: 13px; line-height: 1.7; }.no-activity { display: block; color: var(--muted); font-size: 10px; font-weight: normal; margin-top: 3px; }
.finance-transactions { overflow: auto; max-height: 440px; }.finance-transactions .transaction-description { min-width: 280px; max-width: 440px; white-space: normal; text-align: left; }
.finance-transactions .customer-name { min-width: 200px; max-width: 340px; white-space: normal; text-align: left; }.finance-transactions tfoot { background: #e9f0ee; font-weight: bold; }
.finance-customer-filter { max-width: 430px; margin-bottom: 16px; }
.overlap-note { display: block; color: #925809; font-size: 11px; margin-top: 4px; }
@media (max-width: 760px) { .sidebar { flex-wrap: wrap; }.sidebar-nav { flex-wrap: wrap; } }
@media (max-width: 1000px) { .cost-cards { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (max-width: 480px) { .cost-section { padding: 12px; }.cost-cards strong { font-size: 17px; } }
@media (max-width: 760px) { .topbar { flex-wrap: wrap; padding-bottom: 14px; } .topbar-actions { width: 100%; } }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 12px; font-weight: 700; }.topbar h1 { margin: 0; font-size: 30px; line-height: 1.2; }
.as-of { text-align: right; }.as-of span, .as-of strong { display: block; }.as-of span { color: var(--muted); font-size: 11px; }.as-of strong { margin-top: 5px; font-size: 12px; }
.alert { margin-top: 18px; padding: 13px 16px; display: flex; gap: 12px; background: #fff1ef; border-left: 3px solid var(--red); }.alert span { color: #7f302b; }

.control-band { padding: 20px 0 16px; border-bottom: 1px solid var(--line); }
#operationFilters { display: grid; grid-template-columns: 170px 180px minmax(260px, 1fr) 170px; gap: 10px; max-width: 980px; }
.filter-field { display: grid; gap: 6px; }.filter-field > span { color: var(--muted); font-size: 11px; font-weight: 700; }
.filter-field input, .filter-field select { width: 100%; height: 40px; border: 1px solid #cbd6d2; border-radius: 6px; padding: 0 12px; background: white; color: var(--ink); outline: none; }
.filter-field input:focus, .filter-field select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8,127,107,.1); }

.summary-strip { margin: 20px 0 24px; display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); background: var(--paper); border: 1px solid var(--line); }
.summary-strip > div { min-height: 78px; padding: 15px 18px; border-right: 1px solid var(--line); }.summary-strip > div:last-child { border-right: 0; }
.summary-strip span, .summary-strip strong { display: block; }.summary-strip span { color: var(--muted); font-size: 11px; }.summary-strip strong { margin-top: 6px; font-size: 23px; }
.text-green { color: var(--green); }.text-blue { color: var(--blue); }.text-amber { color: var(--amber); }.text-red { color: var(--red); }

.event-section { margin-bottom: 24px; }
.event-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 10px; }
.event-heading h2 { margin: 0; font-size: 16px; }.event-heading p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }.event-heading > span { color: var(--muted); font-size: 11px; }
.event-table-frame { max-height: 250px; overflow: auto; border: 1px solid var(--line); background: white; }
.event-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 11px; }
.event-table th, .event-table td { padding: 9px 10px; border-right: 1px solid #e1e7e5; border-bottom: 1px solid #e1e7e5; text-align: left; vertical-align: top; }
.event-table th { position: sticky; top: 0; z-index: 2; background: #e9f0ee; }.event-table th:last-child, .event-table td:last-child { border-right: 0; }
.event-table td:nth-child(1) { width: 105px; white-space: nowrap; }.event-table td:nth-child(2) { min-width: 165px; }.event-table td:nth-child(3) { min-width: 150px; }.event-table td:nth-child(5) { min-width: 150px; }.event-table td:nth-child(6) { min-width: 125px; }
.event-table td strong, .event-table td small { display: block; }.event-table td small { margin-top: 3px; color: var(--muted); }
.event-status { display: inline-block; margin-top: 4px; padding: 2px 6px; border-radius: 4px; font-size: 9px; }.event-status.status-approved { background: #dff1ec; color: #11624f; }.event-status.status-pending { background: #fff0d4; color: #8c5700; }.event-status.status-inferred { background: #e8eef1; color: #53636a; }
.event-cost { font-weight: 700; }.event-cost span { color: var(--amber); }.event-empty { padding: 20px; border: 1px solid var(--line); background: white; color: var(--muted); text-align: center; }

.operation-section { min-width: 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; max-width: 840px; font-size: 17px; }.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.section-tools { display: flex; align-items: end; gap: 16px; }
.date-navigator { display: flex; align-items: end; gap: 5px; }
.date-navigator label { display: grid; gap: 4px; }.date-navigator label span { color: var(--muted); font-size: 10px; font-weight: 700; }
.date-navigator input { width: 138px; height: 34px; border: 1px solid #cbd6d2; border-radius: 5px; padding: 0 8px; background: white; }
.date-navigator button { width: 34px; height: 34px; border: 1px solid #cbd6d2; border-radius: 5px; background: white; color: var(--ink); font-size: 21px; cursor: pointer; }
.date-navigator button:hover { border-color: var(--green); color: var(--green); }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px 12px; color: var(--muted); font-size: 10px; }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 2px; vertical-align: -1px; }
.legend-work::before { background: #dff1ec; }.legend-substitute::before { background: #dcecf8; }.legend-leave::before { background: #fff0d4; }.legend-deduction::before { background: #ffe1de; }.legend-wage::before { background: #ece7f7; }

.matrix-frame { position: relative; max-height: calc(100vh - 300px); min-height: 280px; overflow: auto; border: 1px solid #cbd6d2; background: white; }
.identity-header-overlay { position: absolute; top: 0; left: 0; z-index: 20; height: 66px; display: flex; background: #e9f0ee; box-shadow: 2px 0 0 #bdcac6, 0 1px 0 #bdcac6; pointer-events: none; will-change: transform; }
.identity-header-overlay span { height: 66px; display: grid; place-items: center; padding: 7px; border-right: 1px solid #d4ddda; text-align: center; font-size: 11px; font-weight: 700; }
.overlay-1 { width: 52px; }.overlay-2 { width: 98px; }.overlay-3 { width: 250px; }.overlay-4 { width: 112px; }.overlay-5 { width: 220px; }.overlay-6 { width: 180px; }
.operations-export { display: inline-flex; align-items: center; padding: 9px 13px; background: #087f6b; color: white; border-radius: 5px; text-decoration: none; white-space: nowrap; font-size: 12px; }
.operations-export:hover { background: #066653; }
.operations-export:focus-visible { outline: 3px solid #dfac24; outline-offset: 2px; }
.operation-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 11px; }
.operation-table th, .operation-table td { border-right: 1px solid #89968f; border-bottom: 1px solid #89968f; padding: 3px 6px; vertical-align: middle; overflow-wrap: anywhere; }
.operation-table thead th { position: sticky; z-index: 5; background: #e9f0ee; text-align: center; font-weight: 700; }
.operation-table thead tr:first-child th { top: 0; height: 34px; }.operation-table thead tr:nth-child(2) th { top: 34px; height: 32px; }
.operation-table tbody tr:hover td { box-shadow: inset 0 0 0 999px rgba(8,127,107,.035); }
.operation-table tr.group-start td { border-top: 2px solid #9eafaa; }.operation-table tr.group-detail .identity-column { color: #26352f; background: white; }
.operation-table tr.row-period .identity-5 { color: #d63232; }
.operation-table tr.row-period .identity-6 { color: #68716c; font-size: 10px; }
.operation-table tr.row-replacement .identity-5 { color: #185580; }
.operation-table .row-spacer td { height: 16px; padding: 0; }
.operation-table .status-cost-label { background: #fff2c8; color: #54431b; }
.operation-table .status-cost-amount { background: white; color: #142f57; font-variant-numeric: tabular-nums; }
.identity-column { position: sticky; z-index: 2; background: white; white-space: pre-line; }
thead .identity-column { z-index: 8; vertical-align: middle !important; }
.identity-continuation { padding: 0 !important; }
.identity-1 { left: 0; width: 52px; min-width: 52px; text-align: center; }.identity-2 { left: 52px; width: 98px; min-width: 98px; }.identity-3 { left: 150px; width: 250px; min-width: 250px; }.identity-4 { left: 400px; width: 112px; min-width: 112px; }.identity-5 { left: 512px; width: 220px; min-width: 220px; }.identity-6 { left: 732px; width: 180px; min-width: 180px; box-shadow: 2px 0 0 #bdcac6; }
.day-heading, .date-heading, .day-cell { width: 112px; min-width: 112px; text-align: center; }.date-heading { font-size: 13px; }.day-heading.is-weekend, .date-heading.is-weekend { background: #f0cece; color: #633737; }
.day-cell { height: 23px; white-space: pre-line; }.day-cell.is-weekend { background: #f0cece; }
.status-work { background: #edf8f5; color: #155f50; }.status-substitute { background: #e8f3fb; color: #205f8c; font-weight: 700; }.status-leave { background: #fff4df; color: #8c5700; }.status-deduction { background: #ffebe8; color: #a6332b; font-weight: 700; }.status-wage { background: #f0ecf8; color: #60478a; }
.operation-table [data-day].is-selected-date { box-shadow: inset 2px 0 #087f6b, inset -2px 0 #087f6b; }
.operation-table thead [data-day].is-selected-date { background: #cfe9e2; color: #075f51; }
.empty-state { position: sticky; left: 0; width: calc(100vw - 318px); padding: 42px; text-align: center; color: var(--muted); }.empty-state strong, .empty-state span { display: block; }.empty-state strong { color: var(--ink); margin-bottom: 5px; }

@media (max-width: 1100px) {
    .main-content { padding: 26px 24px 40px; }
    .summary-strip { grid-template-columns: repeat(6, minmax(100px, 1fr)); overflow-x: auto; }
    .identity-3 { width: 200px; min-width: 200px; }.identity-4 { left: 350px; }.identity-5 { left: 462px; width: 190px; min-width: 190px; }.identity-6 { left: 652px; width: 150px; min-width: 150px; }
    .overlay-3 { width: 200px; }.overlay-5 { width: 190px; }.overlay-6 { width: 150px; }
}

@media (max-width: 760px) {
    .app-shell { display: block; }.sidebar { position: static; width: 100%; height: auto; padding: 12px 14px; flex-direction: row; align-items: center; gap: 14px; }.brand { padding: 0; }.brand small, .sidebar-foot { display: none; }.sidebar-nav { margin-left: auto; display: flex; }.nav-item { min-height: 38px; padding: 0 10px; }.nav-item.is-muted { display: none; }
    .main-content { padding: 22px 14px 34px; }.topbar { min-height: 76px; }.topbar h1 { font-size: 24px; }.as-of { display: none; }
    #operationFilters { grid-template-columns: 1fr 1fr; max-width: none; }.filter-search { grid-column: 1 / -1; grid-row: 2; }.filter-status { grid-column: 1 / -1; grid-row: 3; }
    .summary-strip { grid-template-columns: repeat(6, 128px); }.summary-strip > div { min-height: 70px; padding: 12px; }.summary-strip strong { font-size: 20px; }
    .event-table { min-width: 780px; }
    .section-heading { align-items: start; flex-direction: column; }.section-tools { width: 100%; align-items: start; flex-direction: column; gap: 9px; }.legend { justify-content: flex-start; }
    .matrix-frame { max-height: calc(100vh - 330px); }
    .identity-1, .identity-2, .identity-4, .identity-6 { display: none; }
    .overlay-1, .overlay-2, .overlay-4, .overlay-6 { display: none !important; }
    .identity-3 { left: 0; width: 170px; min-width: 170px; }.identity-5 { left: 170px; width: 160px; min-width: 160px; box-shadow: 2px 0 0 #bdcac6; }
    .overlay-3 { width: 170px; }.overlay-5 { width: 160px; }
    .day-heading, .date-heading, .day-cell { width: 76px; min-width: 76px; }.empty-state { width: calc(100vw - 30px); }
}

@media (max-width: 430px) {
    .brand span:last-child { display: none; }.nav-symbol { display: none; }.nav-item { font-size: 12px; }
    .summary-strip { grid-template-columns: repeat(6, 116px); }
    .identity-3 { width: 145px; min-width: 145px; }.identity-5 { left: 145px; width: 145px; min-width: 145px; }
    .overlay-3, .overlay-5 { width: 145px; }
}
