/* =========================================================================
   Admin Pro — v2 (Enterprise / Formal / Clean)
   Inspired by Stripe / Vercel / Linear / Notion admin panels
   ========================================================================= */

:root {
    /* Brand — pulled from admin setting via index.php */
    --ap-primary:       var(--mu-primary, #0f172a);
    --ap-accent:        var(--mu-primary, #4f46e5);
    --ap-primary-soft:  color-mix(in srgb, var(--mu-primary, #4f46e5) 12%, transparent);
    --ap-accent-soft:   color-mix(in srgb, var(--mu-primary, #4f46e5) 10%, transparent);

    /* Semantic — fixed, independent of theme mode */
    --ap-success:       #10b981;
    --ap-success-bg:    #ecfdf5;
    --ap-warning:       #f59e0b;
    --ap-warning-bg:    #fffbeb;
    --ap-danger:        #ef4444;
    --ap-danger-bg:     #fef2f2;
    --ap-info:          #0ea5e9;
    --ap-info-bg:       #f0f9ff;

    /* Radii */
    --ap-r-sm: 6px;
    --ap-r-md: 10px;
    --ap-r-lg: 14px;

    /* Layout */
    --ap-sidebar-w: 260px;
    --ap-topbar-h:  64px;
}

/* Light mode — admin */
:root[data-theme="light"] {
    --ap-bg:            #f7f8fa;
    --ap-surface:       #ffffff;
    --ap-surface-alt:   #fafbfc;
    --ap-surface-soft:  #f1f3f5;

    --ap-text:          #0f172a;
    --ap-text-2:        #3a4150;
    --ap-text-muted:    #6b7280;
    --ap-text-subtle:   #98a1b2;

    --ap-border:        #e6e8ec;
    --ap-border-strong: #d6d9e0;

    --ap-shadow-sm:     0 1px 2px rgba(15,23,42,.04), 0 1px 1px rgba(15,23,42,.03);
    --ap-shadow-md:     0 4px 12px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
    --ap-shadow-lg:     0 20px 40px rgba(15,23,42,.08), 0 8px 16px rgba(15,23,42,.04);
}

/* Dark mode — admin */
:root[data-theme="dark"] {
    --ap-bg:            #0b0f17;
    --ap-surface:       #111827;
    --ap-surface-alt:   #0f1624;
    --ap-surface-soft:  #1a2234;

    --ap-text:          #f1f5f9;
    --ap-text-2:        #cbd5e1;
    --ap-text-muted:    #a1a9b6;
    --ap-text-subtle:   #6b7280;

    --ap-border:        #1f2a3a;
    --ap-border-strong: #2a3748;

    --ap-shadow-sm:     0 1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
    --ap-shadow-md:     0 4px 12px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.3);
    --ap-shadow-lg:     0 20px 40px rgba(0,0,0,.55), 0 8px 16px rgba(0,0,0,.35);
}

/* Only apply global resets when admin layout is on page */
body.ap-admin-body {
    background: var(--ap-bg);
    color: var(--ap-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 'Noto Sans Thai', 'Kanit', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Neutralise legacy bootstrap container/row that wraps the admin include */
body.ap-admin-body .container {
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
}
body.ap-admin-body .container > .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
    --bs-gutter-x: 0;
}
body.ap-admin-body .site-footer,
body.ap-admin-body .mu-topbar,
body.ap-admin-body .mu-bottom-nav,
body.ap-admin-body .mu-drawer,
body.ap-admin-body .mu-drawer-backdrop { display: none !important; }
body.ap-admin-body { padding-bottom: 0 !important; }

/* ====== Layout Shell ==================================================== */

.ap-shell {
    display: grid;
    grid-template-columns: var(--ap-sidebar-w) 1fr;
    min-height: 100vh;
    background: var(--ap-bg);
}

.ap-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--ap-surface);
    border-right: 1px solid var(--ap-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 40;
}

.ap-sidebar-head {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--ap-border);
    flex-shrink: 0;
}
.ap-sidebar-head .ap-logo {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center; justify-content: center;
    background: var(--ap-primary);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}
.ap-sidebar-head .ap-brand {
    display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.ap-sidebar-head .ap-brand b {
    font-size: 14px;
    font-weight: 600;
    color: var(--ap-text);
    letter-spacing: -0.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 170px;
}
.ap-sidebar-head .ap-brand span {
    font-size: 11px;
    color: var(--ap-text-muted);
    font-weight: 500;
}

.ap-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 10px 24px;
    scrollbar-width: thin;
}
.ap-nav::-webkit-scrollbar { width: 6px; }
.ap-nav::-webkit-scrollbar-thumb { background: var(--ap-border); border-radius: 3px; }

.ap-nav-section {
    padding: 18px 12px 8px;
    font-size: 10.5px;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--ap-text-subtle);
    text-transform: uppercase;
}
.ap-nav-section:first-child { padding-top: 6px; }

.ap-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 1px 0;
    border-radius: var(--ap-r-sm);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ap-text-2);
    text-decoration: none;
    position: relative;
    transition: background .12s ease, color .12s ease;
}
.ap-nav-link i {
    font-size: 14px;
    width: 18px;
    text-align: center;
    color: var(--ap-text-muted);
}
.ap-nav-link:hover {
    background: var(--ap-surface-soft);
    color: var(--ap-text);
}
.ap-nav-link:hover i { color: var(--ap-text); }
.ap-nav-link.active {
    background: var(--ap-primary-soft);
    color: var(--ap-accent);
    font-weight: 600;
}
.ap-nav-link.active i { color: var(--ap-accent); }
.ap-nav-link.active::before {
    content: "";
    position: absolute;
    left: -10px; top: 6px; bottom: 6px;
    width: 3px;
    background: var(--ap-accent);
    border-radius: 0 3px 3px 0;
}

.ap-sidebar-foot {
    padding: 12px 16px;
    border-top: 1px solid var(--ap-border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.ap-sidebar-foot .ap-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--ap-primary-soft);
    color: var(--ap-accent);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px;
}
.ap-sidebar-foot .ap-who {
    display: flex; flex-direction: column; gap: 0; min-width: 0; flex: 1;
}
.ap-sidebar-foot .ap-who b {
    font-size: 12.5px; color: var(--ap-text); font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;
}
.ap-sidebar-foot .ap-who span {
    font-size: 11px; color: var(--ap-text-muted);
}
.ap-sidebar-foot a {
    color: var(--ap-text-muted);
    font-size: 14px;
    padding: 6px;
    border-radius: var(--ap-r-sm);
    text-decoration: none;
    transition: background .12s, color .12s;
}
.ap-sidebar-foot a:hover { background: var(--ap-danger-bg); color: var(--ap-danger); }

/* ====== Main area ======================================================= */

.ap-main {
    display: flex; flex-direction: column; min-width: 0;
}

.ap-topbar {
    position: sticky;
    top: 0;
    height: var(--ap-topbar-h);
    padding: 0 28px;
    background: var(--ap-surface);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--ap-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 30;
    gap: 16px;
}
.ap-topbar .ap-crumb {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; color: var(--ap-text-muted);
    min-width: 0;
}
.ap-topbar .ap-crumb a { color: var(--ap-text-muted); text-decoration: none; }
.ap-topbar .ap-crumb a:hover { color: var(--ap-text); }
.ap-topbar .ap-crumb .sep { color: var(--ap-text-subtle); }
.ap-topbar .ap-crumb .now {
    color: var(--ap-text); font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 380px;
}

.ap-topbar .ap-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.ap-topbar .ap-btn-icon,
.ap-topbar .ap-chip {
    height: 36px; padding: 0 14px;
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 500; color: var(--ap-text-2);
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: 8px;
    text-decoration: none;
    transition: background .12s, border-color .12s, color .12s;
}
.ap-topbar .ap-btn-icon:hover,
.ap-topbar .ap-chip:hover {
    background: var(--ap-surface-soft); color: var(--ap-text); border-color: var(--ap-border-strong);
}
.ap-topbar .ap-btn-icon { width: 36px; padding: 0; justify-content: center; }
.ap-topbar .ap-chip i { color: var(--ap-accent); }

/* Mobile trigger for sidebar */
.ap-hamburger { display: none; }

/* Page container */
.ap-page {
    padding: 28px 28px 60px;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

.ap-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}
.ap-page-head h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--ap-text);
    letter-spacing: -0.01em;
    margin: 0 0 2px;
}
.ap-page-head p {
    color: var(--ap-text-muted); font-size: 13.5px; margin: 0;
}

/* ====== Primitives ====================================================== */

.ap-card {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-sm);
}
.ap-card-body { padding: 20px 22px; }
.ap-card-head {
    padding: 14px 22px;
    border-bottom: 1px solid var(--ap-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ap-card-head h3 {
    font-size: 14px; font-weight: 600; color: var(--ap-text); margin: 0;
    letter-spacing: -0.005em;
}
.ap-card-head .ap-sub { font-size: 12.5px; color: var(--ap-text-muted); }

/* KPI cards */
.ap-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.ap-kpi-card {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    padding: 18px 20px;
    display: flex; flex-direction: column; gap: 10px;
    box-shadow: var(--ap-shadow-sm);
    transition: box-shadow .15s, transform .15s, border-color .15s;
}
.ap-kpi-card:hover { box-shadow: var(--ap-shadow-md); border-color: var(--ap-border-strong); }
.ap-kpi-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 12.5px; color: var(--ap-text-muted); font-weight: 500;
}
.ap-kpi-icon {
    width: 30px; height: 30px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px;
    background: var(--ap-surface-soft);
    color: var(--ap-text-2);
}
.ap-kpi-icon.k-blue   { background: #eff6ff; color: #2563eb; }
.ap-kpi-icon.k-green  { background: var(--ap-success-bg); color: var(--ap-success); }
.ap-kpi-icon.k-purple { background: var(--ap-primary-soft); color: var(--ap-accent); }
.ap-kpi-icon.k-orange { background: var(--ap-warning-bg); color: #b45309; }
.ap-kpi-icon.k-rose   { background: #fff1f2; color: #e11d48; }
.ap-kpi-icon.k-teal   { background: #ecfeff; color: #0891b2; }

.ap-kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--ap-text);
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.ap-kpi-meta {
    font-size: 12px;
    color: var(--ap-text-muted);
    display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap;
}
.ap-trend {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 600; font-size: 11.5px;
    line-height: 1.4;
}
.ap-trend.up   { color: var(--ap-success); background: var(--ap-success-bg); }
.ap-trend.down { color: var(--ap-danger);  background: var(--ap-danger-bg);  }
.ap-trend.flat { color: var(--ap-text-muted); background: var(--ap-surface-soft); }
.ap-trend i { font-size: 10px; }

/* Grid helpers */
.ap-grid-2  { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 22px; }
.ap-grid-3  { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin-bottom: 22px; }
.ap-grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 16px; margin-bottom: 22px; }

/* Tables */
.ap-table-wrap { overflow-x: auto; }
.ap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.ap-table thead th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ap-text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 12px 22px;
    background: var(--ap-surface-alt);
    border-bottom: 1px solid var(--ap-border);
    white-space: nowrap;
}
.ap-table tbody td {
    padding: 13px 22px;
    border-bottom: 1px solid var(--ap-border);
    color: var(--ap-text-2);
    vertical-align: middle;
}
.ap-table tbody tr:last-child td { border-bottom: 0; }
.ap-table tbody tr:hover td { background: var(--ap-surface-alt); }
.ap-table td b, .ap-table td strong { color: var(--ap-text); font-weight: 600; }
.ap-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Pills / tags */
.ap-tag {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    font-size: 11.5px; font-weight: 600;
    border-radius: 999px;
    background: var(--ap-surface-soft);
    color: var(--ap-text-2);
    border: 1px solid var(--ap-border);
    white-space: nowrap;
}
.ap-tag.s-green  { background: var(--ap-success-bg); color: var(--ap-success); border-color: transparent; }
.ap-tag.s-blue   { background: #eff6ff; color: #2563eb; border-color: transparent; }
.ap-tag.s-purple { background: var(--ap-primary-soft); color: var(--ap-accent); border-color: transparent; }
.ap-tag.s-orange { background: var(--ap-warning-bg); color: #b45309; border-color: transparent; }
.ap-tag.s-rose   { background: #fff1f2; color: #e11d48; border-color: transparent; }
.ap-tag.s-gray   { background: var(--ap-surface-soft); color: var(--ap-text-muted); }

/* Buttons */
.ap-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 0 14px; height: 36px;
    font-size: 13px; font-weight: 500;
    border-radius: 8px;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    color: var(--ap-text-2);
    text-decoration: none;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.ap-btn:hover { background: var(--ap-surface-soft); color: var(--ap-text); border-color: var(--ap-border-strong); }
.ap-btn.primary {
    background: var(--ap-accent);
    color: #fff;
    border-color: var(--ap-accent);
}
.ap-btn.primary:hover { background: var(--ap-accent); filter: brightness(.93); color: #fff; }
.ap-btn.danger {
    background: var(--ap-surface);
    color: var(--ap-danger);
    border-color: var(--ap-border);
}
.ap-btn.danger:hover { background: var(--ap-danger-bg); color: var(--ap-danger); border-color: #fecaca; }
.ap-btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }

/* Forms */
.ap-field {
    display: flex; flex-direction: column; gap: 6px;
    margin-bottom: 14px;
}
.ap-field > label {
    font-size: 12.5px; font-weight: 600; color: var(--ap-text-2);
}
.ap-field > .hint { font-size: 11.5px; color: var(--ap-text-muted); margin-top: 2px; }
.ap-input,
.ap-select,
.ap-textarea {
    height: 38px;
    padding: 0 12px;
    font-size: 13.5px;
    color: var(--ap-text);
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: 8px;
    width: 100%;
    transition: border-color .12s, box-shadow .12s;
    font-family: inherit;
}
.ap-textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.ap-input:focus,
.ap-select:focus,
.ap-textarea:focus {
    outline: 0;
    border-color: var(--ap-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ap-accent) 22%, transparent);
}

/* Empty state */
.ap-empty {
    padding: 42px 20px;
    text-align: center;
    color: var(--ap-text-muted);
    font-size: 13.5px;
}
.ap-empty i { font-size: 28px; display: block; margin-bottom: 10px; color: var(--ap-text-subtle); }

/* Flash */
.ap-flash {
    padding: 11px 14px;
    border-radius: var(--ap-r-md);
    font-size: 13px;
    font-weight: 500;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 16px;
}
.ap-flash.ok  { background: var(--ap-success-bg); color: #047857; border: 1px solid #a7f3d0; }
.ap-flash.err { background: var(--ap-danger-bg);  color: #b91c1c; border: 1px solid #fecaca; }

/* Chart wrapper */
.ap-chart-wrap { position: relative; height: 280px; padding: 12px 6px 4px; }

/* ====== Mobile ======================================================== */
@media (max-width: 992px) {
    .ap-shell { grid-template-columns: 1fr; }
    .ap-sidebar {
        position: fixed; top: 0; left: 0; width: 280px; height: 100vh;
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: var(--ap-shadow-lg);
    }
    .ap-shell.open .ap-sidebar { transform: translateX(0); }
    .ap-shell.open::after {
        content: ""; position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 35;
    }
    .ap-hamburger {
        display: inline-flex; align-items: center; justify-content: center;
        width: 36px; height: 36px; border: 1px solid var(--ap-border);
        border-radius: 8px; background: var(--ap-surface); color: var(--ap-text-2);
        cursor: pointer;
    }
    .ap-topbar { padding: 0 16px; gap: 10px; }
    .ap-page { padding: 18px 16px 60px; }
    .ap-kpi { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
    .ap-grid-2, .ap-grid-3 { grid-template-columns: 1fr; }
    .ap-grid-12 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .ap-kpi { grid-template-columns: 1fr; }
    .ap-page-head { flex-direction: column; align-items: flex-start; }
}

/* =========================================================================
   V3 additions — modern tables, modern modals, sticky footer, mobile stack
   ========================================================================= */

/* ---------- Modern table ---------- */
.tbl-modern-wrap {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    overflow: hidden;
    box-shadow: var(--ap-shadow-sm);
}
.tbl-modern {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
    color: var(--ap-text-2);
    background: transparent;
}
.tbl-modern thead th {
    position: sticky;
    top: 0;
    background: var(--ap-surface-alt);
    color: var(--ap-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11.5px;
    font-weight: 700;
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ap-border);
    white-space: nowrap;
    z-index: 1;
}
.tbl-modern tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--ap-border);
    vertical-align: middle;
    color: var(--ap-text);
}
.tbl-modern tbody tr:last-child td { border-bottom: 0; }
.tbl-modern tbody tr { transition: background .12s ease; }
.tbl-modern tbody tr:hover td { background: var(--ap-surface-alt); }
.tbl-modern tbody tr:nth-child(2n) td { background: color-mix(in srgb, var(--ap-surface-alt) 45%, transparent); }
.tbl-modern tbody tr:nth-child(2n):hover td { background: var(--ap-surface-alt); }
.tbl-modern .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl-modern .muted { color: var(--ap-text-muted); }
.tbl-modern .actions { text-align: right; white-space: nowrap; }
.tbl-modern .actions .ap-btn { margin-left: 4px; }

/* Responsive: stack cells on mobile via data-label */
@media (max-width: 720px) {
    .tbl-modern-wrap { border: 0; background: transparent; box-shadow: none; border-radius: 0; }
    .tbl-modern thead { display: none; }
    .tbl-modern, .tbl-modern tbody, .tbl-modern tr, .tbl-modern td { display: block; width: 100%; }
    .tbl-modern tbody tr {
        background: var(--ap-surface);
        border: 1px solid var(--ap-border);
        border-radius: var(--ap-r-md);
        padding: 6px 4px;
        margin-bottom: 10px;
        box-shadow: var(--ap-shadow-sm);
    }
    .tbl-modern tbody tr:nth-child(2n) td { background: transparent; }
    .tbl-modern tbody td {
        padding: 9px 14px;
        border-bottom: 1px dashed var(--ap-border);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
    }
    .tbl-modern tbody td:last-child { border-bottom: 0; }
    .tbl-modern tbody td::before {
        content: attr(data-label);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: 700;
        color: var(--ap-text-muted);
        flex-shrink: 0;
        text-align: left;
    }
    .tbl-modern .num, .tbl-modern .actions { text-align: right; }
}

/* Auto-promote legacy bootstrap .table inside admin pages to modern look */
body.ap-admin-body .table,
body.ap-admin-body table.table {
    width: 100%;
    margin: 0;
    color: var(--ap-text);
    background: transparent;
    border-collapse: separate;
    border-spacing: 0;
}
body.ap-admin-body .table thead th,
body.ap-admin-body table.table thead th {
    background: var(--ap-surface-alt);
    color: var(--ap-text-muted);
    font-weight: 700;
    font-size: 11.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--ap-border) !important;
    border-top: 0 !important;
    padding: 12px 16px !important;
}
body.ap-admin-body .table tbody td,
body.ap-admin-body table.table tbody td {
    background: transparent !important;
    color: var(--ap-text) !important;
    border-color: var(--ap-border) !important;
    border-top: 1px solid var(--ap-border) !important;
    padding: 13px 16px !important;
    vertical-align: middle;
}
body.ap-admin-body .table tbody tr:hover td { background: var(--ap-surface-alt) !important; }

/* ---------- Modern modal ---------- */
.apm {
    position: fixed; inset: 0;
    background: rgba(8, 12, 20, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    padding: 18px;
    animation: apm-fade .18s ease;
}
.apm.open { display: flex; }
.apm-box {
    background: var(--ap-surface);
    color: var(--ap-text);
    border-radius: var(--ap-r-lg);
    border: 1px solid var(--ap-border);
    box-shadow: var(--ap-shadow-lg);
    max-width: 560px;
    width: 100%;
    max-height: min(92vh, 820px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: apm-pop .22s cubic-bezier(.2,.8,.2,1);
}
.apm-box.lg { max-width: 780px; }
.apm-box.xl { max-width: 1080px; }
.apm-head {
    padding: 16px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--ap-border);
    background: var(--ap-surface);
}
.apm-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ap-text);
}
.apm-head .apm-sub {
    font-size: 12px;
    color: var(--ap-text-muted);
    margin-top: 2px;
}
.apm-x {
    width: 32px; height: 32px;
    border: 1px solid var(--ap-border);
    background: var(--ap-surface);
    color: var(--ap-text-2);
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .12s, border-color .12s, color .12s;
}
.apm-x:hover { background: var(--ap-surface-alt); color: var(--ap-text); border-color: var(--ap-border-strong); }
.apm-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}
.apm-foot {
    padding: 12px 22px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--ap-border);
    background: var(--ap-surface-alt);
}
@keyframes apm-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes apm-pop  { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Auto-upgrade Bootstrap modals inside admin layouts */
body.ap-admin-body .modal-content {
    background: var(--ap-surface) !important;
    color: var(--ap-text) !important;
    border: 1px solid var(--ap-border) !important;
    border-radius: var(--ap-r-lg) !important;
    box-shadow: var(--ap-shadow-lg) !important;
}
body.ap-admin-body .modal-header,
body.ap-admin-body .modal-footer {
    background: var(--ap-surface) !important;
    border-color: var(--ap-border) !important;
    color: var(--ap-text) !important;
}
body.ap-admin-body .modal-title { color: var(--ap-text) !important; font-weight: 700 !important; }

/* ---------- Admin footer (sticks to bottom of admin page) ---------- */
.ap-main { min-height: 100vh; }
.ap-page-wrap { display: flex; flex-direction: column; min-height: calc(100vh - var(--ap-topbar-h)); }
.ap-page { flex: 1 0 auto; }
.ap-footer {
    flex-shrink: 0;
    padding: 18px 28px;
    background: var(--ap-surface);
    border-top: 1px solid var(--ap-border);
    color: var(--ap-text-muted);
    font-size: 12.5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.ap-footer a { color: var(--ap-text-2); text-decoration: none; }
.ap-footer a:hover { color: var(--ap-accent); }
.ap-footer .ap-footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
@media (max-width: 720px) {
    .ap-footer { padding: 14px 16px; flex-direction: column; align-items: flex-start; }
}

/* Theme smooth transition */
body.ap-admin-body, .ap-sidebar, .ap-topbar, .ap-card, .ap-footer,
.apm-box, .tbl-modern, .tbl-modern-wrap {
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

/* ====== Compat helpers for legacy admin pages ========================= */
/* Old pages use .admin-page-card — keep working but make them look clean */
.ap-admin-body .admin-page-card {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-sm);
    padding: 22px;
    backdrop-filter: none;
    animation: none;
}
.ap-admin-body .admin-page-title {
    color: var(--ap-text);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    background: none;
    -webkit-text-fill-color: currentColor;
}
.ap-admin-body .admin-page-title i {
    color: var(--ap-accent);
    background: none;
    -webkit-text-fill-color: currentColor;
    animation: none;
    font-size: 18px;
}
.ap-admin-body .admin-pill {
    background: var(--ap-surface-soft);
    border: 1px solid var(--ap-border);
    color: var(--ap-text-2);
    font-weight: 500;
    font-size: 12.5px;
    padding: 5px 10px;
}

/* =========================================================================
   v5 — Modern admin design system
   Classes prefixed `v5-` — used by custom_category, faq, history pages,
   and as a building block for redesigned admin pages.
   ========================================================================= */

.v5-page {
    display: flex;
    flex-direction: column;
    gap: 18px;
    color: var(--ap-text);
}

.v5-page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
    padding: 20px 22px;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-sm);
}
.v5-page-title {
    font-size: 1.25rem; font-weight: 700; margin: 0;
    color: var(--ap-text); display: flex; align-items: center; gap: 10px;
}
.v5-page-title i { color: var(--ap-accent); }
.v5-page-sub { color: var(--ap-text-muted); font-size: .9rem; margin: 4px 0 0; }

.v5-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 999px;
    background: var(--ap-primary-soft); color: var(--ap-accent);
    border: 1px solid var(--ap-border); font-weight: 600; font-size: .82rem;
}

/* Alert */
.v5-alert {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-radius: var(--ap-r-md);
    border: 1px solid var(--ap-border);
    background: var(--ap-surface-soft);
    color: var(--ap-text);
    font-weight: 500; font-size: .9rem;
}
.v5-alert-ok   { color: #047857; background: var(--ap-success-bg); border-color: #a7f3d0; }
.v5-alert-err  { color: #b91c1c; background: var(--ap-danger-bg);  border-color: #fecaca; }
.v5-alert-warn { color: #92400e; background: var(--ap-warning-bg, #fef3c7); border-color: #fde68a; }
.v5-alert-info { color: #1e40af; background: #eff6ff; border-color: #bfdbfe; }

/* v5 form multi-column + actions */
.v5-card-body { padding: 20px; }
.v5-form-2col {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 18px;
}
@media (max-width: 640px) { .v5-form-2col { grid-template-columns: 1fr; } }
.v5-form-3col {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 18px;
}
@media (max-width: 960px) { .v5-form-3col { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .v5-form-3col { grid-template-columns: 1fr; } }
.v5-form-actions {
    display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 18px; padding-top: 16px;
    border-top: 1px solid var(--ap-border);
}
@media (max-width: 560px) {
    .v5-form-actions { flex-direction: column; }
    .v5-form-actions .v5-btn { width: 100%; }
}

/* Grid layouts */
.v5-grid { display: grid; gap: 18px; }
.v5-grid-5-7 { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
@media (max-width: 960px) { .v5-grid-5-7 { grid-template-columns: 1fr; } }

.v5-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1200px) { .v5-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .v5-grid-4 { grid-template-columns: 1fr; } }

/* Card */
.v5-card {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-sm);
    overflow: hidden;
}
.v5-card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--ap-border);
    font-weight: 700; color: var(--ap-text);
    display: flex; align-items: center; gap: 8px;
    background: var(--ap-surface-alt);
}
.v5-card-head i { color: var(--ap-accent); }

/* Form */
.v5-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.v5-field { display: flex; flex-direction: column; gap: 6px; }
.v5-field label {
    font-size: .85rem; color: var(--ap-text-2); font-weight: 600;
    display: flex; align-items: center; gap: 4px;
}
.v5-req  { color: var(--ap-danger); }
.v5-hint { color: var(--ap-text-muted); font-weight: 400; font-size: .8rem; }

.v5-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.v5-input, .v5-select, .v5-textarea {
    width: 100%;
    background: var(--ap-surface);
    border: 1.5px solid var(--ap-border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--ap-text);
    font-size: .92rem;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.v5-input:focus, .v5-select:focus, .v5-textarea:focus {
    outline: none;
    border-color: var(--ap-accent);
    box-shadow: 0 0 0 3px var(--ap-primary-soft);
}
.v5-textarea { min-height: 90px; resize: vertical; }

/* Color picker */
.v5-color-wrap {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px;
    background: var(--ap-surface);
    border: 1.5px solid var(--ap-border);
    border-radius: 10px;
}
.v5-color {
    width: 32px; height: 32px; border: none; padding: 0;
    border-radius: 8px; cursor: pointer; background: transparent;
}
.v5-color::-webkit-color-swatch-wrapper { padding: 0; border-radius: 8px; }
.v5-color::-webkit-color-swatch { border: none; border-radius: 8px; }
.v5-color::-moz-color-swatch { border: none; border-radius: 8px; }
.v5-color-hex {
    font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
    color: var(--ap-text-2); font-size: .85rem;
}

/* Switch — modern, clearly spaced */
.v5-switch-row {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 14px;
    background: var(--ap-surface-soft);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-md);
}
.v5-switch {
    position: relative; display: inline-block;
    width: 46px; height: 26px; flex: 0 0 46px;
}
.v5-switch input { opacity: 0; width: 0; height: 0; }
.v5-switch-knob {
    position: absolute; inset: 0; cursor: pointer;
    background: var(--ap-border-strong); border-radius: 999px;
    transition: background-color .2s;
}
.v5-switch-knob::before {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 20px; height: 20px; background: #fff;
    border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.15);
    transition: transform .2s;
}
.v5-switch input:checked + .v5-switch-knob { background: var(--ap-accent); }
.v5-switch input:checked + .v5-switch-knob::before { transform: translateX(20px); }
.v5-switch-title { font-weight: 700; color: var(--ap-text); }
.v5-switch-desc  { color: var(--ap-text-muted); font-size: .82rem; margin-top: 2px; }

/* Buttons */
.v5-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 10px; border: 1.5px solid transparent;
    font-weight: 600; font-size: .92rem; cursor: pointer;
    transition: transform .12s, box-shadow .15s, background-color .15s, border-color .15s;
    font-family: inherit;
    text-decoration: none;
}
.v5-btn.w-100 { width: 100%; }
.v5-btn-primary {
    background: var(--ap-accent); color: #fff; border-color: var(--ap-accent);
}
.v5-btn-primary:hover { filter: brightness(0.95); box-shadow: 0 4px 12px var(--ap-primary-soft); }
.v5-btn-ghost {
    background: var(--ap-surface); color: var(--ap-text-2);
    border-color: var(--ap-border);
}
.v5-btn-ghost:hover { background: var(--ap-surface-soft); border-color: var(--ap-border-strong); }
.v5-btn-danger {
    background: var(--ap-danger-bg); color: var(--ap-danger); border-color: #fecaca;
}
.v5-btn-danger:hover { background: var(--ap-danger); color: #fff; border-color: var(--ap-danger); }

/* Icon-only button */
.v5-btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 8px; padding: 0;
    background: var(--ap-surface-soft);
    border: 1px solid var(--ap-border);
    color: var(--ap-text-2); cursor: pointer; margin-left: 4px;
    transition: all .15s;
}
.v5-btn-icon:hover { background: var(--ap-accent); color: #fff; border-color: var(--ap-accent); }
.v5-btn-icon-danger:hover { background: var(--ap-danger); border-color: var(--ap-danger); color: #fff; }

/* Table */
.v5-table-wrap { overflow-x: auto; }
.v5-table {
    width: 100%; border-collapse: collapse;
    font-size: .92rem;
}
.v5-table thead th {
    text-align: left; padding: 11px 14px;
    font-size: .72rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ap-text-muted);
    border-bottom: 1px solid var(--ap-border);
    background: var(--ap-surface-alt);
    white-space: nowrap;
}
.v5-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--ap-border);
    color: var(--ap-text); vertical-align: middle;
}
.v5-table tbody tr:last-child td { border-bottom: none; }
.v5-table tbody tr:hover { background: var(--ap-surface-soft); }
.v5-table .v5-id { color: var(--ap-text-muted); font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
.v5-table .text-end { text-align: right; }
.v5-table .v5-empty { text-align: center; color: var(--ap-text-muted); padding: 32px !important; }

/* Table cell — category */
.v5-cat-cell { display: flex; align-items: center; gap: 10px; }
.v5-cat-thumb {
    width: 48px; height: 36px; border-radius: 8px; object-fit: cover;
    border: 1px solid var(--ap-border); flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.05rem;
}
.v5-cat-thumb-icon { font-size: 1rem; }
.v5-cat-name { font-weight: 600; color: var(--ap-text); }
.v5-cat-meta { font-size: .78rem; color: var(--ap-text-muted); display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.v5-color-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    border: 1px solid rgba(15,23,42,.1);
}
.v5-table code {
    background: var(--ap-surface-soft); border: 1px solid var(--ap-border);
    padding: 2px 6px; border-radius: 5px; font-size: .78rem; color: var(--ap-text-2);
}

/* Badges */
.v5-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 999px;
    font-weight: 600; font-size: .78rem; border: 1px solid transparent;
    cursor: pointer; background: none;
    font-family: inherit;
}
.v5-badge-ok  { color: #047857; background: var(--ap-success-bg); border-color: #a7f3d0; }
.v5-badge-off { color: var(--ap-text-muted); background: var(--ap-surface-soft); border-color: var(--ap-border); }
.v5-badge-warn { color: #b45309; background: var(--ap-warning-bg); border-color: #fde68a; }
.v5-badge-danger { color: #b91c1c; background: var(--ap-danger-bg); border-color: #fecaca; }

/* Card-based mobile view for tables */
@media (max-width: 640px) {
    .v5-table thead { display: none; }
    .v5-table, .v5-table tbody, .v5-table tr, .v5-table td { display: block; width: 100%; }
    .v5-table tr {
        border: 1px solid var(--ap-border); border-radius: var(--ap-r-md);
        margin-bottom: 10px; padding: 6px 4px; background: var(--ap-surface);
    }
    .v5-table tbody td { border-bottom: 1px dashed var(--ap-border); padding: 8px 12px; }
    .v5-table tbody td:last-child { border-bottom: none; }
    .v5-table tbody td::before {
        content: attr(data-label); display: block;
        font-size: .7rem; font-weight: 700; letter-spacing: .06em;
        text-transform: uppercase; color: var(--ap-text-muted); margin-bottom: 2px;
    }
    .v5-table tbody td.text-end { text-align: left; }
    .v5-table .col-slug, .v5-table .col-sort { display: none; }
}

/* Modal */
.v5-modal {
    position: fixed; inset: 0; z-index: 9999;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.v5-modal.is-open { display: flex; }
.v5-modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
    animation: v5-fade .2s ease;
}
.v5-modal-dialog {
    position: relative;
    width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-lg);
    animation: v5-pop .22s ease;
}
@keyframes v5-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes v5-pop  { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.v5-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; border-bottom: 1px solid var(--ap-border);
}
.v5-modal-head h3 {
    margin: 0; font-size: 1.05rem; font-weight: 700;
    color: var(--ap-text); display: flex; align-items: center; gap: 8px;
}
.v5-modal-head h3 i { color: var(--ap-accent); }
.v5-modal-x {
    background: transparent; border: 0; width: 32px; height: 32px;
    border-radius: 8px; cursor: pointer; color: var(--ap-text-muted);
    font-size: 1.1rem;
}
.v5-modal-x:hover { background: var(--ap-surface-soft); color: var(--ap-text); }
.v5-modal-body { padding: 0; }
.v5-modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--ap-border);
    background: var(--ap-surface-alt);
}

/* KPI cards */
.v5-kpi {
    padding: 18px 20px;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-sm);
    display: flex; flex-direction: column; gap: 6px;
    transition: transform .15s, box-shadow .15s;
}
.v5-kpi:hover { transform: translateY(-2px); box-shadow: var(--ap-shadow-md); }
.v5-kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.v5-kpi-label { font-size: .78rem; color: var(--ap-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.v5-kpi-icon {
    width: 34px; height: 34px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--ap-primary-soft); color: var(--ap-accent); font-size: .92rem;
}
.v5-kpi-value { font-size: 1.5rem; font-weight: 800; color: var(--ap-text); letter-spacing: -0.02em; }
.v5-kpi-sub   { font-size: .8rem; color: var(--ap-text-muted); }

/* v5 — additional table/form helpers */
.v5-page-actions { display: flex; align-items: center; gap: 10px; }
.v5-field-hint   { color: var(--ap-text-muted); font-weight: 400; font-size: .78rem; margin-left: 4px; }
.v5-col-actions  { width: 1%; white-space: nowrap; text-align: right; }
.v5-row-actions  { display: inline-flex; gap: 4px; justify-content: flex-end; }
.v5-table-empty  { text-align: center; color: var(--ap-text-muted); padding: 28px !important; font-style: italic; }
.v5-user-cell    { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.v5-user-cell i  { color: var(--ap-accent); font-size: 1.15rem; }

.v5-btn-icon-edit:hover { background: var(--ap-accent); color: #fff; border-color: var(--ap-accent); }

/* v5 modal alternate class (v5-modal-panel, used by user_edit) */
.v5-modal-panel {
    position: relative;
    width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-lg);
    box-shadow: var(--ap-shadow-lg);
    animation: v5-pop .22s ease;
    display: flex; flex-direction: column;
}
.v5-modal-panel .v5-modal-body {
    padding: 20px; display: flex; flex-direction: column; gap: 14px;
}

/* v5 — toggle rows / switch buttons (button-based) */
.v5-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
@media (max-width: 960px) { .v5-grid-2 { grid-template-columns: 1fr; } }

.v5-toggle-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
@media (max-width: 960px) { .v5-toggle-grid { grid-template-columns: 1fr; } }

.v5-toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; padding: 14px 16px;
    background: var(--ap-surface-soft);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-r-md);
}
.v5-toggle-info { min-width: 0; }
.v5-toggle-label {
    font-weight: 700; color: var(--ap-text); font-size: .92rem;
    display: flex; align-items: center; gap: 8px;
}
.v5-toggle-label i { color: var(--ap-accent); }
.v5-toggle-sub { color: var(--ap-text-muted); font-size: .78rem; margin-top: 3px; }

/* button-based switch (acts like a toggle) */
button.v5-switch {
    position: relative; flex-shrink: 0;
    width: 48px; height: 26px; padding: 0;
    border-radius: 999px; border: 1px solid var(--ap-border);
    background: var(--ap-surface-3, #e6e8ec);
    cursor: pointer; transition: background .18s, border-color .18s;
}
button.v5-switch .v5-switch-dot {
    position: absolute; top: 2px; left: 2px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15,23,42,.3);
    transition: transform .18s;
}
button.v5-switch.is-on { background: var(--ap-accent); border-color: var(--ap-accent); }
button.v5-switch.is-on .v5-switch-dot { transform: translateX(22px); }

/* v5 pill variants */
.v5-pill-ok  { background: var(--ap-success-bg); color: #047857; border-color: #a7f3d0; }
.v5-pill-off { background: var(--ap-surface-soft); color: var(--ap-text-muted); }

/* field help */
.v5-field-help {
    font-size: .78rem; color: var(--ap-text-muted); margin-top: 4px;
    line-height: 1.5;
}
.v5-field-help a { color: var(--ap-accent); text-decoration: underline; }

/* v5 — KPI grid helpers for history pages */
.v5-kpi-grid { display: grid; gap: 14px; margin: 0 0 18px; }
.v5-kpi-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.v5-kpi-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) {
    .v5-kpi-grid-3, .v5-kpi-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
    .v5-kpi-grid-3, .v5-kpi-grid-4 { grid-template-columns: 1fr; }
}
.v5-kpi { flex-direction: row; align-items: center; gap: 14px; }
.v5-kpi-ic {
    width: 44px; height: 44px; flex: 0 0 auto;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--ap-primary-soft); color: var(--ap-accent);
    font-size: 1.05rem;
}
.v5-kpi-ic-ok     { background: var(--ap-success-bg); color: #047857; }
.v5-kpi-ic-warn   { background: var(--ap-warning-bg, #fef3c7); color: #b45309; }
.v5-kpi-ic-danger { background: var(--ap-danger-bg);  color: #b91c1c; }
.v5-kpi-ic-info   { background: #eff6ff;              color: #1e40af; }
.v5-kpi-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* v5 — extra helpers for history/table cells */
.v5-amount-pos { color: #047857; font-weight: 700; }
.v5-meta  { color: var(--ap-text-muted); font-size: .72rem; margin-top: 4px; }
.v5-sms   { color: var(--ap-text); font-size: .82rem; }
.v5-ref   { font-family: ui-monospace, Menlo, monospace; font-size: .78rem; color: var(--ap-text-muted); }
.v5-code  { font-family: ui-monospace, Menlo, monospace; font-size: .75rem; color: var(--ap-text); background: var(--ap-surface-soft); padding: 2px 6px; border-radius: 6px; }

/* v5 — responsive table: card view on mobile */
@media (max-width: 640px) {
    .v5-table,
    .v5-table thead,
    .v5-table tbody,
    .v5-table tr,
    .v5-table th,
    .v5-table td { display: block; width: 100%; }
    .v5-table thead { display: none; }
    .v5-table tbody tr {
        border: 1px solid var(--ap-border);
        border-radius: var(--ap-r-md);
        margin-bottom: 10px;
        background: var(--ap-surface);
        padding: 6px 12px;
    }
    .v5-table tbody tr:hover { background: var(--ap-surface); }
    .v5-table tbody td {
        display: flex; justify-content: space-between; align-items: center; gap: 10px;
        border: none;
        padding: 8px 0;
        border-bottom: 1px dashed var(--ap-border);
    }
    .v5-table tbody td:last-child { border-bottom: none; }
    .v5-table tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--ap-text-muted);
        font-weight: 600;
        font-size: .78rem;
        text-transform: uppercase;
        letter-spacing: .04em;
    }
    .v5-table tbody td > * { text-align: right; }
}

