/*
 * AffTrack admin UI v2 - components for modernized pages (tpl/admin_v2/*)
 * Loaded after admin-v2.css. Modernized pages render inside .at-modern (no legacy grid).
 *
 * Building blocks:
 *   .at-page-head        title, subtitle, breadcrumb, actions
 *   .at-card             surface card (+ -head, -body, -foot, .at-card-flush for edge-to-edge tables)
 *   .at-kpis / .at-kpi   stat tiles
 *   .at-seg              segmented status filter with counts
 *   .at-table            data table inside a card
 *   .at-pill-*           status pills (always text + color, never color alone)
 *   .at-dl               label/value detail grid
 *   .at-list             compact row list (notices, activity)
 *   .at-empty            empty state
 *   .at-savebar          sticky form action bar
 */

/* ------------------------------------------------------------------ */
/* Bootstrap 5 theming to the instance brand                           */
/* ------------------------------------------------------------------ */

.at-v2 .btn-primary {
    --bs-btn-bg: var(--at-brand);
    --bs-btn-border-color: var(--at-brand);
    --bs-btn-color: var(--at-brand-contrast);
    --bs-btn-hover-bg: var(--at-brand);
    --bs-btn-hover-border-color: var(--at-brand);
    --bs-btn-hover-color: var(--at-brand-contrast);
    --bs-btn-active-bg: var(--at-brand);
    --bs-btn-active-border-color: var(--at-brand);
    --bs-btn-active-color: var(--at-brand-contrast);
    --bs-btn-disabled-bg: var(--at-brand);
    --bs-btn-disabled-border-color: var(--at-brand);
    --bs-btn-focus-shadow-rgb: var(--at-brand-rgb);
}

.at-v2 .btn-primary:hover {
    filter: brightness(.92);
}

.at-v2 .btn-outline-primary {
    --bs-btn-color: var(--at-brand);
    --bs-btn-border-color: var(--at-brand);
    --bs-btn-hover-bg: var(--at-brand);
    --bs-btn-hover-border-color: var(--at-brand);
    --bs-btn-hover-color: var(--at-brand-contrast);
    --bs-btn-active-bg: var(--at-brand);
    --bs-btn-active-border-color: var(--at-brand);
    --bs-btn-focus-shadow-rgb: var(--at-brand-rgb);
}

.at-v2 .btn-light {
    --bs-btn-bg: #fff;
    --bs-btn-border-color: var(--at-border-strong);
    --bs-btn-color: #344054;
    --bs-btn-hover-bg: var(--at-surface-2);
    --bs-btn-hover-border-color: var(--at-border-strong);
    --bs-btn-active-bg: #eef0f3;
    --bs-btn-active-border-color: var(--at-border-strong);
}

.at-v2 .btn {
    --bs-btn-font-size: .8125rem;
    --bs-btn-font-weight: 600;
    --bs-btn-border-radius: var(--at-radius-sm);
    --bs-btn-padding-y: .375rem;
    --bs-btn-padding-x: .8rem;
}

.at-v2 .btn-sm {
    --bs-btn-font-size: .75rem;
    --bs-btn-padding-y: .2rem;
    --bs-btn-padding-x: .55rem;
}

.at-v2 .page-link {
    --bs-pagination-active-bg: var(--at-brand);
    --bs-pagination-active-border-color: var(--at-brand);
    --bs-pagination-color: var(--at-brand);
}

.at-v2 .active > .page-link,
.at-v2 .page-link.active {
    background-color: var(--at-brand);
    border-color: var(--at-brand);
    color: var(--at-brand-contrast);
}

.at-v2 .form-check-input:checked {
    background-color: var(--at-brand);
    border-color: var(--at-brand);
}

.at-v2 .nav-link {
    color: #475467;
}

.at-v2 .nav-link:hover {
    color: var(--at-text);
}

/* Legacy style.min.css paints every input grey with an inset shadow; undo it for BS5 controls. */
.at-v2 .form-control,
.at-v2 .form-select {
    background-color: var(--at-surface);
    box-shadow: none;
    border: 1px solid var(--at-border-strong);
    border-radius: var(--at-radius-sm);
    font-size: .8125rem;
    color: var(--at-text);
    min-height: 34px;
}

.at-v2 .form-control-sm,
.at-v2 .form-select-sm {
    min-height: 30px;
    font-size: .75rem;
}

.at-v2 .form-control:focus,
.at-v2 .form-select:focus,
.at-v2 .form-check-input:focus {
    border-color: var(--at-brand);
    box-shadow: 0 0 0 3px rgba(var(--at-brand-rgb), .15);
}

.at-v2 .form-label {
    font-size: .75rem;
    font-weight: 600;
    color: #475467;
    margin-bottom: 4px;
}

.at-v2 .form-text {
    font-size: .75rem;
    color: var(--at-text-muted);
}

.at-v2 .input-group-text {
    font-size: .8125rem;
    background: var(--at-surface-2);
    border-color: var(--at-border-strong);
}

.at-v2 .accordion-button {
    font-size: .8125rem;
    font-weight: 600;
    padding: 10px 16px;
    color: var(--at-text);
    background: var(--at-surface);
    box-shadow: none;
}

.at-v2 .accordion-button:not(.collapsed) {
    background: var(--at-surface-2);
    color: var(--at-text);
}

.at-v2 .accordion-button:focus {
    box-shadow: 0 0 0 3px rgba(var(--at-brand-rgb), .15);
}

.at-v2 .modal-content {
    border-radius: 12px;
    border: 1px solid var(--at-border);
    box-shadow: 0 20px 48px rgba(16, 24, 40, .18);
}

.at-v2 .modal-title {
    font-size: 1rem;
    font-weight: 700;
}

.at-v2 .dropdown-menu {
    font-size: .8125rem;
    border-color: var(--at-border);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(16, 24, 40, .12);
}

.at-v2 .dropdown-item {
    border-radius: 6px;
    padding: 6px 10px;
}

.at-v2 .dropdown-menu {
    padding: 4px;
}

/* ------------------------------------------------------------------ */
/* Modern page frame                                                   */
/* ------------------------------------------------------------------ */

.at-modern {
    color: var(--at-text);
    font-size: .875rem;
    line-height: 1.5;
    min-width: 0;
}

.at-modern a {
    color: var(--at-brand);
    text-decoration: none;
}

.at-modern a:hover {
    text-decoration: underline;
}

.at-modern a.btn,
.at-modern a.btn:hover {
    color: var(--bs-btn-color);
}

.at-modern a.btn:hover {
    color: var(--bs-btn-hover-color);
}

.at-modern a.btn:hover,
.at-modern a.at-seg-item:hover,
.at-modern a.at-kpi:hover,
.at-modern a.at-list-row:hover,
.at-modern .nav-link:hover {
    text-decoration: none;
}

.at-num {
    font-variant-numeric: tabular-nums;
}

.at-muted {
    color: var(--at-text-muted);
}

/* Page head ---------------------------------------------------------- */

.at-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 20px;
    margin-bottom: 18px;
}

.at-page-head-main {
    min-width: 0;
}

.at-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: .75rem;
    color: var(--at-text-muted);
    margin-bottom: 4px;
}

.at-breadcrumb a {
    color: var(--at-text-muted);
}

.at-breadcrumb .sep {
    opacity: .6;
}

.at-page-title {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -.015em;
    line-height: 1.25;
    margin: 0;
    color: var(--at-text);
}

.at-page-sub {
    color: var(--at-text-muted);
    font-size: .8125rem;
    margin: 4px 0 0;
}

.at-page-actions {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Cards --------------------------------------------------------------- */

.at-card {
    background: var(--at-surface);
    border: 1px solid var(--at-border);
    border-radius: var(--at-radius);
    box-shadow: var(--at-shadow);
    margin-bottom: 16px;
    min-width: 0;
}

.at-card-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--at-border);
}

.at-card-title {
    font-size: .9375rem;
    font-weight: 700;
    margin: 0;
    color: var(--at-text);
}

.at-card-sub {
    font-size: .75rem;
    color: var(--at-text-muted);
    margin: 0;
}

.at-card-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
    align-items: center;
}

.at-card-body {
    padding: 16px;
}

.at-card-foot {
    padding: 10px 16px;
    border-top: 1px solid var(--at-border);
    background: var(--at-surface-2);
    border-radius: 0 0 var(--at-radius) var(--at-radius);
    font-size: .8125rem;
}

.at-card-flush {
    overflow-x: auto;
}

.at-card-flush > .table,
.at-card-flush .dt-container .table {
    margin-bottom: 0;
}

.at-card-attn {
    border-color: #f5d38a;
}

.at-card-attn > .at-card-head {
    background: #fff8e6;
    border-bottom-color: #f5d38a;
    border-radius: var(--at-radius) var(--at-radius) 0 0;
}

/* KPI tiles ----------------------------------------------------------- */

.at-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.at-kpi {
    display: block;
    background: var(--at-surface);
    border: 1px solid var(--at-border);
    border-radius: var(--at-radius);
    box-shadow: var(--at-shadow);
    padding: 14px 16px;
    color: var(--at-text);
    min-width: 0;
}

a.at-kpi {
    transition: border-color .15s, box-shadow .15s;
}

a.at-kpi:hover {
    border-color: rgba(var(--at-brand-rgb), .45);
    box-shadow: 0 0 0 3px rgba(var(--at-brand-rgb), .08);
}

.at-kpi-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--at-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.at-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    color: var(--at-text);
}

.at-kpi-sub {
    font-size: .75rem;
    color: var(--at-text-muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.at-kpi-rows {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    margin-top: 8px;
    font-size: .8125rem;
    font-variant-numeric: tabular-nums;
}

.at-kpi-rows span:nth-child(odd) {
    color: var(--at-text-muted);
}

.at-kpi-rows span:nth-child(even) {
    text-align: right;
    font-weight: 600;
}

/* Segmented status filter -------------------------------------------- */

.at-seg {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.at-seg-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px solid var(--at-border);
    border-radius: 999px;
    background: var(--at-surface);
    color: #344054 !important;
    font-size: .8125rem;
    font-weight: 600;
}

.at-seg-item:hover {
    border-color: var(--at-border-strong);
    background: var(--at-surface-2);
}

.at-seg-item .at-seg-count {
    font-size: .6875rem;
    font-weight: 700;
    color: var(--at-text-muted);
    background: var(--at-surface-2);
    border-radius: 999px;
    padding: 1px 7px;
    font-variant-numeric: tabular-nums;
}

.at-seg-item.active {
    background: rgba(var(--at-brand-rgb), .10);
    border-color: rgba(var(--at-brand-rgb), .45);
    color: var(--at-brand) !important;
}

.at-seg-item.active .at-seg-count {
    background: var(--at-surface);
    color: var(--at-brand);
}

/* Tables -------------------------------------------------------------- */

.at-table {
    --bs-table-hover-bg: rgba(var(--at-brand-rgb), .04);
    font-size: .8125rem;
    margin-bottom: 0;
}

.at-table > thead > tr > th {
    background: var(--at-surface-2);
    color: #475467;
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    border-bottom: 1px solid var(--at-border);
    padding: 9px 12px;
    vertical-align: middle;
}

.at-table > tbody > tr > td {
    padding: 9px 12px;
    border-bottom-color: var(--at-border);
    vertical-align: middle;
}

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

.at-table th a.at-sort {
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.at-table th a.at-sort i {
    font-size: .625rem;
    opacity: .45;
}

.at-table th a.at-sort.active i {
    opacity: 1;
    color: var(--at-brand);
}

.at-table td.at-right,
.at-table th.at-right {
    text-align: right;
}

.at-table .at-cell-main {
    font-weight: 600;
    color: var(--at-text);
}

.at-table .at-cell-sub {
    font-size: .75rem;
    color: var(--at-text-muted);
}

.at-modern .dt-container {
    font-size: .8125rem;
}

.at-modern .dt-container > .row {
    padding: 0 16px;
    margin: 10px 0;
    align-items: center;
}

.at-modern .dt-container > .row:has(table),
.at-modern .dt-container > .row:has(.dt-scroll) {
    padding: 0;
    margin: 0;
}

.at-modern .dt-container > .row:has(table) > [class*="col"] {
    padding: 0;
}

/* Pills ---------------------------------------------------------------- */

.at-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .6875rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
    background: #eef0f3;
    color: #344054;
}

.at-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .8;
}

.at-pill-plain::before {
    display: none;
}

.at-pill-success { background: #e3f4e8; color: #1e6b36; }
.at-pill-warning { background: #fff2d6; color: #8a5a00; }
.at-pill-danger  { background: #fde7e7; color: #a11c1c; }
.at-pill-info    { background: #e3f1fb; color: #155a8a; }
.at-pill-brand   { background: rgba(var(--at-brand-rgb), .12); color: var(--at-brand); }
.at-pill-neutral { background: #eef0f3; color: #475467; }

/* Detail grid --------------------------------------------------------- */

.at-dl {
    display: grid;
    grid-template-columns: minmax(120px, 38%) 1fr;
    gap: 8px 16px;
    margin: 0;
    font-size: .8125rem;
}

.at-dl dt {
    color: var(--at-text-muted);
    font-weight: 500;
}

.at-dl dd {
    margin: 0;
    color: var(--at-text);
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Row list ------------------------------------------------------------ */

.at-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.at-list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--at-border);
    color: var(--at-text) !important;
}

.at-list > li:last-child > .at-list-row,
.at-list > .at-list-row:last-child {
    border-bottom: 0;
}

a.at-list-row:hover {
    background: var(--at-surface-2);
}

.at-list-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(var(--at-brand-rgb), .10);
    color: var(--at-brand);
    font-size: .8125rem;
}

.at-list-icon.attn {
    background: #fdecec;
    color: var(--at-danger);
}

.at-list-main {
    flex: 1 1 auto;
    min-width: 0;
}

.at-list-title {
    font-weight: 600;
    font-size: .8125rem;
}

.at-list-sub {
    font-size: .75rem;
    color: var(--at-text-muted);
}

.at-list-end {
    margin-left: auto;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Profile header -------------------------------------------------------- */

.at-profile {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.at-avatar-lg {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    background: rgba(var(--at-brand-rgb), .12);
    color: var(--at-brand);
    font-weight: 700;
    font-size: 1.125rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

/* Tabs (sub-page navigation) ------------------------------------------- */

.at-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--at-border);
    margin-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.at-tabs a,
.at-tabs button {
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 8px 12px;
    font-size: .8125rem;
    font-weight: 600;
    color: #475467 !important;
    white-space: nowrap;
    margin-bottom: -1px;
    text-decoration: none !important;
}

.at-tabs a:hover,
.at-tabs button:hover {
    color: var(--at-text) !important;
}

.at-tabs a.active,
.at-tabs button.active {
    color: var(--at-brand) !important;
    border-bottom-color: var(--at-brand);
}

/* Empty state ---------------------------------------------------------- */

.at-empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--at-text-muted);
}

.at-empty i {
    font-size: 1.5rem;
    margin-bottom: 8px;
    color: #98a2b3;
}

.at-empty-title {
    font-weight: 700;
    color: var(--at-text);
    margin-bottom: 2px;
}

/* Sticky save bar ------------------------------------------------------- */

.at-savebar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    padding: 12px 16px;
    margin: 0 -1px -1px;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--at-border);
    border-radius: 0 0 var(--at-radius) var(--at-radius);
    backdrop-filter: blur(4px);
}

/* Notes / timeline ------------------------------------------------------ */

.at-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.at-timeline > li {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--at-border);
}

.at-timeline > li:last-child {
    border-bottom: 0;
}

.at-timeline-meta {
    font-size: .75rem;
    color: var(--at-text-muted);
}

.at-timeline-meta strong {
    display: block;
    color: var(--at-text);
    font-size: .8125rem;
}

.at-timeline-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: .8125rem;
}

@media (max-width: 767.98px) {
    .at-timeline > li {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .at-dl {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .at-dl dd {
        margin-bottom: 8px;
    }

    .at-page-actions {
        margin-left: 0;
    }
}

/* Charts --------------------------------------------------------------- */

.at-chart {
    position: relative;
    height: 280px;
}

.at-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: .75rem;
    color: #475467;
}

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

.at-legend i {
    width: 14px;
    height: 3px;
    border-radius: 2px;
    display: inline-block;
}

/* Date range ------------------------------------------------------------ */

.at-daterange {
    flex-wrap: nowrap;
    max-width: 560px;
}

.at-daterange input[type="text"] {
    min-width: 110px;
}

/* Totals strip above report tables ---------------------------------------- */

.at-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 28px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--at-border);
    background: var(--at-surface-2);
}

.at-totals > div {
    min-width: 0;
}

.at-totals .lbl {
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--at-text-muted);
}

.at-totals .val {
    font-size: 1.0625rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Fallback for controls rendered by PHP helpers inside modern pages (e.g. the time zone select) */
.at-modern select:not(.form-select):not(.dt-input),
.at-modern input[type="text"]:not(.form-control):not(.dt-input) {
    display: block;
    width: 100%;
    min-height: 34px;
    padding: 5px 10px;
    font-size: .8125rem;
    color: var(--at-text);
    background-color: var(--at-surface);
    border: 1px solid var(--at-border-strong);
    border-radius: var(--at-radius-sm);
    box-shadow: none;
}

/* ---- Server-side pager (tpl/admin_v2/_ui/pager.tpl, 2026-09-29) ---------------------------- */
.at-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    padding: 10px 14px;
    border-top: 1px solid var(--at-border);
    font-size: .8125rem;
    color: var(--at-text-muted);
}
.at-card-head + .at-pager,
.at-pager.at-pager-top { border-top: 0; border-bottom: 1px solid var(--at-border); }
.at-pager-info strong { color: var(--at-text); font-weight: 600; }
.at-pager-per { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.at-pager-per .form-select { width: auto; padding-top: 2px; padding-bottom: 2px; }
.at-pager nav { margin-left: auto; }
.at-pager .pagination { --bs-pagination-active-bg: var(--at-brand); --bs-pagination-active-border-color: var(--at-brand); --bs-pagination-color: var(--at-text); }
.at-table th a.at-sort { white-space: nowrap; }
@media (max-width: 575.98px) { .at-pager nav { margin-left: 0; width: 100%; overflow-x: auto; } }

/* ---- Report center (tpl/admin_v2/report/center.tpl, 2026-09-29) ---------------------------- */
.rc-group-title { font-size: .8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--at-text-muted); margin: 8px 0 10px; }
a.rc-tile { display: block; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.rc-tile:hover, a.rc-tile:focus-visible { border-color: var(--at-brand); box-shadow: 0 4px 14px rgba(var(--at-brand-rgb), .14); transform: translateY(-1px); }
.rc-tile-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: rgba(var(--at-brand-rgb), .1); color: var(--at-brand); margin-bottom: 10px; }
.rc-tile-title { font-weight: 600; margin-bottom: 4px; }
.rc-tile-desc { font-size: .8125rem; color: var(--at-text-muted); line-height: 1.4; }
.rc-table td, .rc-table th { white-space: nowrap; }
.rc-table td:not(.at-num) { white-space: normal; min-width: 120px; }
