/* Koei Table Pro — visual layer. Pairs with table-pro.js. Pure CSS, no build step. */
:root {
    --tp-brand: var(--color-brand-500, #ff4650);
    --tp-brand-600: var(--color-brand-600, #e93641);
    --tp-brand-50: var(--color-brand-50, #fff0f1);
    --tp-ink: var(--color-ink-950, #06152d);
    --tp-line: #eaecf0;
    --tp-line-soft: #f0f1f3;
    --tp-muted: #667085;
    --tp-bg-head: #f8f9fb;
    --tp-radius: 16px;
    --tp-shadow: 0 4px 20px rgba(16, 24, 40, .04);
    --tp-pop-shadow: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
}

/* ---------- Toolbar ---------- */
.tp-toolbar {
    position: relative;
    padding: 12px 14px 0;
    background: #fff;
    border: 1px solid var(--tp-line);
    border-bottom: 0;
    border-radius: var(--tp-radius) var(--tp-radius) 0 0;
    box-shadow: var(--tp-shadow);
}
.tp-toolbar + .tp-scroll { border-top-left-radius: 0; border-top-right-radius: 0; border-top: 1px solid var(--tp-line); box-shadow: var(--tp-shadow); }
.app-card > .tp-toolbar { border: 0; border-bottom: 1px solid var(--tp-line-soft); border-radius: var(--tp-radius) var(--tp-radius) 0 0; box-shadow: none; }
.app-card > .tp-toolbar + .tp-scroll { border-top: 0; box-shadow: none; border-radius: 0 0 var(--tp-radius) var(--tp-radius); }
/* cards that clip overflow (Tailwind overflow-hidden) would cut popovers off */
.app-card:has(> .tp-toolbar) { overflow: visible !important; }
.tp-row1 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 12px; }
.tp-spacer { flex: 1 1 auto; }
.tp-count { font-size: 12px; color: var(--tp-muted); white-space: nowrap; }

.tp-search {
    display: flex; align-items: center; gap: 8px;
    height: 38px; min-width: 220px; flex: 0 1 300px; padding: 0 10px;
    color: #98a2b3; background: #fff;
    border: 1px solid #d0d5dd; border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
.tp-search:focus-within { border-color: var(--tp-brand); box-shadow: 0 0 0 4px rgba(255, 70, 80, .12); color: var(--tp-brand); }
.tp-search input {
    flex: 1; min-width: 0; height: 100%; border: 0 !important; outline: 0 !important;
    background: transparent; box-shadow: none !important; padding: 0 !important;
    font-size: 14px; color: var(--tp-ink);
}
.tp-search kbd {
    font: 600 11px/1 ui-monospace, monospace; color: #98a2b3;
    border: 1px solid #e4e7ec; border-radius: 5px; padding: 3px 6px; background: #f9fafb;
}
.tp-search:focus-within kbd { display: none; }

.tp-btn {
    display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
    font-size: 13px; font-weight: 600; color: #344054; white-space: nowrap;
    background: #fff; border: 1px solid #d0d5dd; border-radius: 10px; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.tp-btn:hover { background: #f9fafb; border-color: #b8c0cc; }
.tp-btn:focus-visible, .tp-kebab:focus-visible, .tp-tab:focus-visible, .tp-opt:focus-visible { outline: 2px solid var(--tp-brand); outline-offset: 2px; }
.tp-btn.is-on { color: var(--tp-brand-600); border-color: #ffb9bf; background: var(--tp-brand-50); }

/* ---------- Popovers ---------- */
.tp-pop { position: relative; }
.tp-panel {
    position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
    display: none; min-width: 230px; max-height: min(70vh, 480px); overflow: auto; padding: 8px;
    background: #fff; border: 1px solid var(--tp-line); border-radius: 12px; box-shadow: var(--tp-pop-shadow);
}
.tp-panel.is-open { display: block; animation: tp-pop .12s ease-out; }
@keyframes tp-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.tp-panel hr { border: 0; border-top: 1px solid var(--tp-line-soft); margin: 8px 0; }
.tp-panel-title { padding: 6px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #98a2b3; }
.tp-panel-note { padding: 6px 10px 8px; font-size: 12px; color: var(--tp-muted); line-height: 1.6; }
.tp-opt {
    display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 14px;
    padding: 8px 10px; font-size: 14px; color: #344054; text-align: left;
    background: none; border: 0; border-radius: 8px; cursor: pointer;
}
.tp-opt:hover { background: #f4f6fa; }
.tp-opt.is-selected { background: var(--tp-brand-50); color: var(--tp-ink); font-weight: 600; }
.tp-opt-label { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.tp-opt-extra { font-size: 11px; font-weight: 500; color: #98a2b3; }
.tp-radio { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #c4cad4; background: #fff; }
.tp-opt.is-selected .tp-radio { border-color: var(--tp-brand); box-shadow: inset 0 0 0 3.5px #fff; background: var(--tp-brand); }
.tp-check-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 14px; color: #344054; border-radius: 8px; cursor: pointer; }
.tp-check-opt:hover { background: #f4f6fa; }
.tp-check-opt input, .tp-check input { width: 16px; height: 16px; accent-color: var(--tp-brand); cursor: pointer; }
.tp-link { margin: 4px 10px 2px; padding: 4px 0; font-size: 12px; font-weight: 700; color: var(--tp-brand-600); background: none; border: 0; cursor: pointer; }

/* ---------- Tabs (All / Paid / Unpaid …) ---------- */
.tp-tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 -14px; padding: 0 14px; border-top: 1px solid var(--tp-line-soft); scrollbar-width: none; }
.tp-tabs::-webkit-scrollbar { display: none; }
.tp-tab {
    display: inline-flex; align-items: center; gap: 8px; padding: 11px 12px; margin-bottom: -1px;
    font-size: 13px; font-weight: 600; color: var(--tp-muted); white-space: nowrap;
    background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer;
    transition: color .15s, border-color .15s;
}
.tp-tab:hover { color: var(--tp-ink); }
.tp-tab i { font-style: normal; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: #f2f4f7; color: var(--tp-muted); }
.tp-tab.is-active { color: var(--tp-brand-600); border-bottom-color: var(--tp-brand); }
.tp-tab.is-active i { background: var(--tp-brand-50); color: var(--tp-brand-600); }

/* ---------- Active chips (Group / Sort / Search) ---------- */
.tp-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0; border-top: 1px solid var(--tp-line-soft); }
.tp-chips.is-empty { display: none; }
.tp-toolbar:not(:has(.tp-tabs)) .tp-chips { border-top-color: transparent; }
.tp-chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 11px; font-size: 12px; color: #344054; background: #f4f6fa; border: 1px solid #e4e7ec; border-radius: 8px; }
.tp-chip em { font-style: normal; color: #98a2b3; }
.tp-chip span { font-weight: 700; }
.tp-chip button { display: grid; place-items: center; width: 20px; height: 20px; color: #98a2b3; background: none; border: 0; border-radius: 5px; cursor: pointer; }
.tp-chip button svg { width: 12px; height: 12px; }
.tp-chip button:hover { background: #e4e7ec; color: var(--tp-ink); }

/* ---------- Bulk selection bar ---------- */
.tp-bulk { display: none; align-items: center; gap: 8px; margin: 0 -14px; padding: 10px 14px; font-size: 13px; color: var(--tp-ink); background: var(--tp-brand-50); border-top: 1px solid #ffdadd; }
.tp-toolbar.has-selection .tp-bulk { display: flex; }
.tp-toolbar.has-selection .tp-row1, .tp-toolbar.has-selection .tp-tabs, .tp-toolbar.has-selection .tp-chips { display: none; }
.tp-toolbar.has-selection { padding-top: 0; }

/* ---------- Table body ---------- */
.tp-scroll { max-height: min(72vh, 780px); overflow: auto !important; }
.tp-scroll .tp-table { border-collapse: separate; border-spacing: 0; }
.tp-scroll .tp-table thead th {
    position: sticky; top: 0; z-index: 3;
    background: var(--tp-bg-head); color: #667085;
    font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
    border-bottom: 1px solid var(--tp-line);
}
.tp-scroll .tp-table tbody td { border-top: 1px solid var(--tp-line-soft); transition: background .12s; }
.tp-scroll .tp-table tbody tr:first-child td { border-top: 0; }
.tp-scroll .tp-table tbody tr:not(.tp-group):not(.tp-empty):hover td { background: #fafbfd; }
.tp-scroll .tp-table tbody tr.is-selected td { background: #fff5f6 !important; }
.tp-scroll .tp-table tbody tr.is-selected td:nth-child(2) { box-shadow: inset 3px 0 0 var(--tp-brand); }
.tp-compact .tp-table tbody td { padding-top: 8px !important; padding-bottom: 8px !important; }
.tp-compact .tp-table tbody td small { display: none; }
.tp-hide { display: none !important; }
.tp-check { width: 44px; padding-left: 16px !important; padding-right: 0 !important; }
.tp-sortable { cursor: pointer; user-select: none; }
.tp-sortable:hover { color: var(--tp-ink) !important; }
.tp-arrow { margin-left: 6px; font-size: 11px; color: #c4cad4; }
.tp-sortable.is-sorted { color: var(--tp-brand-600) !important; }
.tp-sortable.is-sorted .tp-arrow { color: var(--tp-brand); }
.tp-actions { width: 56px; text-align: right; }

/* group rows */
.tp-group td { padding: 0 !important; background: #f4f6fa !important; border-top: 1px solid var(--tp-line) !important; }
.tp-group-btn { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 18px; font-size: 13px; color: var(--tp-ink); text-align: left; background: none; border: 0; cursor: pointer; }
.tp-group-btn svg { transition: transform .15s; color: #667085; }
.tp-group.is-collapsed .tp-group-btn svg { transform: rotate(-90deg); }
.tp-group-count { padding: 1px 8px; font-size: 11px; font-weight: 700; color: var(--tp-muted); background: #fff; border: 1px solid #e4e7ec; border-radius: 999px; }

/* empty result */
.tp-empty td { padding: 0 !important; }
.tp-empty-box { display: grid; justify-items: center; gap: 6px; padding: 44px 16px; color: var(--tp-muted); font-size: 13px; }
.tp-empty-box b { color: var(--tp-ink); font-size: 15px; }
.tp-empty-box .tp-btn { margin-top: 10px; }

/* ---------- Row action menu (kebab) ---------- */
.tp-menu-wrap { display: inline-block; position: relative; }
.tp-kebab { display: grid; place-items: center; width: 34px; height: 34px; color: #98a2b3; background: none; border: 0; border-radius: 8px; cursor: pointer; transition: background .15s, color .15s; }
.tp-kebab:hover, .tp-kebab[aria-expanded="true"] { background: #f2f4f7; color: var(--tp-ink); }
.tp-menu {
    position: fixed; z-index: 60; display: none; min-width: 190px; padding: 6px; text-align: left;
    background: #fff; border: 1px solid var(--tp-line); border-radius: 12px; box-shadow: var(--tp-pop-shadow);
}
.tp-menu.is-open { display: block; animation: tp-pop .12s ease-out; }
.tp-menu form { display: block; margin: 0; }
.tp-menu a, .tp-menu button.tp-item {
    display: flex !important; width: 100%; min-height: 0 !important; align-items: center; gap: 8px;
    margin: 0 !important; padding: 9px 12px !important; font-size: 14px !important; font-weight: 500 !important; line-height: 1.3;
    color: #344054 !important; text-align: left; text-decoration: none;
    background: none !important; border: 0 !important; border-radius: 8px !important; box-shadow: none !important; cursor: pointer;
    transform: none !important;
}
.tp-menu a:hover, .tp-menu button.tp-item:hover { background: #f4f6fa !important; color: var(--tp-ink) !important; }
.tp-menu .is-danger { color: #d92d20 !important; }
.tp-menu .is-danger:hover { background: #fef3f2 !important; color: #b42318 !important; }
.tp-menu .is-success { color: #067647 !important; }
.tp-menu .is-success:hover { background: #ecfdf3 !important; color: #05603a !important; }

/* ---------- Visual refresh of shared page parts ---------- */
.app-main .status-pill, .app-main .status-badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
    font-size: 11px; font-weight: 700; line-height: 1.5; white-space: nowrap; border-radius: 999px;
}
.app-main .status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.app-main .status-pill.approved { background: #ecfdf3; color: #067647; }
.app-main .status-pill.pending { background: #fffaeb; color: #b54708; }
.app-main .status-pill.rejected { background: #fef3f2; color: #b42318; }

/* server-side filter links → underline tabs */
.app-main .filter-pills { gap: 2px; margin-bottom: 18px !important; border-bottom: 1px solid var(--tp-line); }
.app-main .filter-pill {
    padding: 10px 14px; margin-bottom: -1px; font-size: 13px; color: var(--tp-muted);
    background: none !important; border-bottom: 2px solid transparent; border-radius: 0 !important; box-shadow: none !important;
}
.app-main .filter-pill:hover { color: var(--tp-ink); }
.app-main .filter-pill.is-active { color: var(--tp-brand-600); border-bottom-color: var(--tp-brand); background: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
    .tp-search { flex: 1 1 100%; }
    .tp-count { order: 9; flex: 1 1 100%; }
    .tp-spacer { display: none; }
    .tp-btn span { display: none; }
    .tp-btn { padding: 0 11px; }
    .tp-btn.tp-btn-icon span { display: none; }
    .tp-panel { left: auto; right: 0; }
    .tp-pop:first-of-type .tp-panel { left: 0; right: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .tp-panel.is-open, .tp-menu.is-open { animation: none; }
    .tp-group-btn svg { transition: none; }
}
