/**
 * Admin Panel (commission-admin.html) — GearVN bento, tokens only.
 * Loaded after css/style.css; no theme selectors (variables.css owns per-theme values).
 */

/* ---------- Header ---------- */
.adm-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--surface);
    border-bottom: 2px solid var(--brand-600);
}
.adm-header__inner,
.adm-header__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1600px;
    margin-inline: auto;
    padding: 8px 24px;
}
.adm-header__bar {
    flex-wrap: wrap;
    padding-top: 0;
    padding-bottom: 12px;
}
.adm-header__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.adm-header__logo { display: inline-flex; padding: 8px 0; }
.adm-header__logo .gv-logo { width: 112px; }
.adm-header__title {
    margin: 0;
    padding-left: 12px;
    border-left: 1px solid var(--line);
    font-size: 18px;
    font-weight: 700;
    color: var(--ink-900);
    white-space: nowrap;
}
.adm-header__actions { display: flex; align-items: center; gap: 12px; }
.adm-header__actions .gv-select { width: auto; min-width: 11rem; }

.adm-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius-ctl);
    background: var(--surface-2);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.adm-tabs::-webkit-scrollbar { display: none; }
.admin-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink-600);
    font: 500 14px/1.2 var(--font-sans);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 150ms ease-out, color 150ms ease-out;
}
.admin-tab:hover { color: var(--ink-900); }
.admin-tab[aria-selected="true"] {
    background: var(--surface);
    color: var(--brand-ink);
    font-weight: 600;
    box-shadow: var(--shadow-1), inset 0 -2px 0 var(--brand-600);
}
.admin-tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Layout ---------- */
.adm-main { padding-top: 24px; }
.adm-stack { display: flex; flex-direction: column; gap: 16px; }
.adm-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.adm-kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
#profitSummaryCards { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* Panel = tile with its own padded head/body sections */
.adm-panel { padding: 0; overflow: hidden; }
.adm-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.adm-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.adm-title > i { color: var(--brand-ink); }

/* ---------- Form controls (legacy markup) ---------- */
.adm-main input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not(.kpi-cat-pct-input),
.adm-main select:not(.gv-select),
.adm-dialog input:not([type="hidden"]),
.adm-dialog select {
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-ctl);
    background: var(--surface);
    color: var(--ink-900);
    font: 400 14px/1.4 var(--font-sans);
}
.adm-main input::placeholder,
.adm-dialog input::placeholder { color: var(--ink-400); }
.adm-main input:focus,
.adm-main select:focus,
.adm-dialog input:focus,
.adm-dialog select:focus {
    outline: none;
    border-color: var(--brand-600);
    box-shadow: var(--focus-ring);
}
.adm-dialog label,
.adm-main label { color: var(--ink-600); font-size: 13px; font-weight: 500; }

.kpi-cat-pct-input {
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font: inherit;
}
.kpi-cat-pct-input:hover,
.kpi-cat-pct-input:focus { border-color: var(--line-strong); outline: none; }
.kpi-cat-pct-input::-webkit-inner-spin-button { opacity: 0; }
.kpi-cat-pct-input:hover::-webkit-inner-spin-button,
.kpi-cat-pct-input:focus::-webkit-inner-spin-button { opacity: 1; }
.kpi-cat-input { max-width: 10rem; }

/* KPI progress bar: status color + the % label next to it (never color alone) */
.kpi-cat-bar { background: var(--danger); }
.kpi-cat-bar[data-state="mid"] { background: var(--warning); }
.kpi-cat-bar[data-state="high"] { background: var(--success); }

/* ---------- Tables ---------- */
.adm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    color: var(--ink-900);
    font-variant-numeric: tabular-nums;
}
.adm-thead th {
    position: sticky;
    top: 0;
    height: 44px;
    background: var(--surface-2);
    color: var(--ink-600);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}
.adm-table tbody tr { transition: background-color 150ms ease-out; }
.adm-table tbody tr:hover { background: var(--brand-50); }
.adm-table td { vertical-align: middle; }
.adm-table td.text-right,
.adm-table th.text-right { white-space: nowrap; }
.rate-row:hover { background: var(--brand-50); }
.adm-row--inactive { background: var(--surface-2); color: var(--ink-600); }

.adm-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-ctl);
    background: transparent;
    cursor: pointer;
    transition: background-color 150ms ease-out;
}
.adm-icon-btn:hover { background: var(--surface-2); }
.adm-icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.adm-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    color: var(--ink-600);
    font-weight: 700;
}
.adm-rank--top { background: var(--brand-50); color: var(--brand-ink); }

/* ---------- Dialogs ---------- */
.adm-scrim { background: var(--scrim); }
.adm-dialog {
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    border: 1px solid var(--brand-100);
    border-top: 3px solid var(--brand-600);
    border-radius: var(--radius-tile);
    background: var(--surface);
    color: var(--ink-900);
    box-shadow: var(--shadow-pop);
}
.adm-dialog__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 12px 12px 24px;
    border-bottom: 1px solid var(--line);
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    padding: 12px 20px;
    border: 1px solid var(--line);
    border-left-width: 4px;
    border-radius: var(--radius-ctl);
    background: var(--surface);
    color: var(--ink-900);
    box-shadow: var(--shadow-pop);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 200ms ease-out, transform 200ms ease-out;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

/* ---------- Payroll tab ---------- */
.pr-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--info);
    border-radius: var(--radius-ctl);
    background: var(--surface);
    color: var(--ink-900);
    font-size: 14px;
    line-height: 1.45;
}
.pr-banner:empty { display: none; }
.pr-banner > i { margin-top: 3px; }
.pr-banner--final { border-left-color: var(--success); }
.pr-banner--final > i { color: var(--success); }
.pr-banner--draft { border-left-color: var(--warning); }
.pr-banner--draft > i { color: var(--warning); }
.pr-alert--warning { color: var(--warning); }
.pr-alert--warning::before { content: '\f071'; }

.pr-statement td { white-space: nowrap; }
.pr-statement th:first-child,
.pr-statement td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    text-align: left;
    box-shadow: inset -1px 0 0 var(--line);
}
.pr-statement .adm-thead th:first-child { z-index: 2; background: var(--surface-2); }
.pr-statement tbody tr:hover td:first-child { background: var(--brand-50); }
.pr-statement td[title] { cursor: help; }
.pr-statement tbody tr + tr td { border-top: 1px solid var(--line); }
.pr-row--strong td { font-weight: 700; background: var(--surface-2); }
.pr-statement .pr-row--strong td:first-child { background: var(--surface-2); }
.pr-row--sub td { font-size: 12px; color: var(--ink-600); }
.pr-section td {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-600);
    background: var(--surface-2);
}
.pr-statement .pr-section td:first-child { background: var(--surface-2); box-shadow: none; }
.pr-section--company td,
.pr-statement .pr-section--company td:first-child { color: var(--info); }
.pr-row--company td,
.pr-statement .pr-row--company td:first-child { background: color-mix(in srgb, var(--info) 6%, var(--surface)); color: var(--ink-600); }

.pr-form {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    align-items: end;
}
.pr-form label { display: block; margin-bottom: 4px; }
.pr-form input:not([type="checkbox"]),
.pr-form select,
.pr-form textarea { width: 100%; }
.pr-form__wide { grid-column: span 2; }
.pr-form__full { grid-column: 1 / -1; margin: 0; }
.pr-form__submit { display: flex; justify-content: flex-end; gap: 8px; }
.pr-form__submit--start { justify-content: flex-start; }
.pr-form--inline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pr-num { width: 6.5rem; }
.pr-money { width: 9.5rem; }
.pr-note { min-width: 10rem; width: 100%; }
.pr-history { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.pr-link { color: var(--brand-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.pr-json {
    padding: 8px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-ctl);
    background: var(--surface);
    color: var(--ink-900);
    font: 400 12px/1.5 var(--font-mono);
    resize: vertical;
}
.pr-json:focus { outline: none; box-shadow: var(--focus-ring); }
.pr-code { font: 400 12px/1.5 var(--font-mono); word-break: break-word; }
.pr-apply { padding: 12px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius-ctl); }

/* Phiếu lương (modal + in) */
.pr-payslip__body { padding: 16px 24px 24px; }
.pr-payslip__info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 16px; font-size: 13px; }
.pr-payslip__info dt { color: var(--ink-600); }
.pr-payslip__info dd { margin: 0; font-weight: 600; }
.pr-payslip__table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.pr-payslip__table td { padding: 6px 0; border-top: 1px solid var(--line); }
.pr-payslip__table td:last-child { text-align: right; white-space: nowrap; padding-left: 12px; }
.pr-payslip__section th {
    padding: 14px 0 6px;
    text-align: left;
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-600);
}
.pr-payslip__section--company th { color: var(--info); }
.pr-payslip__strong td { font-weight: 700; }
.pr-payslip__detail td { border-top: 0; padding: 0 0 6px; font-size: 12px; color: var(--ink-600); text-align: left !important; white-space: normal !important; }
.pr-payslip__detail ul { margin: 0; padding-left: 16px; list-style: disc; }
.pr-payslip__net td {
    padding: 12px;
    border: 0;
    background: var(--brand-50);
    color: var(--brand-ink);
    font-size: 18px;
    font-weight: 700;
}
.pr-payslip__net td:first-child { border-radius: var(--radius-ctl) 0 0 var(--radius-ctl); }
.pr-payslip__net td:last-child { border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0; padding-right: 12px; }
@media print {
    body.pr-printing > *:not(#payslipModal) { display: none !important; }
    body.pr-printing #payslipModal { position: static; display: block !important; background: none; }
    body.pr-printing .pr-payslip { max-width: none; max-height: none; overflow: visible; margin: 0; border: 0; box-shadow: none; }
    body.pr-printing .pr-no-print { display: none !important; }
}
.pr-config > summary { cursor: pointer; list-style: none; justify-content: flex-start; }
.pr-config > summary::-webkit-details-marker { display: none; }
.pr-config > summary::after {
    content: '\f078';
    margin-left: auto;
    font: 900 12px 'Font Awesome 6 Free';
    color: var(--ink-600);
    transition: transform 150ms ease-out;
}
.pr-config[open] > summary::after { transform: rotate(180deg); }
.pr-config:not([open]) > summary { border-bottom: 0; }
.pr-config > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
    .adm-split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
    .adm-header { position: static; }
    .adm-header__inner,
    .adm-header__bar { padding-inline: 16px; }
    .adm-header__logo .gv-logo { width: 88px; }
    .adm-header__title { font-size: 16px; }
    .adm-header__brand .gv-chip { display: none; }
    .adm-header__actions,
    .adm-header__actions > div { width: 100%; }
    .adm-header__actions .gv-select,
    .adm-header__actions .gv-btn { flex: 1; }
    .adm-tabs { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-tab:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .pr-form__wide { grid-column: 1 / -1; }
    #payrollContent .gv-kpi__value { font-size: 19px; }
    .pr-payslip { margin-inline: 8px; }
    .pr-payslip .adm-dialog__head { flex-wrap: wrap; padding-left: 16px; }
    .pr-payslip .adm-dialog__head > div { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto auto; }
    .pr-payslip .adm-dialog__head .gv-btn--secondary { padding-inline: 8px; min-width: 0; }
    .pr-payslip__body { padding: 12px 16px 16px; }
    .pr-payslip__info { grid-template-columns: 1fr; gap: 0; }
    .pr-payslip__info dd { margin-bottom: 6px; }
    .admin-tab { min-height: 44px; justify-content: center; }
    .adm-kpis,
    #profitSummaryCards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .adm-header__logo { min-height: 44px; align-items: center; }
    /* KPI per-category rows: progress bar + % move to their own line */
    #kpiCatInputs > div { flex-wrap: wrap; }
    #kpiCatInputs > div > .kpi-cat-input { flex: 1; width: auto; max-width: none; }
    #kpiCatInputs > div > .flex-1 { flex-basis: calc(100% - 4.25rem); }
    div:has(> #kpiCatInputs) > div:first-child { display: none; }
    .adm-main { padding-top: 16px; }
    .adm-icon-btn { width: 44px; height: 44px; }
    .adm-main input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not(.kpi-cat-pct-input),
    .adm-main select:not(.gv-select),
    .adm-dialog input:not([type="hidden"]),
    .adm-dialog select,
    .kpi-cat-pct-input { min-height: 44px; font-size: 16px; }
    .toast { left: 16px; right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .admin-tab,
    .adm-table tbody tr,
    .toast,
    .pr-config > summary::after { transition: none; }
}
