:root {
    --accent: #ec4899;
    --accent-soft: #fdf2f8;
    --accent-strong: #be185d;
    --ink: #14213d;
    --muted: #64748b;
    --line: #dbe4f0;
}

* { box-sizing: border-box; }

html { background: #f3f6fb; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 0 0, rgba(59, 130, 246, .08), transparent 28rem),
        linear-gradient(180deg, #f8fafc 0, #f3f6fb 32rem, #eef3f9 100%);
    font-family: 'Noto Sans Thai', Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body[data-department="call"] {
    --accent: #f97316;
    --accent-soft: #fff7ed;
    --accent-strong: #c2410c;
}

body[data-department="withdraw"] {
    --accent: #10b981;
    --accent-soft: #ecfdf5;
    --accent-strong: #047857;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

.app-shell {
    width: min(1880px, 100%);
    margin: 0 auto;
    padding: 18px 22px 30px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 90;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 74px;
    margin: -18px -22px 18px;
    padding: 13px 26px;
    border-bottom: 1px solid rgba(203, 213, 225, .8);
    background: rgba(248, 250, 252, .88);
    backdrop-filter: blur(18px);
}

.brand-lockup { text-align: center; }
.brand-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0;
    color: #14213d;
    font-size: clamp(21px, 2vw, 29px);
    font-weight: 900;
    letter-spacing: 0;
}
.brand-subtitle { margin-top: 2px; color: #64748b; font-size: 13px; font-weight: 600; }

.topbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.soft-button, .icon-button, .primary-button, .ghost-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border-radius: 13px;
    border: 1px solid #d8e2ef;
    background: #fff;
    color: #334155;
    padding: 9px 14px;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
.soft-button:hover, .icon-button:hover, .ghost-button:hover {
    transform: translateY(-1px);
    border-color: #b9c8da;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .08);
}
.icon-button { width: 42px; padding: 0; }
.primary-button {
    min-height: 48px;
    padding: 11px 22px;
    border-color: transparent;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 28%, transparent);
}
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 14px 28px color-mix(in srgb, var(--accent) 34%, transparent); }
.primary-button:disabled { opacity: .45; transform: none; box-shadow: none; }
.ghost-button { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 28%, #d8e2ef); background: var(--accent-soft); }

.preview-banner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding: 14px 17px;
    border: 1px solid #c4b5fd;
    border-radius: 18px;
    color: #4c1d95;
    background: linear-gradient(135deg, #faf5ff, #eef2ff);
    box-shadow: 0 8px 22px rgba(76, 29, 149, .06);
}
.preview-banner strong { display: block; font-size: 14px; }
.preview-banner p { margin: 2px 0 0; color: #6d28d9; font-size: 13px; font-weight: 600; }
.preview-badge { flex: none; border-radius: 999px; background: #6d28d9; color: #fff; padding: 6px 10px; font-size: 11px; font-weight: 900; text-decoration: none; }
.preview-badge.official { cursor: default; background: #047857; pointer-events: none; }

.workspace {
    overflow: hidden;
    border: 1px solid rgba(203, 213, 225, .92);
    border-radius: 27px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 22px 60px rgba(15, 23, 42, .10);
}

.workspace-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 17px 20px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #fff, #fbfdff);
}

.department-tabs { display: flex; gap: 7px; padding: 5px; border-radius: 16px; background: #edf2f7; }
.department-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 138px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #64748b;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 900;
    transition: all .17s ease;
}
.department-tab:hover { color: #334155; background: rgba(255,255,255,.65); }
.department-tab.active { color: #fff; background: var(--accent); box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 26%, transparent); }
.department-tab.denied { display: none; }

.toolbar-note { display: flex; align-items: center; gap: 8px; color: #64748b; font-size: 13px; font-weight: 600; }
.toolbar-note-dot { width: 9px; height: 9px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 5px #d1fae5; }

.control-panel {
    display: grid;
    grid-template-columns: minmax(180px, .7fr) minmax(210px, 1fr) minmax(240px, 1.3fr) minmax(190px, .8fr) auto;
    align-items: end;
    gap: 13px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
}
.field-label { display: block; margin: 0 0 6px 2px; color: #475569; font-size: 12px; font-weight: 700; letter-spacing: 0; }
.field-control {
    width: 100%;
    height: 45px;
    border: 1px solid #cdd9e7;
    border-radius: 13px;
    outline: none;
    background: #fff;
    color: #1e293b;
    padding: 0 13px;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 2px 5px rgba(15, 23, 42, .03);
    transition: border-color .16s ease, box-shadow .16s ease;
}
.field-control:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 13%, transparent); }
.field-control:disabled { cursor: not-allowed; color: #475569; background: #eef2ff; opacity: 1; }
body.legacy-combined .control-panel { background: linear-gradient(90deg, #f5f3ff, #f8fafc); }

.context-strip {
    display: grid;
    grid-template-columns: minmax(300px, 1.5fr) repeat(3, minmax(150px, .55fr));
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}
.context-main, .context-stat {
    min-height: 78px;
    border: 1px solid #e2e8f0;
    border-radius: 17px;
    background: #fff;
    padding: 13px 15px;
}
.context-main { display: flex; align-items: center; gap: 13px; border-color: color-mix(in srgb, var(--accent) 24%, #e2e8f0); background: linear-gradient(135deg, var(--accent-soft), #fff); }
.context-icon { display: grid; flex: none; width: 47px; height: 47px; place-items: center; border-radius: 15px; background: var(--accent); color: #fff; font-size: 23px; box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 25%, transparent); }
.context-title { margin: 0; color: #1e293b; font-size: 16px; font-weight: 900; }
.context-description { margin: 2px 0 0; color: #64748b; font-size: 12px; font-weight: 600; }
.source-pill { display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; border-radius: 999px; padding: 4px 8px; color: #92400e; background: #fef3c7; font-size: 11px; font-weight: 700; }
.source-pill.snapshot { color: #065f46; background: #d1fae5; }
.context-stat { display: flex; flex-direction: column; justify-content: center; }
.context-stat span { color: #64748b; font-size: 11px; font-weight: 700; }
.context-stat strong { margin-top: 2px; color: #1e293b; font-size: 20px; font-weight: 900; }
.context-stat small { color: #64748b; font-size: 11px; font-weight: 600; }

.table-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    min-height: 70px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}
.table-heading h2 { margin: 0; color: #172033; font-size: 19px; font-weight: 900; }
.table-heading p { margin: 2px 0 0; color: #64748b; font-size: 12px; font-weight: 600; }
.website-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.website-chip { border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 800; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .08); }

.table-viewport {
    position: relative;
    overflow: auto;
    min-height: 390px;
    max-height: calc(100vh - 465px);
    background: #f8fafc;
    scrollbar-color: #9aa9bc #e9eef5;
    scrollbar-width: thin;
}
.table-viewport::-webkit-scrollbar { width: 11px; height: 11px; }
.table-viewport::-webkit-scrollbar-track { background: #e9eef5; }
.table-viewport::-webkit-scrollbar-thumb { border: 3px solid #e9eef5; border-radius: 999px; background: #9aa9bc; }

.work-table { width: 100%; min-width: 1120px; border-collapse: separate; border-spacing: 0; background: #fff; }
.work-table th, .work-table td { height: 49px; border-right: 1px solid #dce5f0; border-bottom: 1px solid #dce5f0; padding: 0; white-space: nowrap; }
.work-table thead th { position: sticky; top: 0; z-index: 30; height: 48px; color: #334155; background: #e8eef6; font-size: 12px; font-weight: 800; text-align: center; }
.work-table thead tr.subhead th { top: 48px; z-index: 29; height: 39px; background: #f1f5f9; }
.work-table tbody tr:hover td { background-color: #f8fbff; }
.work-table tbody tr.status-row td { background-color: var(--row-status-color, #fff7ed); }
.work-table .sticky-code, .work-table .sticky-name { position: sticky; z-index: 20; background: #fff; }
.work-table .sticky-code { left: 0; width: 72px; min-width: 72px; text-align: center; }
.work-table .sticky-name { left: 72px; width: 162px; min-width: 162px; box-shadow: 5px 0 9px rgba(15, 23, 42, .045); }
.work-table thead .sticky-code, .work-table thead .sticky-name { z-index: 50; background: #dfe7f1; }
.employee-code { color: #475569; font-family: inherit; font-size: 13px; font-weight: 800; }
.employee-name { overflow: hidden; padding: 0 12px; color: #1e293b; font-size: 13px; font-weight: 800; text-overflow: ellipsis; }
.employee-name small { display: block; color: #64748b; font-size: 10px; font-weight: 600; }
.employee-name .legacy-origin {
    max-width: 100%;
    overflow: hidden;
    color: #7c3aed;
    font-size: 10px;
    line-height: 1.35;
    text-overflow: ellipsis;
}
body.legacy-combined .work-table .sticky-name { width: 230px; min-width: 230px; }
body.legacy-combined .work-table th,
body.legacy-combined .work-table td { height: 58px; }
.website-header { color: var(--website-text, #fff) !important; background: var(--website-color, #475569) !important; }
.metric-header { min-width: 84px; }
.metric-cell { min-width: 84px; background: #fff; }
.metric-input {
    width: 100%;
    height: 48px;
    border: 0;
    outline: none;
    background: transparent;
    color: #1e293b;
    padding: 0 8px;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
}
.metric-input:focus { position: relative; z-index: 4; background: #fff; box-shadow: inset 0 0 0 2px var(--accent), 0 4px 12px rgba(15, 23, 42, .08); }
.total-cell { min-width: 92px; padding: 0 10px !important; color: #0f766e; background: #ecfdf5 !important; font-size: 13px; font-weight: 900; text-align: center; }
.status-cell { min-width: 150px; padding: 5px 7px !important; background: #fff; }
.status-select { width: 100%; height: 37px; border: 1px solid #cbd5e1; border-radius: 10px; outline: none; background: #fff; padding: 0 8px; color: #334155; font-size: 12px; font-weight: 700; }
.status-select:disabled { color: #94a3b8; background: #f1f5f9; }
.note-cell { min-width: 185px; padding: 5px 7px !important; background: #fff; }
.note-input { width: 100%; height: 37px; border: 1px solid transparent; border-radius: 9px; outline: none; background: #f8fafc; padding: 0 10px; color: #475569; font-size: 12px; font-weight: 600; }
.note-input:focus { border-color: var(--accent); background: #fff; }

.empty-state { display: grid; min-height: 390px; place-items: center; padding: 50px 20px; text-align: center; }
.empty-state-icon { display: grid; width: 72px; height: 72px; margin: 0 auto 14px; place-items: center; border-radius: 23px; background: var(--accent-soft); color: var(--accent-strong); font-size: 35px; }
.empty-state h3 { margin: 0; color: #334155; font-size: 18px; font-weight: 900; }
.empty-state p { max-width: 560px; margin: 5px auto 0; color: #94a3b8; font-size: 12px; font-weight: 700; }

.savebar {
    position: sticky;
    bottom: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto auto;
    align-items: center;
    gap: 15px;
    min-height: 79px;
    padding: 13px 20px;
    border-top: 1px solid #cfd9e6;
    background: rgba(248, 250, 252, .95);
    backdrop-filter: blur(14px);
}
.save-state { display: flex; align-items: center; gap: 11px; }
.save-state-icon { display: grid; width: 39px; height: 39px; place-items: center; border-radius: 13px; color: #64748b; background: #e2e8f0; }
.save-state.dirty .save-state-icon { color: #92400e; background: #fef3c7; }
.save-state.saved .save-state-icon { color: #047857; background: #d1fae5; }
.save-state strong { display: block; color: #334155; font-size: 12px; font-weight: 900; }
.save-state small { display: block; color: #94a3b8; font-size: 10px; font-weight: 700; }
.daily-totals { display: flex; gap: 8px; }
.daily-total { min-width: 105px; border: 1px solid #dce5f0; border-radius: 13px; background: #fff; padding: 7px 11px; text-align: right; }
.daily-total span { display: block; color: #94a3b8; font-size: 9px; font-weight: 900; }
.daily-total strong { display: block; color: #334155; font-size: 15px; font-weight: 900; }

.loading-overlay { position: absolute; inset: 0; z-index: 65; display: none; place-items: center; background: rgba(248,250,252,.82); backdrop-filter: blur(3px); }
.loading-overlay.visible { display: grid; }
.loading-card { border: 1px solid #dce5f0; border-radius: 18px; background: #fff; padding: 18px 24px; color: #475569; box-shadow: 0 18px 45px rgba(15,23,42,.14); font-size: 13px; font-weight: 900; }

.modal-backdrop { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(15,23,42,.68); backdrop-filter: blur(7px); }
.modal-backdrop.visible { display: flex; }
.modal-card { width: min(440px, 100%); overflow: hidden; border-radius: 24px; background: #fff; box-shadow: 0 30px 80px rgba(15,23,42,.28); }
.modal-content { padding: 27px; text-align: center; }
.modal-icon { font-size: 47px; }
.modal-content h3 { margin: 10px 0 5px; color: #1e293b; font-size: 20px; font-weight: 900; }
.modal-content p { margin: 0; color: #64748b; font-size: 12px; font-weight: 700; white-space: pre-line; }
.modal-backdrop.detail-modal .modal-card { width: min(590px, 100%); }
.modal-backdrop.detail-modal .modal-content p {
    max-height: 45vh;
    overflow: auto;
    border-radius: 14px;
    background: #f8fafc;
    padding: 13px 15px;
    text-align: left;
    line-height: 1.65;
}
.modal-actions { display: flex; gap: 9px; padding: 14px; border-top: 1px solid #e2e8f0; background: #f8fafc; }
.modal-actions button { flex: 1; min-height: 43px; border: 0; border-radius: 12px; font-weight: 900; }
.modal-cancel { color: #475569; background: #e2e8f0; }
.modal-confirm { color: #fff; background: var(--accent); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 230; display: flex; align-items: center; gap: 10px; max-width: 390px; border: 1px solid #bbf7d0; border-radius: 16px; background: #f0fdf4; color: #166534; padding: 12px 15px; box-shadow: 0 18px 44px rgba(15,23,42,.16); font-size: 12px; font-weight: 800; transform: translateY(30px); opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { border-color: #fecaca; color: #991b1b; background: #fef2f2; }

.production-link { border-color: #c4b5fd; color: #6d28d9; background: #f5f3ff; }
.emergency-link { border-color: #fecaca; color: #b91c1c; background: #fff7f7; }
.emergency-link:hover { border-color: #fca5a5; background: #fef2f2; }
body.production-mode .preview-banner { border-color: #fbbf24; background: linear-gradient(90deg, #fffbeb, #fff7ed); }
body.production-mode .preview-banner strong { color: #92400e; }
body.production-mode .preview-banner p { color: #9a3412; }

.summary-actionbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 11px 20px;
    border-bottom: 1px solid #dce5f0;
    background: linear-gradient(90deg, #f8fafc, #f5f3ff);
}
.summary-actionbar-copy strong { display: block; color: #334155; font-size: 13px; font-weight: 800; }
.summary-actionbar-copy small { display: block; margin-top: 1px; color: #64748b; font-size: 11px; font-weight: 600; }
.summary-action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.summary-button {
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 11px;
    padding: 0 13px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 5px 13px rgba(15, 23, 42, .1);
    transition: transform .15s ease, filter .15s ease;
}
.summary-button:hover { filter: brightness(.96); transform: translateY(-1px); }
.summary-button:disabled { cursor: not-allowed; filter: grayscale(.35); opacity: .55; transform: none; }
.summary-button.monthly { background: #0d9488; }
.summary-button.supervisor { background: #dc2626; }
.summary-button.global { background: #7c3aed; }

.emergency-backdrop {
    position: fixed;
    inset: 0;
    z-index: 210;
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow: auto;
    padding: 24px;
    background: rgba(15, 23, 42, .82);
    backdrop-filter: blur(9px);
}
.emergency-backdrop.visible { display: flex; }
body.emergency-open .modal-backdrop { z-index: 240; }
body.emergency-open .toast { z-index: 250; }
.emergency-dialog {
    width: min(1280px, 100%);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 24px;
    background: #f8fafc;
    box-shadow: 0 35px 100px rgba(15, 23, 42, .42);
}
.emergency-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 21px 24px;
    color: #fff;
    background: linear-gradient(135deg, #172033, #293750);
}
.emergency-kicker { display: block; margin-bottom: 4px; color: #fda4af; font-size: 9px; font-weight: 900; letter-spacing: .12em; }
.emergency-header h2 { margin: 0; font-size: 22px; font-weight: 900; }
.emergency-header p { margin: 4px 0 0; color: #cbd5e1; font-size: 11px; font-weight: 600; }
.emergency-close { display: grid; width: 43px; height: 43px; flex: none; place-items: center; border: 0; border-radius: 13px; color: #fff; background: rgba(255,255,255,.12); font-size: 27px; }
.emergency-datebar {
    display: grid;
    grid-template-columns: 250px 1fr auto;
    align-items: end;
    gap: 13px;
    padding: 14px 20px;
    border-bottom: 1px solid #dce5f0;
    background: #fff;
}
.emergency-datebar label > span { display: block; margin: 0 0 5px 2px; color: #475569; font-size: 11px; font-weight: 800; }
.emergency-datebar input,
.emergency-field input,
.emergency-field select {
    width: 100%;
    height: 42px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    outline: none;
    background: #fff;
    padding: 0 11px;
    color: #1e293b;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
}
.emergency-datebar input:focus,
.emergency-field input:focus,
.emergency-field select:focus { border-color: #8b5cf6; box-shadow: 0 0 0 3px rgba(139, 92, 246, .11); }
.emergency-load-state { align-self: center; color: #64748b; font-size: 11px; font-weight: 700; }
.emergency-load-state.loading { color: #7c3aed; }
.emergency-load-state.error { color: #b91c1c; }
.emergency-reload { height: 42px; border: 1px solid #c4b5fd; border-radius: 11px; background: #f5f3ff; color: #6d28d9; padding: 0 15px; font-size: 11px; font-weight: 900; }
.emergency-grid { display: grid; grid-template-columns: minmax(300px, .72fr) minmax(560px, 1.28fr); gap: 16px; padding: 18px; }
.emergency-card { border: 1px solid #dce5f0; border-radius: 19px; background: #fff; padding: 18px; box-shadow: 0 7px 20px rgba(15,23,42,.05); }
.emergency-card-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.emergency-card-icon { display: grid; width: 44px; height: 44px; flex: none; place-items: center; border-radius: 14px; font-size: 22px; }
.emergency-card-icon.danger { background: #fee2e2; }
.emergency-card-icon.safe { background: #e0e7ff; }
.emergency-card-heading h3 { margin: 0; color: #1e293b; font-size: 17px; font-weight: 900; }
.emergency-card-heading p { margin: 2px 0 0; color: #64748b; font-size: 10px; font-weight: 600; }
.emergency-field { display: block; min-width: 0; }
.emergency-field > span { display: block; margin: 0 0 5px 2px; color: #475569; font-size: 10px; font-weight: 800; }
.emergency-field + .emergency-field { margin-top: 12px; }
.emergency-range-fields { margin-top: 12px; border: 1px solid #fed7aa; border-radius: 13px; background: #fffaf5; padding: 11px; }
.emergency-range-fields[hidden] { display: none; }
.emergency-range-check { width: 100%; height: 38px; margin-top: 10px; border: 1px solid #fdba74; border-radius: 10px; background: #fff; color: #9a3412; font-family: inherit; font-size: 11px; font-weight: 900; }
.emergency-range-check:disabled { cursor: not-allowed; opacity: .5; }
.emergency-range-fields > small { display: block; margin-top: 7px; color: #9a3412; font-size: 9px; font-weight: 700; text-align: center; }
.emergency-summary { margin: 13px 0; border: 1px solid #e2e8f0; border-radius: 13px; background: #f8fafc; padding: 11px 12px; color: #475569; font-size: 11px; font-weight: 700; line-height: 1.55; white-space: pre-line; }
.reset-card .emergency-summary { border-color: #fed7aa; background: #fff7ed; color: #9a3412; }
.confirm-field input { border-color: #fecaca; background: #fffafa; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.emergency-danger-button,
.emergency-primary-button { width: 100%; min-height: 44px; border: 0; border-radius: 12px; color: #fff; font-size: 12px; font-weight: 900; }
.emergency-danger-button { margin-top: 12px; background: #dc2626; }
.emergency-primary-button { margin-top: 13px; background: #4f46e5; }
.emergency-danger-button:disabled,
.emergency-primary-button:disabled { cursor: not-allowed; filter: grayscale(.35); opacity: .48; }
.emergency-warning { display: block; margin-top: 8px; color: #991b1b; font-size: 9px; font-weight: 700; text-align: center; }
.emergency-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.emergency-form-grid .emergency-field + .emergency-field { margin-top: 0; }
.employee-picker-grid { grid-template-columns: .8fr 1.2fr; }
.emergency-placements { margin: 13px 0; border: 1px solid #bfdbfe; border-radius: 13px; background: #eff6ff; padding: 10px 12px; }
.emergency-placements > span { display: block; margin-bottom: 6px; color: #1d4ed8; font-size: 9px; font-weight: 900; text-transform: uppercase; }
.emergency-placement-list { display: flex; flex-wrap: wrap; gap: 6px; }
.emergency-placement-chip { display: inline-flex; align-items: center; border: 1px solid #bfdbfe; border-radius: 999px; background: #fff; color: #1e3a8a; padding: 5px 8px; font-size: 9px; font-weight: 800; }
.emergency-target-box { margin-top: 14px; border: 1px solid #c7d2fe; border-radius: 15px; background: #f5f3ff; padding: 12px; }
.emergency-target-box[hidden] { display: none; }
.emergency-target-box > strong { display: block; margin-bottom: 9px; color: #5b21b6; font-size: 11px; font-weight: 900; }
.target-grid { grid-template-columns: .72fr .9fr 1.38fr; }
.action-summary { margin-bottom: 0; border-color: #c7d2fe; background: #f5f3ff; color: #5b21b6; }

.report-backdrop {
    position: fixed;
    inset: 0;
    z-index: 205;
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow: auto;
    padding: 24px;
    background: rgba(15, 23, 42, .78);
    backdrop-filter: blur(8px);
}
.report-backdrop.visible { display: flex; }
.report-dialog {
    width: min(1580px, 100%);
    min-height: min(720px, calc(100vh - 48px));
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 25px;
    background: #f8fafc;
    box-shadow: 0 35px 100px rgba(15, 23, 42, .38);
}
.report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 20px 24px;
    color: #fff;
    background: linear-gradient(135deg, #172033, #293750);
}
.report-header h2 { margin: 0; font-size: 21px; font-weight: 800; }
.report-header p { margin: 3px 0 0; color: #cbd5e1; font-size: 12px; font-weight: 600; }
.report-close { display: grid; width: 42px; height: 42px; flex: none; place-items: center; border: 0; border-radius: 13px; color: #fff; background: rgba(255,255,255,.12); font-size: 28px; line-height: 1; }
.report-toolbar {
    display: flex;
    align-items: end;
    gap: 11px;
    padding: 14px 20px;
    border-bottom: 1px solid #dce5f0;
    background: #fff;
}
.report-date-controls { display: flex; gap: 9px; }
.report-toolbar label { display: block; }
.report-toolbar label > span { display: block; margin: 0 0 5px 2px; color: #475569; font-size: 11px; font-weight: 700; }
.report-toolbar input,
.report-toolbar select {
    height: 40px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    outline: none;
    background: #fff;
    padding: 0 11px;
    color: #334155;
    font-size: 12px;
    font-weight: 700;
}
.report-toolbar input:focus,
.report-toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.report-scope-control { min-width: 280px; flex: 1; }
.report-scope-control select { width: 100%; }
.report-load { min-height: 40px; border: 0; border-radius: 11px; background: var(--accent); color: #fff; padding: 0 17px; font-size: 11px; font-weight: 900; }
.report-load:disabled { opacity: .55; }
.report-context-note { padding: 8px 20px; border-bottom: 1px solid #dce5f0; color: #5b21b6; background: #f5f3ff; font-size: 12px; font-weight: 700; }
.report-content { min-height: 500px; padding: 18px; }
.report-loading,
.report-empty { display: flex; min-height: 430px; align-items: center; justify-content: center; flex-direction: column; gap: 10px; color: #64748b; text-align: center; }
.report-loading span,
.report-empty span { font-size: 38px; }
.report-loading strong,
.report-empty strong { max-width: 650px; font-size: 13px; font-weight: 900; }
.report-empty.error { color: #b91c1c; }
.report-cards { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.report-card { border: 1px solid #dce5f0; border-radius: 16px; background: #fff; padding: 12px 14px; box-shadow: 0 5px 14px rgba(15,23,42,.04); }
.report-card span { display: block; color: #64748b; font-size: 11px; font-weight: 700; }
.report-card strong { display: block; margin-top: 1px; color: #334155; font-size: 22px; font-weight: 900; }
.report-card.emerald strong { color: #059669; }
.report-card.blue strong { color: #2563eb; }
.report-card.violet strong { color: #7c3aed; }
.report-card.amber strong { color: #d97706; }
.report-table-wrap { overflow: auto; max-height: calc(100vh - 310px); border: 1px solid #dce5f0; border-radius: 16px; background: #fff; }
.report-table { width: 100%; min-width: max-content; border-collapse: separate; border-spacing: 0; color: #334155; background: #fff; font-size: 12px; }
.report-table th,
.report-table td { height: 42px; min-width: 76px; border-right: 1px solid #dce5f0; border-bottom: 1px solid #dce5f0; padding: 5px 9px; text-align: center; white-space: nowrap; }
.report-table thead th { position: sticky; top: 0; z-index: 5; color: #334155; background: #e8eef6; font-weight: 900; }
.report-table thead tr:nth-child(2) th { top: 42px; background: #f1f5f9; }
.report-table tbody tr:nth-child(even) td { background: #f8fafc; }
.report-table tbody tr:hover td { background: #eff6ff; }
.report-table .report-code { color: #475569; font-family: inherit; font-weight: 800; }
.report-table .report-name { min-width: 170px; text-align: left; font-weight: 800; }
.report-table .report-grand { color: #6d28d9; background: #f5f3ff !important; font-size: 12px; font-weight: 900; }
.report-table .report-chat { color: #c2410c; background: #fff7ed !important; font-weight: 900; }
.report-table .report-group-one { color: #047857; background: #ecfdf5 !important; font-weight: 900; }
.report-table .report-group-two { color: #1d4ed8; background: #eff6ff !important; font-weight: 900; }
.report-table tfoot td { position: sticky; bottom: 0; z-index: 4; color: #fff; background: #334155; font-weight: 900; }
.report-status { display: inline-flex; border-radius: 999px; background: color-mix(in srgb, var(--status-color) 18%, #fff); color: color-mix(in srgb, var(--status-color) 75%, #0f172a); padding: 4px 8px; font-weight: 900; }

/* สรุปส่งหัวหน้า: จัดเป็นแผ่นเดียวสำหรับแคปหน้าจอเหมือนระบบเดิม */
.report-backdrop.supervisor-mode { padding: 10px; background: rgba(15, 23, 42, .82); }
.supervisor-mode .report-dialog {
    width: min(1840px, 100%);
    height: calc(100vh - 20px);
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 15px;
    background: #f4f7fb;
}
.supervisor-mode .report-header { min-height: 64px; flex: none; padding: 15px 20px; background: #1e293b; }
.supervisor-mode .report-header h2 { font-size: 18px; font-weight: 800; }
.supervisor-mode .report-header p,
.supervisor-mode .report-toolbar,
.supervisor-mode .report-context-note { display: none; }
.supervisor-mode .report-content { min-height: 0; flex: 1; overflow: hidden; padding: 30px; background: #f4f7fb; }
.supervisor-sheet {
    display: flex;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #d6e0ec;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .08);
}
.supervisor-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex: none;
    min-height: 145px;
    padding: 25px 24px;
    border-bottom: 4px solid #3b82f6;
    color: #fff;
    background: #1e293b;
}
.supervisor-sheet-heading { display: flex; align-items: center; gap: 18px; min-width: 0; }
.supervisor-sheet-icon {
    display: grid;
    width: 66px;
    height: 66px;
    flex: none;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 13px;
    background: rgba(255, 255, 255, .1);
    font-size: 36px;
}
.supervisor-sheet-heading h3 {
    margin: 0 0 8px;
    color: #fff;
    font-size: clamp(24px, 2vw, 34px);
    font-weight: 800;
    line-height: 1.25;
}
.supervisor-date-badge {
    display: inline-flex;
    align-items: center;
    min-height: 43px;
    border: 2px solid #60a5fa;
    border-radius: 11px;
    padding: 7px 16px;
    color: #fff;
    background: #2563eb;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 6px 14px rgba(37, 99, 235, .24);
}
.supervisor-kpis { display: flex; flex: none; gap: 14px; }
.supervisor-kpi {
    min-width: 135px;
    border: 1px solid #475569;
    border-radius: 13px;
    padding: 13px 18px;
    background: #334155;
    text-align: center;
}
.supervisor-kpi span { display: block; color: #cbd5e1; font-size: 11px; font-weight: 700; }
.supervisor-kpi strong { display: block; margin-top: 2px; font-size: 28px; font-weight: 900; line-height: 1.2; }
.supervisor-kpi.blue strong { color: #60a5fa; }
.supervisor-kpi.orange strong { color: #fb923c; }
.supervisor-kpi.emerald strong { color: #34d399; }
.supervisor-kpi.yellow strong { color: #facc15; }
.supervisor-sheet-body { min-height: 0; display: flex; flex: 1; padding: 25px; background: #f8fafc; }
.supervisor-table-wrap {
    min-height: 0;
    max-height: none;
    flex: 1;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    border-radius: 0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
}
.supervisor-mode .report-table {
    --report-code-width: 64px;
    --report-name-width: 160px;
    --report-nickname-width: 88px;
    width: 100%;
    min-width: 1220px;
    font-size: 12px;
}
.supervisor-mode .report-table th,
.supervisor-mode .report-table td {
    height: 46px;
    min-width: 54px;
    padding: 6px 6px;
    border-color: #cfd9e6;
    font-weight: 700;
}
.supervisor-mode .report-table thead th {
    position: sticky;
    top: 0;
    z-index: 15;
    color: #1e293b;
    background: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.35;
}
.supervisor-mode .report-table thead tr:first-child th { height: 65px; }
.supervisor-mode .report-table thead tr:nth-child(2) th {
    position: sticky;
    top: 65px;
    z-index: 16;
    background: #f8fafc;
}
.supervisor-mode .report-table thead th[style] {
    font-size: 11px;
    text-transform: uppercase;
    white-space: normal;
}
.supervisor-mode .report-site-label {
    display: inline-block;
    max-width: 82px;
    line-height: 1.2;
    white-space: normal;
    word-break: normal;
}
.supervisor-mode .report-table .report-code { min-width: 64px; color: #1e293b; }
.supervisor-mode .report-table .report-name { width: 160px; min-width: 160px; color: #1e293b; }
.supervisor-mode .report-table thead tr:first-child > th:nth-child(1),
.supervisor-mode .report-table tbody > tr > td:nth-child(1) {
    width: var(--report-code-width);
    min-width: var(--report-code-width);
    max-width: var(--report-code-width);
    position: sticky;
    left: 0;
}
.supervisor-mode .report-table thead tr:first-child > th:nth-child(2),
.supervisor-mode .report-table tbody > tr > td:nth-child(2) {
    width: var(--report-name-width);
    min-width: var(--report-name-width);
    max-width: var(--report-name-width);
    position: sticky;
    left: var(--report-code-width);
}
.supervisor-mode .report-table thead tr:first-child > th:nth-child(3),
.supervisor-mode .report-table tbody > tr > td:nth-child(3) {
    width: var(--report-nickname-width);
    min-width: var(--report-nickname-width);
    max-width: var(--report-nickname-width);
    position: sticky;
    left: calc(var(--report-code-width) + var(--report-name-width));
    box-shadow: 5px 0 8px -8px rgba(15, 23, 42, .8);
}
.supervisor-mode .report-table thead tr:first-child > th:nth-child(-n+3) { z-index: 30; }
.supervisor-mode .report-table tbody > tr > td:nth-child(-n+3) {
    z-index: 8;
    background: #fff;
}
.supervisor-mode .report-table tbody > tr:nth-child(even) > td:nth-child(-n+3) { background: #f8fafc; }
.supervisor-mode .report-table tbody > tr:hover > td:nth-child(-n+3) { background: #eff6ff; }
.supervisor-mode .report-table .report-total-heading { background: #f1f5f9; }
.supervisor-mode .report-table .report-total-subhead { color: #b91c1c; background: #fef2f2; }
.supervisor-mode .report-table .report-grand-subhead,
.supervisor-mode .report-table .report-chat-heading { color: #9a3412; background: #fff7ed; }
.supervisor-mode .report-table .report-grand { color: #c2410c; background: #fff7ed !important; font-size: 13px; }
.supervisor-mode .report-table .report-chat { color: #c2410c; background: #fffaf5 !important; font-size: 13px; }
.supervisor-mode .report-table tfoot td {
    position: static;
    bottom: auto;
    height: 54px;
    color: #fff;
    background: #334155;
    font-size: 13px;
    font-weight: 800;
}
.supervisor-mode .report-table tfoot td:first-child {
    position: sticky;
    left: 0;
    z-index: 9;
}
.supervisor-mode .report-table tfoot .supervisor-total-highlight { color: #facc15; font-size: 15px; }
.supervisor-status-text { min-width: 82px !important; font-weight: 800 !important; }
.supervisor-mode .report-table tbody tr.supervisor-status-row td,
.supervisor-mode .report-table tbody tr.supervisor-status-row:hover td,
.supervisor-mode .report-table tbody tr.supervisor-status-row td.report-grand,
.supervisor-mode .report-table tbody tr.supervisor-status-row td.report-chat,
.supervisor-mode .report-table tbody tr.supervisor-status-row td.report-group-one,
.supervisor-mode .report-table tbody tr.supervisor-status-row td.report-group-two {
    color: var(--status-text) !important;
    background: var(--status-bg) !important;
    font-weight: 800;
}

@media (max-height: 900px) and (min-width: 1000px) {
    .report-backdrop.supervisor-mode { padding: 6px; }
    .supervisor-mode .report-header { min-height: 52px; padding: 9px 17px; }
    .supervisor-mode .report-content { padding: 14px; }
    .supervisor-sheet-header { min-height: 108px; padding: 15px 20px; }
    .supervisor-sheet-icon { width: 55px; height: 55px; font-size: 30px; }
    .supervisor-sheet-heading h3 { margin-bottom: 5px; font-size: 25px; }
    .supervisor-date-badge { min-height: 36px; padding: 5px 12px; font-size: 14px; }
    .supervisor-kpi { min-width: 120px; padding: 8px 14px; }
    .supervisor-kpi strong { font-size: 24px; }
    .supervisor-sheet-body { padding: 14px; }
    .supervisor-mode .report-table th,
    .supervisor-mode .report-table td { height: 39px; padding: 4px 5px; }
    .supervisor-mode .report-table thead tr:first-child th { height: 52px; }
    .supervisor-mode .report-table thead tr:nth-child(2) th { top: 52px; }
    .supervisor-mode .report-table tfoot td { height: 46px; }
}

@media (max-width: 1120px) {
    .control-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .control-panel .control-action { grid-column: span 2; }
    .context-strip { grid-template-columns: repeat(3, 1fr); }
    .context-main { grid-column: span 3; }
    .table-viewport { max-height: 60vh; }
    .summary-actionbar { align-items: flex-start; flex-direction: column; }
    .summary-action-buttons { justify-content: flex-start; }
    .report-cards { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    .emergency-grid { grid-template-columns: 1fr; }
    .supervisor-sheet-header { align-items: flex-start; flex-direction: column; }
    .supervisor-kpis { width: 100%; }
    .supervisor-kpi { flex: 1; }
}

@media (max-width: 760px) {
    .app-shell { padding: 10px; }
    .topbar { grid-template-columns: auto 1fr auto; margin: -10px -10px 10px; padding: 10px; }
    .brand-subtitle, .topbar .button-label, .toolbar-note { display: none; }
    .brand-title { font-size: 17px; }
    .preview-banner { border-radius: 14px; }
    .workspace { border-radius: 18px; }
    .workspace-toolbar { align-items: stretch; flex-direction: column; padding: 12px; }
    .department-tabs { overflow-x: auto; }
    .department-tab { min-width: 125px; }
    .control-panel { grid-template-columns: 1fr; padding: 13px; }
    .control-panel .control-action { grid-column: auto; }
    .context-strip { grid-template-columns: repeat(2, 1fr); padding: 12px; }
    .context-main { grid-column: span 2; }
    .context-stat:last-child { grid-column: span 2; }
    .table-heading { align-items: flex-start; flex-direction: column; padding: 12px; }
    .website-chips { justify-content: flex-start; }
    .summary-actionbar { padding: 10px 12px; }
    .summary-action-buttons { display: grid; width: 100%; grid-template-columns: 1fr; }
    .summary-button { width: 100%; }
    .savebar { grid-template-columns: 1fr auto; padding: 10px 12px; }
    .daily-totals { display: none; }
    .primary-button { padding: 10px 15px; }
    .report-backdrop { padding: 0; }
    .report-dialog { min-height: 100vh; border-radius: 0; }
    .report-header { padding: 15px; }
    .report-toolbar { align-items: stretch; flex-direction: column; padding: 12px; }
    .report-date-controls { display: grid; grid-template-columns: 1fr 1fr; }
    .report-date-controls label,
    .report-date-controls input,
    .report-scope-control { width: 100%; min-width: 0; }
    .report-content { padding: 10px; }
    .report-cards { grid-template-columns: repeat(2, 1fr); }
    .emergency-backdrop { padding: 0; }
    .emergency-dialog { min-height: 100vh; border-radius: 0; }
    .emergency-header { align-items: flex-start; padding: 16px; }
    .emergency-header h2 { font-size: 18px; }
    .emergency-datebar { grid-template-columns: 1fr; align-items: stretch; padding: 12px; }
    .emergency-grid { padding: 10px; }
    .emergency-form-grid,
    .employee-picker-grid,
    .target-grid { grid-template-columns: 1fr; }
    .supervisor-mode .report-content { padding: 10px; }
    .supervisor-sheet-header { min-height: 0; padding: 18px; }
    .supervisor-sheet-icon { width: 54px; height: 54px; font-size: 29px; }
    .supervisor-sheet-heading h3 { font-size: 21px; }
    .supervisor-date-badge { min-height: 38px; padding: 6px 11px; font-size: 13px; }
    .supervisor-kpis { display: grid; grid-template-columns: repeat(2, 1fr); }
    .supervisor-kpi { min-width: 0; padding: 10px; }
    .supervisor-kpi strong { font-size: 22px; }
    .supervisor-sheet-body { padding: 10px; }
}
