/**
 * Shared SHG list / filter / empty / focus surfaces.
 * Tokens live in templates/base.html :root — do not redefine brand colors here.
 */

/* Stronger secondary copy than Bootstrap default #6c757d on #f8f9fa */
.text-muted,
.form-text {
    color: #5a6570 !important;
}

/*
 * REGRESSION GUARDS — do not weaken these.
 * Past mistakes: light text on light headers; grey thead text on dark thead;
 * purple (#667eea/#764ba2) page themes; pale gold KPIs with white text.
 */

/*
 * Thead contrast:
 * - Default SHG thead (base.html dark bg) → light text
 * - Bootstrap thead.table-light / .table-light → dark text on light bg
 * Never force grey body text onto a dark thead.
 */
.table > thead:not(.table-light) > tr > th {
    color: var(--text-light, #ecf0f1);
}

.table > thead.table-light > tr > th,
.table-light > tr > th {
    color: #212529 !important;
    background-color: #f8f9fa !important;
}

/* Light card headers: dark ink (covers CRM .lead-card and Bootstrap light headers) */
.card-header.bg-white,
.card-header.bg-light,
.card-header.bg-transparent,
.card-header.shg-card-header-light,
.lead-card .card-header {
    color: #212529 !important;
}

.card-header.bg-white h1,
.card-header.bg-white h2,
.card-header.bg-white h3,
.card-header.bg-white h4,
.card-header.bg-white h5,
.card-header.bg-white h6,
.card-header.bg-light h1,
.card-header.bg-light h2,
.card-header.bg-light h3,
.card-header.bg-light h4,
.card-header.bg-light h5,
.card-header.bg-light h6,
.lead-card .card-header h1,
.lead-card .card-header h2,
.lead-card .card-header h3,
.lead-card .card-header h4,
.lead-card .card-header h5,
.lead-card .card-header h6,
.lead-card .card-header .mb-0 {
    color: #212529 !important;
}

/* Warning / orange surfaces: dark text, not white-on-gold */
.bg-warning,
.badge.bg-warning,
.btn-warning {
    color: #1a1a1a !important;
}

.text-warning {
    color: var(--accent-orange, #f39c12) !important;
}

/* —— Focus & clickability —— */
a[href],
button:not(:disabled),
[role="button"],
.btn,
.nav-link,
.form-check-input,
.form-select,
.form-control,
summary {
    cursor: pointer;
}

a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.page-link:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
    outline: 2px solid var(--accent-blue, #3498db);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.25);
}

.btn:focus:not(:focus-visible),
.form-control:focus:not(:focus-visible),
.form-select:focus:not(:focus-visible) {
    box-shadow: none;
}

/* —— Top back link (GymOWl-style parent exit; not an action-row button) —— */
.shg-back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0 0 0.85rem;
    padding: 0.15rem 0;
    color: var(--accent-blue, #3498db);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: color 160ms ease;
}
.shg-back-link:hover,
.shg-back-link:focus-visible {
    color: var(--primary-dark, #2c3e50);
    text-decoration: none;
}
.shg-back-link:focus-visible {
    outline: 2px solid var(--accent-blue, #3498db);
    outline-offset: 2px;
    border-radius: 2px;
}
.shg-back-link i {
    font-size: 0.75rem;
    line-height: 1;
}
@media (prefers-reduced-motion: reduce) {
    .shg-back-link { transition: none; }
}

/* —— Page header —— */
.shg-page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.shg-page-header__title {
    margin-bottom: 0;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-dark, #2c3e50);
}

.shg-page-header__sub {
    margin: 0.35rem 0 0;
    color: var(--muted-text, #5a6570);
    font-size: 0.925rem;
}

.shg-page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Buttons with FA icons: consistent alignment (Pro Max — no emoji, stable hover) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.btn > i[class*="fa-"],
.btn > i[class^="fa"] {
    font-size: 0.9em;
    line-height: 1;
    flex-shrink: 0;
}

/* Member detail action row: keep gap when buttons wrap on small screens */
.member-detail-actions {
    gap: 0.5rem;
}

.member-detail-actions .btn {
    margin: 0;
}

/* —— Segment strip (All / Active / Renewal / …) —— */
.shg-segment-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.shg-segment-strip .btn {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* —— Filter toolbar —— */
.shg-filter-toolbar .card-body {
    padding: 1rem 1.15rem;
}

.shg-filter-toolbar .form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted-text, #495057);
    margin-bottom: 0.25rem;
}

.shg-filter-toolbar .form-control,
.shg-filter-toolbar .form-select {
    font-size: 0.925rem;
}

.shg-filter-toolbar__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
}

.shg-filter-toolbar .border-top {
    border-color: var(--border-color, #dee2e6) !important;
}

/* —— Tables —— */
.shg-table-wrap,
.table-responsive {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.shg-table-wrap .table > tbody > tr {
    transition: background-color 0.15s ease;
}

.shg-table-wrap .table > tbody > tr:hover {
    background-color: rgba(52, 152, 219, 0.06);
}

/* Do not override thead color — base.html uses dark bg + light text */
.shg-table-wrap .table thead th {
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/*
 * Root laptop fix for dense action columns:
 * keep full button labels; wrap inside the cell so the page/shell
 * does not gain horizontal scroll (Pro Max: contain table overflow).
 */
.shg-row-actions,
.table td > .d-flex.gap-1,
.table td > .d-flex.gap-2,
.table td .btn-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
}

/* Status + transfer destination: contain long names so tables don't blow out */
.table td.shg-status-cell {
    max-width: 10.5rem;
    white-space: normal;
    vertical-align: middle;
}

.shg-xfer-meta {
    margin-top: 0.25rem;
    max-width: 100%;
}

.shg-xfer-link {
    display: inline-flex;
    align-items: baseline;
    gap: 0.3rem;
    max-width: 100%;
    font-size: 0.75rem;
    line-height: 1.25;
    text-decoration: none;
    color: var(--bs-primary, #0d6efd);
}

.shg-xfer-link:hover,
.shg-xfer-link:focus-visible {
    text-decoration: underline;
}

.shg-xfer-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table td.shg-actions-cell,
.table tbody td:has(> .d-flex.gap-1),
.table tbody td:has(> .shg-row-actions) {
    white-space: normal;
    min-width: 11.5rem;
    vertical-align: middle;
}

/* Compact primary + Options overflow (membership history, etc.) */
.shg-row-actions--primary {
    flex-wrap: nowrap;
    gap: 0.4rem;
}

.shg-row-actions--primary .dropdown {
    flex: 0 0 auto;
}

.shg-actions-menu {
    min-width: 12.5rem;
    max-height: min(20rem, 70vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.35rem 0;
    border: 1px solid rgba(44, 62, 80, 0.12);
    box-shadow: 0 8px 24px rgba(44, 62, 80, 0.12);
    /* Popper strategy:fixed — keep above table overflow scrollers */
    z-index: 1080;
}

.shg-actions-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.875rem;
    color: var(--text-dark, #2c3e50);
}

.shg-actions-menu .dropdown-item:hover,
.shg-actions-menu .dropdown-item:focus {
    background: var(--bg-light, #f8f9fa);
    color: var(--text-dark, #2c3e50);
}

.shg-actions-menu .dropdown-item.text-danger:hover,
.shg-actions-menu .dropdown-item.text-danger:focus {
    background: rgba(231, 76, 60, 0.08);
    color: var(--accent-red, #e74c3c);
}

.shg-actions-menu .dropdown-divider {
    margin: 0.35rem 0;
}

@media (prefers-reduced-motion: reduce) {
    .shg-actions-menu {
        box-shadow: none;
    }
}

.table td .shg-row-actions .btn,
.table td > .d-flex.gap-1 > .btn,
.table td > .d-flex.gap-1 > form .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

/*
 * Cap action-cell width so a long single-line button strip cannot
 * inflate the whole table (root cause of laptop horizontal crush).
 * Labels stay visible; buttons wrap onto a second line.
 */
@media (max-width: 1599.98px) {
    .table td.shg-actions-cell {
        max-width: 18rem;
        width: auto;
    }

    .table td.shg-actions-cell .shg-row-actions:not(.shg-row-actions--primary) {
        max-width: 100%;
    }
}

@media (max-width: 1399.98px) {
    .table td.shg-actions-cell {
        max-width: 16rem;
        width: auto;
    }

    .table > :not(caption) > * > * {
        padding: 0.45rem 0.5rem;
    }

    .btn.btn-sm {
        padding: 0.28rem 0.55rem;
        font-size: 0.8125rem;
    }

    .shg-page-header {
        gap: 0.5rem;
        margin-bottom: 0.85rem;
    }

    .shg-filter-toolbar .card-body {
        padding: 0.75rem 0.85rem;
    }

    .shg-segment-strip {
        gap: 0.35rem;
    }
}

@media (max-width: 1199.98px) {
    .table td.shg-actions-cell {
        max-width: 16.5rem;
        width: 16.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .shg-table-wrap .table > tbody > tr {
        transition: none;
    }
}

/* —— Empty / no-result —— */
.shg-empty {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: var(--bg-lighter, #fff);
    border: 1px dashed var(--border-color, #dee2e6);
    border-radius: 0.5rem;
}

.shg-empty__icon {
    font-size: 2rem;
    color: var(--muted-text, #adb5bd);
    margin-bottom: 0.75rem;
}

.shg-empty__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark, #2c3e50);
    margin-bottom: 0.35rem;
}

.shg-empty__body {
    color: var(--muted-text, #5a6570);
    font-size: 0.95rem;
    max-width: 28rem;
    margin: 0 auto 1rem;
}

.shg-empty__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.shg-empty--filtered .shg-empty__icon {
    color: var(--accent-orange, #f39c12);
}

/* —— Reduced motion —— */
@media (prefers-reduced-motion: reduce) {
    .shg-segment-strip .btn,
    .shg-table-wrap .table > tbody > tr,
    .shg-page-header,
    a, button, .btn, .nav-link {
        transition: none !important;
    }
}
