/* =========================================================
   KhataBook shell — layout, sidebar (full + mini rail), header
   and the light / dark themes.
   Loaded after kb-theme.css: it owns the tokens below and
   restyles the shared components through them.
   ========================================================= */

/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="light"] {
    color-scheme: light;

    --kb-shell: #0a0a0a;
    --kb-panel: #ffffff;
    --kb-surface: #ffffff;
    --kb-card: #fafafa;
    --kb-head: #f3f3f3;
    --kb-field: #ffffff;
    --kb-canvas: #fafafa;

    --kb-ink: #111111;
    --kb-ink-soft: #262626;
    --kb-muted: #737373;
    --kb-line: #ececec;
    --kb-line-strong: #dcdcdc;

    --kb-primary: #111111;
    --kb-primary-hover: #000000;
    --kb-primary-rgb: 17, 17, 17;
    --kb-primary-soft: rgba(17, 17, 17, 0.07);
    --kb-accent: #111111;
    --kb-accent-hover: #000000;
    --kb-accent-rgb: 17, 17, 17;
    --kb-accent-soft: rgba(17, 17, 17, 0.08);
    --kb-link: #111111;
    --kb-on-primary: #ffffff;

    --kb-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    --kb-shadow-sm: none;

    --kb-stripe: #f0f0f0;
    --kb-hover: #e6e6e6;

    --kb-sidebar-w: 240px;
    --kb-rail-w: 76px;
    --kb-auth-bg: #f4f4f4;

    --bs-primary: #111111;
    --bs-primary-rgb: 17, 17, 17;
    --bs-link-color: #111111;
    --bs-link-hover-color: #000000;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --kb-shell: #000000;
    --kb-panel: #070707;
    --kb-surface: #101010;
    --kb-card: #0d0d0d;
    --kb-head: #151515;
    --kb-field: #040404;
    --kb-canvas: #0d0d0d;

    --kb-ink: #f5f5f5;
    --kb-ink-soft: #e5e5e5;
    --kb-muted: #8c8c8c;
    --kb-line: #1c1c1c;
    --kb-line-strong: #2a2a2a;

    --kb-primary: #f5f5f5;
    --kb-primary-hover: #ffffff;
    --kb-primary-rgb: 245, 245, 245;
    --kb-primary-soft: rgba(255, 255, 255, 0.1);
    --kb-accent: #f5f5f5;
    --kb-accent-hover: #ffffff;
    --kb-accent-rgb: 245, 245, 245;
    --kb-accent-soft: rgba(255, 255, 255, 0.12);
    --kb-link: #ffffff;
    --kb-on-primary: #111111;

    --kb-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --kb-stripe: #171717;
    --kb-hover: #222222;
    --kb-auth-bg: #000000;

    --bs-primary: #f5f5f5;
    --bs-primary-rgb: 245, 245, 245;
    --bs-link-color: #ffffff;
    --bs-link-hover-color: #ffffff;
}

/* ---------- Base ---------- */
html {
    background: var(--kb-shell);
}

body.kb-body,
.kb-auth-body {
    font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
    --kb-font: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
    --kb-body: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
}

body.kb-body {
    background: var(--kb-shell);
    color: var(--kb-ink);
}

/* ---------- Shell: dark frame + one big rounded panel ---------- */
.kb-app {
    background: var(--kb-shell);
}

.kb-main {
    background: var(--kb-panel);
    margin: 16px 16px 16px var(--kb-sidebar-w);
    min-height: calc(100vh - 32px);
    border-radius: 32px;
    transition: margin-left .25s ease;
}

.kb-content {
    padding: 28px 40px 12px;
}

.kb-footer {
    background: transparent;
    border: 0;
    justify-content: center;
    padding: 14px 24px 22px;
    color: var(--kb-muted);
}

.kb-footer span:last-child {
    display: none;
}

/* ---------- Header (inside the panel) ---------- */
.kb-header {
    position: static;
    min-height: 84px;
    padding: 20px 40px;
    background: transparent;
    border-bottom: 1px solid var(--kb-line);
    backdrop-filter: none;
}

.kb-greeting h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--kb-ink-soft);
    line-height: 1.25;
}

.kb-greeting h1 em {
    font-style: italic;
    font-weight: 600;
}

.kb-greeting p {
    margin: 2px 0 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--kb-muted);
}

.kb-icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: var(--kb-head);
    color: var(--kb-ink-soft);
}

.kb-icon-btn:hover {
    background: var(--kb-primary-soft);
    color: var(--kb-link);
}

.kb-menu-btn {
    background: transparent;
}

.kb-theme-toggle .kb-icon-sun {
    display: none;
}

:root[data-theme="dark"] .kb-theme-toggle .kb-icon-moon {
    display: none;
}

:root[data-theme="dark"] .kb-theme-toggle .kb-icon-sun {
    display: block;
}

.kb-header-right {
    gap: 8px;
}

/* ---------- Sidebar (open) ---------- */
.kb-sidebar {
    width: var(--kb-sidebar-w);
    background: var(--kb-shell);
    color: #fff;
    border: 0;
    transition: width .25s ease;
}

.kb-sidebar-brand {
    padding: 24px 20px 18px;
    justify-content: space-between;
    border: 0;
}

.kb-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff !important;
    text-decoration: none !important;
}

.kb-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: #fff;
    color: #000;
    font-size: 18px;
    font-weight: 800;
}

.kb-brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.kb-nav {
    flex: 1;
    padding: 4px 12px;
}

.kb-nav-foot {
    flex: 0 0 auto;
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.kb-nav-link {
    position: relative;
    height: 42px;
    margin: 0 0 2px;
    padding: 0 12px;
    gap: 12px;
    border-radius: 10px;
    color: #a3a3a3 !important;
    font-size: 14px;
    font-weight: 500;
}

.kb-nav-link svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.8;
}

.kb-nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff !important;
}

.kb-nav-link .kb-chevron {
    width: 16px;
    height: 16px;
    margin-right: 0;
}

.kb-nav-link.active {
    background: #fff;
    color: #000 !important;
    font-weight: 600;
    box-shadow: none;
}

.kb-nav-user {
    height: 52px;
}

.kb-nav-user img {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}

.kb-nav-user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.kb-nav-user-text strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
}

.kb-nav-user-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    opacity: 0.65;
}

.kb-sidebar .kb-submenu {
    padding: 0 0 6px;
}

.kb-sidebar .kb-submenu a {
    padding: 8px 12px 8px 42px;
    border-radius: 8px;
    color: #8a8a8a !important;
    font-size: 13px;
    font-weight: 500;
}

.kb-sidebar .kb-submenu a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff !important;
}

.kb-sidebar .kb-submenu a.active {
    background: transparent;
    color: #fff !important;
    font-weight: 700;
}

.kb-sidebar-close {
    background: rgba(255, 255, 255, 0.1);
}

/* ---------- Sidebar (collapsed icon rail, desktop) ---------- */
@media (min-width: 992px) {
    html[data-sidebar="mini"] .kb-sidebar {
        width: var(--kb-rail-w);
        overflow: visible;
    }

    html[data-sidebar="mini"] .kb-main {
        margin-left: var(--kb-rail-w);
    }

    html[data-sidebar="mini"] .kb-sidebar-brand {
        justify-content: center;
        padding: 24px 0 18px;
    }

    html[data-sidebar="mini"] .kb-brand-name,
    html[data-sidebar="mini"] .kb-nav-user-text,
    html[data-sidebar="mini"] .kb-nav-link span,
    html[data-sidebar="mini"] .kb-nav-link .kb-chevron {
        display: none;
    }

    html[data-sidebar="mini"] .kb-nav,
    html[data-sidebar="mini"] .kb-nav-foot {
        padding-left: 14px;
        padding-right: 14px;
        overflow: visible;
    }

    html[data-sidebar="mini"] .kb-nav-link {
        width: 48px;
        height: 44px;
        padding: 0;
        justify-content: center;
    }

    html[data-sidebar="mini"] .kb-nav-user {
        height: 44px;
    }

    /* hover tooltip */
    html[data-sidebar="mini"] .kb-nav-link::after {
        content: attr(data-title);
        position: absolute;
        top: 50%;
        left: calc(100% + 14px);
        padding: 6px 12px;
        border-radius: 8px;
        background: #fff;
        color: #000;
        font-size: 12px;
        font-weight: 600;
        white-space: nowrap;
        opacity: 0;
        transform: translateY(-50%);
        pointer-events: none;
        transition: opacity .15s ease;
        z-index: 70;
    }

    html[data-sidebar="mini"] .kb-nav-link:hover::after {
        opacity: 1;
    }

    html[data-sidebar="mini"] .kb-nav-group.flyout > .kb-nav-toggle::after {
        display: none;
    }

    /* submenus open as a small panel beside the rail */
    html[data-sidebar="mini"] .kb-nav-group {
        position: relative;
    }

    html[data-sidebar="mini"] .kb-sidebar .kb-submenu,
    html[data-sidebar="mini"] .kb-nav-group.open .kb-submenu {
        display: none;
    }

    html[data-sidebar="mini"] .kb-nav-group.flyout .kb-submenu {
        display: block;
        position: absolute;
        top: 0;
        left: calc(100% + 14px);
        min-width: 170px;
        padding: 6px;
        border: 1px solid #2a2a2a;
        border-radius: 12px;
        background: #141414;
        box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
        z-index: 70;
    }

    html[data-sidebar="mini"] .kb-sidebar .kb-nav-group.flyout .kb-submenu a {
        padding: 9px 12px;
    }
}

/* ---------- Small screens: drawer + full-bleed panel ---------- */
@media (max-width: 991.98px) {
    .kb-main {
        margin: 0;
        min-height: 100vh;
        border-radius: 0;
    }

    .kb-header {
        position: sticky;
        top: 0;
        z-index: 30;
        min-height: 60px;
        padding: 10px 16px;
        background: var(--kb-panel);
    }

    .kb-greeting h1 {
        font-size: 16px;
    }

    .kb-content {
        padding: 18px 16px 8px;
    }

}

/* ---------- Components on the panel ---------- */
.card {
    background: var(--kb-card);
    border-color: var(--kb-line) !important;
    box-shadow: none !important;
    color: var(--kb-ink);
}

.card-header,
.modal-header {
    background: transparent !important;
    color: var(--kb-ink);
}

.card-header {
    border-bottom-color: var(--kb-line) !important;
}

.table {
    background: transparent;
    color: var(--kb-ink);
}

.table thead th {
    background: var(--kb-head) !important;
    color: var(--kb-muted) !important;
    border-bottom-color: var(--kb-line) !important;
}

.table td {
    border-color: var(--kb-line) !important;
    color: var(--kb-ink);
}

.table-hover tbody tr:hover {
    background: var(--kb-head) !important;
}

.table-bordered {
    border-color: var(--kb-line) !important;
}

.kb-statement-table thead th:first-child,
.kb-statement-table th:first-child,
.kb-statement-table td:first-child {
    background: var(--kb-card) !important;
    color: var(--kb-ink);
}

.kb-statement-table thead th:first-child {
    background: var(--kb-head) !important;
    color: var(--kb-muted) !important;
}

.btn.btn-secondary,
.btn.btn-outline-secondary,
.btn.btn-default,
.btn.btn-light {
    background: var(--kb-surface) !important;
    border-color: var(--kb-line-strong) !important;
    color: var(--kb-ink) !important;
}

.btn.btn-secondary:hover,
.btn.btn-outline-secondary:hover {
    background: var(--kb-head) !important;
}

.btn.btn-info,
.btn.btn-outline-primary {
    color: var(--kb-link) !important;
}

.form-control,
.form-select,
.input-group-text {
    background-color: var(--kb-field);
    border-color: var(--kb-line-strong);
    color: var(--kb-ink);
}

.form-control::placeholder {
    color: var(--kb-muted);
}

.form-control:disabled,
.form-control[readonly] {
    background-color: var(--kb-head);
}

.input-group-text {
    color: var(--kb-muted);
}

a,
.kb-content a:not(.btn):not(.dropdown-item):not(.page-link) {
    color: var(--kb-link);
}

.text-muted,
.kb-content .text-muted,
.page-header .text-muted {
    color: var(--kb-muted) !important;
}

.page-header h3,
.kb-content > .kb-container > h3,
.card-title,
h1, h2, h3, h4, h5, h6 {
    color: var(--kb-ink-soft);
}

.kb-kpi-value {
    color: var(--kb-ink);
}

hr {
    border-color: var(--kb-line);
}

/* dropdowns, modals, popovers */
.dropdown-menu,
.modal-content,
.popover {
    background: var(--kb-surface);
    color: var(--kb-ink);
    border: 1px solid var(--kb-line);
}

.dropdown-item {
    color: var(--kb-ink);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--kb-head);
    color: var(--kb-ink);
}

.dropdown-divider {
    border-color: var(--kb-line);
}

.modal-header,
.modal-footer {
    border-color: var(--kb-line);
}

:root[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* DataTables / pagination */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper label {
    color: var(--kb-muted);
}

.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper .dataTables_paginate span,
.dataTables_wrapper .dataTables_paginate > .paginate_button.previous,
.dataTables_wrapper .dataTables_paginate > .paginate_button.next {
    background: var(--kb-head) !important;
    border-color: var(--kb-line) !important;
    color: var(--kb-ink) !important;
}

.page-link {
    background: var(--kb-surface);
    border-color: var(--kb-line);
    color: var(--kb-ink);
}

/* select2 */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple,
.select2-dropdown {
    background: var(--kb-field);
    border-color: var(--kb-line-strong);
    color: var(--kb-ink);
}

.select2-container--default .select2-selection--single .select2-selection__rendered,
.select2-container--default .select2-results__option {
    color: var(--kb-ink);
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--kb-field);
    border-color: var(--kb-line-strong);
    color: var(--kb-ink);
}

.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background: var(--kb-primary);
    color: #fff;
}

/* ledger / statement / analytics surfaces */
.kb-member-card,
.kb-st-card,
.kb-st-card-desc,
.kb-st-share,
.kb-st-delete {
    background: var(--kb-surface) !important;
    color: var(--kb-ink);
    border-color: var(--kb-line) !important;
}

.statement-header {
    background: var(--kb-head) !important;
    color: var(--kb-ink) !important;
}

:root[data-theme="dark"] .kb-ledger-bal.is-due,
:root[data-theme="dark"] .kb-ledger-bal.is-bad {
    background: rgba(255, 122, 130, 0.14) !important;
    color: #ff9aa0 !important;
}

:root[data-theme="dark"] .alert-info,
:root[data-theme="dark"] .alert-danger {
    background: var(--kb-head);
    color: var(--kb-ink);
    border-color: var(--kb-line);
}

:root[data-theme="dark"] .bg-white,
:root[data-theme="dark"] .bg-light {
    background: var(--kb-surface) !important;
}

:root[data-theme="dark"] .text-dark {
    color: var(--kb-ink) !important;
}

/* SweetAlert */
:root[data-theme="dark"] .swal2-popup {
    background: var(--kb-surface);
    color: var(--kb-ink);
}

:root[data-theme="dark"] .swal2-title,
:root[data-theme="dark"] .swal2-html-container {
    color: var(--kb-ink);
}

/* PWA install banner keeps its own dark look */
.kb-pwa-install .btn-outline-secondary {
    background: transparent !important;
}

/* ---------- Auth pages ---------- */
.kb-auth-body {
    background:
        radial-gradient(900px 480px at 50% -10%, rgba(var(--kb-primary-rgb), 0.12), transparent 60%),
        var(--kb-auth-bg);
    color: var(--kb-ink);
}

.kb-auth-theme {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 50;
}

.kb-auth-theme .kb-icon-btn {
    background: var(--kb-surface);
    border: 1px solid var(--kb-line);
}

.kb-auth-shell .card,
.kb-auth-card {
    background: var(--kb-surface);
    border-color: var(--kb-line) !important;
    color: var(--kb-ink);
}

.kb-auth-title {
    color: var(--kb-ink);
}

.kb-auth-card a,
.kb-auth-shell .card a:not(.btn) {
    color: var(--kb-link);
}

:root[data-theme="dark"] .kb-auth-logo {
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.4));
}

.form-check-label {
    color: var(--kb-ink);
}

/* ---------- Sidebar: keep labels on one line ---------- */
.kb-nav-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =========================================================
   Shared page pieces
   ========================================================= */

.kb-empty {
    padding: 36px 16px;
    border: 1px dashed var(--kb-line-strong);
    border-radius: 14px;
    text-align: center;
    color: var(--kb-muted);
}

.kb-empty svg {
    width: 28px;
    height: 28px;
    margin-bottom: 8px;
}

/* monochrome avatars */
.kb-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--kb-primary);
    color: var(--kb-on-primary);
    font-size: 15px;
    font-weight: 700;
}

.kb-avatar-sm {
    width: 30px;
    height: 30px;
    font-size: 12px;
}

.kb-av-1,
.kb-av-2,
.kb-av-3,
.kb-av-4 {
    background: var(--kb-primary);
}

/* minimal table */
.kb-table-wrap {
    overflow-x: auto;
}

.kb-table {
    width: 100%;
    border-collapse: collapse;
}

.kb-table thead th {
    padding: 0 12px 12px 0;
    border-bottom: 1px solid var(--kb-line);
    font-size: 12px;
    font-weight: 500;
    color: var(--kb-muted);
    white-space: nowrap;
}

.kb-table tbody td {
    padding: 14px 12px 14px 0;
    border-bottom: 1px solid var(--kb-line);
    font-size: 13px;
    vertical-align: middle;
    color: var(--kb-ink);
}

.kb-table th:last-child,
.kb-table td:last-child {
    padding-right: 0;
}

.kb-table tbody tr {
    cursor: pointer;
}

.kb-table tbody tr:hover td {
    background: var(--kb-head);
}

.kb-table tbody tr:last-child td {
    border-bottom: 0;
}

.kb-table .kb-table-empty td {
    padding: 28px 0;
    text-align: center;
    color: var(--kb-muted);
    cursor: default;
}

.kb-person {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

@media (max-width: 575.98px) {
    /* tables become stacked rows */
    .kb-table thead {
        display: none;
    }

    .kb-table tbody tr {
        display: block;
        padding: 12px 0;
        border-bottom: 1px solid var(--kb-line);
    }

    .kb-table tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 5px 0;
        border: 0;
        text-align: right !important;
    }

    .kb-table tbody td::before {
        content: attr(data-label);
        font-size: 11.5px;
        font-weight: 500;
        color: var(--kb-muted);
    }
}

/* =========================================================
   Dashboard (minimal)
   ========================================================= */

.dash {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dash-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.dash-stats > div {
    padding: 20px 24px;
    border: 1px solid var(--kb-line);
    border-radius: 16px;
    background: var(--kb-card);
}

.dash-stats span {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--kb-muted);
}

.dash-stats strong {
    display: block;
    margin: 6px 0 2px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--kb-ink);
}

.dash-stats small {
    font-size: 12px;
    color: var(--kb-muted);
}

.dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 20px;
}

.dash-card {
    padding: 20px 24px;
    border: 1px solid var(--kb-line);
    border-radius: 16px;
    background: var(--kb-card);
}

.dash-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.dash-card-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--kb-ink);
}

.dash-card-head a,
.dash-legend {
    font-size: 12px;
    color: var(--kb-muted) !important;
}

.dash-card-head a:hover {
    color: var(--kb-ink) !important;
}

.dash-legend {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dash-key {
    display: inline-block;
    width: 18px;
    margin-left: 8px;
    border-top: 2px solid var(--kb-ink);
}

.dash-key.is-dashed {
    border-top-style: dashed;
    border-top-color: var(--kb-muted);
}

.dash-chart-box {
    position: relative;
    height: 240px;
}

/* accounts list */
.dash-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--kb-line);
    color: var(--kb-ink) !important;
}

.dash-list a:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.dash-list a:first-child {
    padding-top: 0;
}

.dash-list a span {
    min-width: 0;
}

.dash-list strong,
.dash-list small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-list strong {
    font-size: 14px;
    font-weight: 600;
}

.dash-list small {
    font-size: 12px;
    color: var(--kb-muted);
}

.dash-list b {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
}

.dash-list a:hover strong {
    text-decoration: underline;
}

.dash-empty {
    margin: 0;
    font-size: 13px;
    color: var(--kb-muted);
}

/* status: a small dot and a word, no colour */
.dash-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--kb-muted);
}

.dash-status::before {
    content: "";
    width: 8px;
    height: 8px;
    border: 1.5px solid var(--kb-muted);
    border-radius: 50%;
}

.dash-status.is-done {
    color: var(--kb-ink);
}

.dash-status.is-done::before {
    border-color: var(--kb-ink);
    background: var(--kb-ink);
}

@media (max-width: 1199.98px) {
    .dash-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 767.98px) {
    .dash-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dash-stats {
        gap: 12px;
    }

    .dash-stats > div {
        padding: 16px 18px;
    }

    .dash-stats strong {
        font-size: 24px;
    }

    .dash-card {
        padding: 16px;
    }
}

/* --- page head + tools --- */
.kb-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.kb-page-head h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--kb-ink-soft);
}

.kb-page-head p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--kb-muted);
}

.kb-page-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.kb-page-tools .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 42px;
    padding: 0 18px;
}

.kb-page-tools .btn svg {
    width: 16px;
    height: 16px;
}

.kb-search {
    position: relative;
    margin: 0;
}

.kb-search svg {
    position: absolute;
    top: 50%;
    left: 14px;
    width: 16px;
    height: 16px;
    transform: translateY(-50%);
    color: var(--kb-muted);
    pointer-events: none;
}

.kb-search input {
    width: 240px;
    max-width: 100%;
    height: 42px;
    padding: 0 14px 0 38px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 12px;
    background: var(--kb-field);
    color: var(--kb-ink);
    font-size: 13px;
}

.kb-search input:focus {
    outline: none;
    border-color: var(--kb-primary);
    box-shadow: 0 0 0 3px rgba(var(--kb-primary-rgb), 0.15);
}

/* --- account cards --- */
.kb-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.kb-acc-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    border: 1px solid var(--kb-line);
    border-radius: 18px;
    background: var(--kb-card);
    transition: border-color .15s ease, transform .15s ease;
}

.kb-acc-card:hover {
    border-color: var(--kb-primary);
    transform: translateY(-2px);
}

.kb-acc-card header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.kb-acc-title {
    flex: 1;
    min-width: 0;
}

.kb-acc-title h3 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 600;
    color: var(--kb-ink);
}

.kb-acc-title small {
    font-size: 12px;
    color: var(--kb-muted);
}

.kb-acc-actions {
    display: flex;
    gap: 4px;
}

.kb-acc-actions form {
    margin: 0;
}

.kb-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--kb-muted) !important;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.kb-icon-link svg {
    width: 16px;
    height: 16px;
}

.kb-icon-link:hover {
    background: var(--kb-head);
    color: var(--kb-link) !important;
}

.kb-icon-link.is-danger:hover {
    background: rgba(255, 51, 63, 0.12);
    color: #e0364a !important;
}

.kb-members {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;
}

.kb-avatars {
    display: inline-flex;
}

.kb-avatars .kb-avatar {
    margin-left: -8px;
    border: 2px solid var(--kb-card);
}

.kb-avatars .kb-avatar:first-child {
    margin-left: 0;
}

.kb-av-more {
    background: var(--kb-head);
    color: var(--kb-ink-soft);
}

.kb-members-names {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--kb-muted);
}

.kb-acc-open {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--kb-primary-soft);
    font-size: 13px;
    font-weight: 600;
    color: var(--kb-link) !important;
    text-decoration: none !important;
}

.kb-acc-open svg {
    width: 16px;
    height: 16px;
}

.kb-acc-open:hover {
    background: var(--kb-primary);
    color: #fff !important;
}

/* ---------- Black & white: content on the primary colour ---------- */
.btn.btn-primary,
.btn.btn-success,
.btn.btn-primary:hover,
.btn.btn-success:hover {
    color: var(--kb-on-primary) !important;
}

.dataTables_wrapper .dataTables_paginate .page-item.active .page-link,
.pagination .page-item.active .page-link,
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,
.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    color: var(--kb-on-primary) !important;
}

.kb-acc-open:hover {
    color: var(--kb-on-primary) !important;
}

/* =========================================================
   Analytics (minimal)
   ========================================================= */

.kb-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.kb-select {
    height: 40px;
    padding: 0 34px 0 14px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 10px;
    background-color: var(--kb-field);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    color: var(--kb-ink);
    font-size: 13px;
    font-weight: 500;
    appearance: none;
    -webkit-appearance: none;
}

.kb-select:focus {
    outline: none;
    border-color: var(--kb-ink);
}

.kb-link-btn {
    display: inline-flex;
    align-items: center;
    height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--kb-muted) !important;
}

.kb-link-btn:hover {
    color: var(--kb-ink) !important;
}

button.kb-link-btn {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.dash > .kb-page-head {
    margin-bottom: 0;
}

.dash-grid.is-top {
    align-items: start;
}

.dash-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* account share: a name, a figure and a thin bar */
.dash-bars {
    margin: 0;
    padding: 0;
    list-style: none;
}

.dash-bars li {
    padding: 12px 0;
    border-bottom: 1px solid var(--kb-line);
}

.dash-bars li:first-child {
    padding-top: 0;
}

.dash-bars li:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.dash-bar-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.dash-bar-top a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--kb-ink) !important;
}

.dash-bar-top span {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--kb-muted);
}

.dash-bar-track {
    height: 4px;
    margin-top: 8px;
    border-radius: 4px;
    background: var(--kb-line);
}

.dash-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--kb-ink);
}

/* numbered rankings */
.dash-rank {
    margin: 0;
    padding: 0;
    list-style: none;
}

.dash-rank li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--kb-line);
}

.dash-rank li:first-child {
    padding-top: 0;
}

.dash-rank li:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.dash-rank i {
    width: 22px;
    flex-shrink: 0;
    font-size: 12px;
    font-style: normal;
    font-weight: 600;
    color: var(--kb-muted);
}

.dash-rank span {
    flex: 1;
    min-width: 0;
}

.dash-rank strong,
.dash-rank small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-rank strong {
    font-size: 13.5px;
    font-weight: 600;
}

.dash-rank small {
    font-size: 11.5px;
    color: var(--kb-muted);
}

.dash-rank b {
    font-size: 14px;
    font-weight: 700;
}

.dash-rank .dash-empty {
    display: block;
}

/* read-only tables: no hover, no pointer */
.kb-table.is-static tbody tr {
    cursor: default;
}

.kb-table.is-static tbody tr:hover td {
    background: transparent;
}

.kb-table td a {
    font-weight: 500;
    color: var(--kb-ink) !important;
}

.kb-table td a:hover {
    text-decoration: underline;
}

/* =========================================================
   Forms, lists, details and auth (minimal)
   ========================================================= */

.kb-form-card {
    max-width: 720px;
}

.kb-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
}

.kb-field {
    margin-bottom: 18px;
}

.kb-field > label,
.kb-field-top label {
    display: block;
    margin-bottom: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--kb-ink-soft);
}

.kb-field > label i,
.kb-field-top label i {
    margin-left: 3px;
    font-style: normal;
    color: var(--kb-muted);
}

.kb-input {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 10px;
    background: var(--kb-field);
    color: var(--kb-ink);
    font-size: 14px;
}

.kb-input[type="file"] {
    height: auto;
    padding: 10px 14px;
}

.kb-input:focus {
    outline: none;
    border-color: var(--kb-ink);
    box-shadow: 0 0 0 3px rgba(var(--kb-primary-rgb), 0.12);
}

.kb-input.is-invalid {
    border-color: #d33;
}

.kb-help {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--kb-muted);
}

.kb-error {
    margin: 6px 0 0;
    font-size: 12px;
    color: #d33;
}

:root[data-theme="dark"] .kb-error,
:root[data-theme="dark"] .kb-input.is-invalid {
    color: #ff7a7a;
    border-color: #ff7a7a;
}

.kb-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

.kb-form-actions .btn {
    height: 42px;
    padding: 0 22px;
}

/* checkbox list (replaces the multi-select) */
.kb-field-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.kb-field-top label {
    margin: 0;
}

.kb-field-tools button {
    margin-left: 12px;
    padding: 0;
    border: 0;
    background: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--kb-muted);
    cursor: pointer;
}

.kb-field-tools button:hover {
    color: var(--kb-ink);
}

.kb-checks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 8px;
    max-height: 320px;
    padding: 12px;
    overflow-y: auto;
    border: 1px solid var(--kb-line-strong);
    border-radius: 12px;
    background: var(--kb-field);
}

.kb-check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--kb-ink);
    cursor: pointer;
}

.kb-check:hover {
    background: var(--kb-head);
}

.kb-check input,
.kb-check-inline input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--kb-ink);
}

.kb-check-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 13px;
    color: var(--kb-ink-soft);
}

/* tags */
.kb-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.kb-tag {
    display: inline-block;
    padding: 3px 10px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: var(--kb-ink-soft);
}

/* list rows: icon actions on the right */
.kb-row-actions {
    text-align: right;
    white-space: nowrap;
}

.kb-row-actions .kb-icon-link,
.kb-inline {
    display: inline-flex;
    vertical-align: middle;
}

.kb-inline {
    margin: 0;
}

/* detail list */
.kb-dl {
    margin: 0;
}

.kb-dl > div {
    display: flex;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--kb-line);
}

.kb-dl > div:last-child {
    border-bottom: 0;
}

.kb-dl dt {
    width: 140px;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--kb-muted);
}

.kb-dl dd {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--kb-ink);
}

/* profile */
.kb-profile-grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 20px;
    align-items: start;
}

.kb-profile-me {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--kb-line);
}

.kb-profile-me img {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}

.kb-profile-me strong,
.kb-profile-me small {
    display: block;
}

.kb-profile-me small {
    color: var(--kb-muted);
}

.kb-danger {
    color: #d33 !important;
}

:root[data-theme="dark"] .kb-danger {
    color: #ff7a7a !important;
}

.dash-card .kb-help {
    margin: 0;
}

/* auth */
.kb-auth-shell {
    justify-content: center;
}

.kb-auth-box {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    padding: 36px;
    border: 1px solid var(--kb-line);
    border-radius: 20px;
    background: var(--kb-surface);
    box-shadow: var(--kb-shadow);
}

.kb-auth-brand {
    margin-bottom: 28px;
    text-align: center;
}

.kb-auth-brand .kb-brand-mark {
    margin-bottom: 18px;
    background: var(--kb-primary);
    color: var(--kb-on-primary);
}

.kb-auth-brand h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--kb-ink);
}

.kb-auth-brand p {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--kb-muted);
}

.kb-auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 4px 0 22px;
    font-size: 13px;
}

.kb-auth-row a,
.kb-auth-foot a {
    font-weight: 600;
    color: var(--kb-ink) !important;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.kb-auth-foot {
    margin: 22px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--kb-muted);
}

.kb-auth-note {
    margin: 0 0 18px;
    padding: 10px 14px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 10px;
    font-size: 13px;
    color: var(--kb-ink-soft);
}

.kb-block {
    display: block;
    width: 100%;
    height: 46px;
}

/* show/hide password button */
.kb-password-wrap {
    position: relative;
}

.kb-password-wrap .kb-input {
    padding-right: 44px;
}

.kb-password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    width: 34px;
    height: 34px;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    background: none;
    color: var(--kb-muted);
    cursor: pointer;
}

.kb-password-toggle:hover {
    color: var(--kb-ink);
}

@media (max-width: 767.98px) {
    .kb-form-grid,
    .kb-profile-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .kb-auth-box {
        padding: 28px 22px;
    }

    .kb-dl > div {
        flex-direction: column;
        gap: 4px;
    }
}

/* =========================================================
   Statement ledger (minimal)
   ========================================================= */

/* filter bar */
.kb-ledger-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.kb-ledger-search {
    margin-left: auto;
}

.kb-seg {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 10px;
    background: var(--kb-field);
}

.kb-seg button {
    height: 32px;
    padding: 0 14px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--kb-muted);
    cursor: pointer;
}

.kb-seg button em {
    margin-left: 4px;
    font-style: normal;
    opacity: 0.7;
}

.kb-seg button:hover {
    color: var(--kb-ink);
}

.kb-seg button.is-on {
    background: var(--kb-primary);
    color: var(--kb-on-primary);
}

/* ledger table */
.kb-ledger td,
.kb-ledger th {
    white-space: nowrap;
}

.kb-ledger .kb-desc {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--kb-muted);
}

.kb-toggle {
    height: 28px;
    padding: 0 12px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 999px;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    color: var(--kb-muted);
    cursor: pointer;
}

.kb-toggle:hover {
    border-color: var(--kb-ink);
    color: var(--kb-ink);
}

.kb-toggle.is-on {
    border-color: var(--kb-primary);
    background: var(--kb-primary);
    color: var(--kb-on-primary);
}

/* add-statement modal */
.kb-modal-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--kb-ink);
}

.modal-body .kb-form-grid {
    column-gap: 14px;
}

.kb-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.kb-split .member-item {
    padding: 10px 12px;
    border: 1px solid var(--kb-line);
    border-radius: 10px;
}

.kb-switch {
    display: flex;
    align-items: center;
    gap: 10px;
}

.kb-switch input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--kb-ink);
}

.kb-switch label {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--kb-ink);
}

.kb-extra {
    margin-top: 8px;
}

.kb-extra .kb-input {
    height: 36px;
    font-size: 13px;
}

/* inputs: selects and text areas */
.kb-input.kb-select {
    width: 100%;
    height: 44px;
}

textarea.kb-input {
    height: auto;
    padding: 12px 14px;
}

.kb-input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 6px 12px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 8px;
    background: var(--kb-head);
    color: var(--kb-ink);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.kb-password-wrap .kb-password-toggle,
.kb-password-wrap .kb-password-toggle i {
    color: var(--kb-muted) !important;
}

@media (max-width: 767.98px) {
    .kb-ledger-search {
        margin-left: 0;
        width: 100%;
    }

    .kb-ledger-search input {
        width: 100%;
    }

    .kb-split {
        grid-template-columns: minmax(0, 1fr);
    }

    .kb-table tbody td:empty {
        display: none;
    }
}

/* =========================================================
   Row actions: icons on desktop, labelled buttons on phones
   ========================================================= */

.kb-icon-link span {
    display: none;
}

@media (max-width: 575.98px) {
    .kb-table tbody td.kb-row-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
        margin-top: 8px;
        padding: 12px 0 0;
        border-top: 1px solid var(--kb-line);
        text-align: right !important;
    }

    .kb-table tbody td.kb-row-actions::before {
        display: none;
    }

    .kb-row-actions .kb-icon-link {
        width: auto;
        height: 36px;
        gap: 6px;
        padding: 0 14px;
        border: 1px solid var(--kb-line-strong);
        border-radius: 10px;
        color: var(--kb-ink) !important;
        font-size: 12.5px;
        font-weight: 600;
    }

    .kb-row-actions .kb-icon-link span {
        display: inline;
    }

    .kb-row-actions .kb-icon-link.is-danger {
        color: #d33 !important;
    }

    :root[data-theme="dark"] .kb-row-actions .kb-icon-link.is-danger {
        color: #ff7a7a !important;
    }

    /* each stacked row reads as one block */
    .kb-table.is-static tbody tr {
        padding: 16px 0;
    }
}

@media (max-width: 575.98px) {
    /* the first cell is the row's title: no label, left aligned */
    .kb-table tbody td:first-child {
        justify-content: flex-start;
        padding-bottom: 8px;
        font-size: 15px;
        text-align: left !important;
    }

    .kb-table tbody td:first-child::before {
        display: none;
    }
}

/* small numeric tables (members, balances) stay as real tables on phones */
@media (max-width: 575.98px) {
    .kb-table.is-flat thead {
        display: table-header-group;
    }

    .kb-table.is-flat tbody tr {
        display: table-row;
        padding: 0;
        border: 0;
    }

    .kb-table.is-flat tbody td,
    .kb-table.is-flat tbody td:first-child {
        display: table-cell;
        padding: 12px 8px 12px 0;
        border-bottom: 1px solid var(--kb-line);
        font-size: 13px;
        text-align: right !important;
    }

    .kb-table.is-flat tbody td:first-child {
        text-align: left !important;
        font-weight: 600;
    }

    .kb-table.is-flat tbody td::before {
        display: none;
    }

    .kb-table.is-flat th,
    .kb-table.is-flat td {
        white-space: normal;
    }

    .kb-table.is-flat th:first-child,
    .kb-table.is-flat td:first-child {
        padding-left: 0;
    }

    .kb-table.is-flat th:last-child,
    .kb-table.is-flat td:last-child {
        padding-right: 0;
    }
}

/* =========================================================
   Table rows: alternating light / dark so rows are easy to tell apart
   ========================================================= */

.kb-table thead th {
    padding: 0 14px 12px;
}

.kb-table tbody td {
    padding: 14px;
    border-bottom: 0;
}

.kb-table th:last-child,
.kb-table td:last-child {
    padding-right: 14px;
}

.kb-table tbody tr:nth-child(even) td {
    background: var(--kb-stripe);
}

.kb-table tbody tr:nth-child(even) td:first-child {
    border-radius: 10px 0 0 10px;
}

.kb-table tbody tr:nth-child(even) td:last-child {
    border-radius: 0 10px 10px 0;
}

.kb-table tbody tr:hover td,
.kb-table.is-static tbody tr:hover td {
    background: var(--kb-hover);
}

.kb-table .kb-table-empty td,
.kb-table .kb-table-empty:hover td {
    background: transparent;
}

@media (max-width: 575.98px) {
    /* stacked rows: shade the whole block, not the single lines */
    .kb-table:not(.is-flat) tbody tr {
        border-bottom: 0;
        border-radius: 12px;
    }

    .kb-table:not(.is-flat) tbody tr:nth-child(even) {
        background: var(--kb-stripe);
    }

    .kb-table:not(.is-flat) tbody tr:nth-child(even) td,
    .kb-table:not(.is-flat) tbody tr:hover td {
        background: transparent;
    }

    .kb-table:not(.is-flat) tbody td {
        padding: 5px 14px;
    }

    .kb-table tbody td.kb-row-actions {
        margin: 8px 14px 0;
        padding: 12px 0 0;
    }

    .kb-table.is-flat tbody td,
    .kb-table.is-flat tbody td:first-child {
        padding: 12px 10px;
        border-bottom: 0;
    }

    .kb-table.is-flat th:first-child,
    .kb-table.is-flat td:first-child {
        padding-left: 12px;
    }

    .kb-table.is-flat th:last-child,
    .kb-table.is-flat td:last-child {
        padding-right: 12px;
    }
}

/* =========================================================
   Statement cards (phones): compact, four short lines
   ========================================================= */

.kb-st-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kb-st {
    padding: 12px 14px;
    border: 1px solid var(--kb-line);
    border-radius: 14px;
    background: var(--kb-card);
}

.kb-st:nth-child(even) {
    background: var(--kb-stripe);
}

.kb-st header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.kb-st header strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 600;
    color: var(--kb-ink);
}

.kb-st header b {
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--kb-ink);
}

/* details on their own line, as a small card */
.kb-st-detail {
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid var(--kb-line);
    border-radius: 10px;
    background: var(--kb-surface);
}

.kb-st-detail span {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--kb-muted);
}

.kb-st-detail p {
    margin: 2px 0 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--kb-ink);
    overflow-wrap: anywhere;
}

/* one small card per member with their amount */
.kb-st-members {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.kb-st-members > div {
    padding: 7px 12px;
    border: 1px solid var(--kb-line);
    border-radius: 10px;
    background: var(--kb-surface);
}

.kb-st-members small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--kb-muted);
}

.kb-st-members b {
    font-size: 15px;
    font-weight: 700;
    color: var(--kb-ink);
}

.kb-st footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--kb-line);
}

.kb-st-bal {
    font-size: 12px;
    color: var(--kb-muted);
}

.kb-st-bal.is-off {
    font-weight: 700;
    color: var(--kb-ink);
}

.kb-st-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* =========================================================
   Pagination (server side)
   ========================================================= */

.kb-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 18px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--kb-line);
    font-size: 12.5px;
    color: var(--kb-muted);
}

.kb-pager-info {
    margin-right: auto;
}

.kb-pager-size {
    margin: 0;
}

.kb-pager-size label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.kb-pager-size select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 8px;
    background: var(--kb-field);
    color: var(--kb-ink);
    font-size: 12.5px;
    font-weight: 600;
}

.kb-pager-nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.kb-pager-nav a,
.kb-pager-nav .is-on,
.kb-pager-nav .is-off {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--kb-line-strong);
    border-radius: 8px;
    background: var(--kb-field);
    color: var(--kb-ink) !important;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none !important;
}

.kb-pager-nav a:hover {
    border-color: var(--kb-ink);
}

.kb-pager-nav .is-on {
    border-color: var(--kb-primary);
    background: var(--kb-primary);
    color: var(--kb-on-primary) !important;
}

.kb-pager-nav .is-off {
    opacity: 0.4;
}

.kb-pager-gap {
    padding: 0 4px;
}

.kb-cards + .kb-pager {
    margin-top: 20px;
}

@media (max-width: 575.98px) {
    .kb-pager {
        justify-content: space-between;
    }

    .kb-pager-info {
        flex-basis: 100%;
    }
}

/* =========================================================
   Buttons: the text always follows the theme, even when focused or pressed
   ========================================================= */

.btn.btn-primary:focus,
.btn.btn-primary:focus-visible,
.btn.btn-primary:active,
.btn.btn-primary.active,
.btn.btn-success:focus,
.btn.btn-success:focus-visible,
.btn.btn-success:active,
.btn.btn-success.active,
.btn.btn-primary:disabled,
.btn.btn-primary.disabled {
    background: var(--kb-primary-hover) !important;
    border-color: var(--kb-primary-hover) !important;
    color: var(--kb-on-primary) !important;
}

.btn.btn-secondary:focus,
.btn.btn-secondary:active,
.btn.btn-secondary.active {
    background: var(--kb-head) !important;
    border-color: var(--kb-line-strong) !important;
    color: var(--kb-ink) !important;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* =========================================================
   Loader
   ========================================================= */

.kb-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -3px;
    animation: kb-spin .7s linear infinite;
}

.kb-spinner.is-sm {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    vertical-align: -2px;
}

@keyframes kb-spin {
    to { transform: rotate(360deg); }
}

.kb-loader {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-radius: inherit;
    background: color-mix(in srgb, var(--kb-surface) 78%, transparent);
    font-size: 13px;
    font-weight: 600;
    color: var(--kb-ink);
}

.kb-loader[hidden] {
    display: none;
}

.kb-loader .kb-spinner {
    width: 22px;
    height: 22px;
    vertical-align: middle;
}

/* =========================================================
   Checkboxes: the tick always contrasts with the box
   (light theme: light tick on a dark box, dark theme: dark tick on a light box)
   ========================================================= */

.form-check-input[type="checkbox"] {
    background-color: var(--kb-field);
    border: 1px solid var(--kb-line-strong);
}

.form-check-input[type="checkbox"]:checked {
    border-color: var(--kb-primary);
    background-color: var(--kb-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] .form-check-input[type="checkbox"]:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23111' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3E%3C/svg%3E");
}

.form-check-input[type="checkbox"]:focus {
    border-color: var(--kb-ink);
    box-shadow: 0 0 0 3px rgba(var(--kb-primary-rgb), 0.15);
}

/* the checkbox lists elsewhere (users, roles, accounts) use the native box: tint it the same way */
.kb-check input,
.kb-check-inline input,
.kb-switch input {
    accent-color: var(--kb-primary);
    color-scheme: light;
}

:root[data-theme="dark"] .kb-check input,
:root[data-theme="dark"] .kb-check-inline input,
:root[data-theme="dark"] .kb-switch input {
    color-scheme: dark;
}

/* =========================================================
   Balance badges: not buttons, just a status
   red = owes, green = is owed, plain = settled
   ========================================================= */

.kb-badge {
    display: inline-block;
    min-width: 46px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.45;
    text-align: center;
    white-space: nowrap;
    cursor: default;
    user-select: none;
    pointer-events: none;
}

.kb-badge.is-neg {
    background: rgba(225, 29, 72, 0.12);
    color: #c81e45;
}

.kb-badge.is-pos {
    background: rgba(16, 185, 129, 0.15);
    color: #0b8a5d;
}

.kb-badge.is-zero {
    min-width: 0;
    padding-right: 0;
    padding-left: 0;
    background: transparent;
    color: var(--kb-muted);
    font-weight: 600;
}

:root[data-theme="dark"] .kb-badge.is-neg {
    background: rgba(251, 113, 133, 0.16);
    color: #ff8da0;
}

:root[data-theme="dark"] .kb-badge.is-pos {
    background: rgba(52, 211, 153, 0.16);
    color: #4ade9a;
}

/* the stat cards' label rule must not stretch a badge */
.dash-stats .kb-badge {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 700;
}
