/**
 * Unified UI Components
 * Standardized tables, badges, filters, and mobile cards
 */

/* ==========================================================================
   CSS Variables - Component Colors
   ========================================================================== */
:root {
    /* Status colors */
    --status-success: #2e7d32;
    --status-success-bg: #e8f5e9;
    --status-warning: #e65100;
    --status-warning-bg: #fff3e0;
    --status-error: #c62828;
    --status-error-bg: #ffebee;
    --status-info: #1565c0;
    --status-info-bg: #e3f2fd;

    /* Role colors */
    --role-admin: #c62828;
    --role-admin-bg: #ffebee;
    --role-committee: #1565c0;
    --role-committee-bg: #e3f2fd;
    --role-cellar: #7b1fa2;
    --role-cellar-bg: #f3e5f5;
    --role-member: #2e7d32;
    --role-member-bg: #e8f5e9;

    /* Wine type colors */
    --wine-red: #c62828;
    --wine-red-bg: #ffebee;
    --wine-white: #f9a825;
    --wine-white-bg: #fffde7;
    --wine-sparkling: #00838f;
    --wine-sparkling-bg: #e0f7fa;
    --wine-rose: #d81b60;
    --wine-rose-bg: #fce4ec;
    --wine-fortified: #6d4c41;
    --wine-fortified-bg: #efebe9;
    --wine-dessert: #ff8f00;
    --wine-dessert-bg: #fff8e1;

    /* Table colors */
    --table-header: #722F37;
    --table-hover: #f8f8f8;
    --table-border: #eee;
    --table-stripe: #fafafa;
}

/* ==========================================================================
   Data Tables - Unified Style
   ========================================================================== */
.data-table-wrapper {
    background: var(--bg-secondary, white);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow, rgba(0,0,0,0.08));
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--table-header);
}

.data-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    border-bottom: none;
}

.data-table th a {
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.data-table th a:hover {
    text-decoration: underline;
}

.data-table th .sort-icon {
    opacity: 0.7;
    font-size: 10px;
}

.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--table-border);
    font-size: 13px;
    vertical-align: middle;
    color: var(--text-primary, #333);
}

.data-table tbody tr {
    transition: background-color 0.15s;
}

.data-table tbody tr:hover {
    background: var(--table-hover);
}

/* Striped rows (optional) */
.data-table.striped tbody tr:nth-child(even) {
    background: var(--table-stripe);
}

.data-table.striped tbody tr:hover {
    background: var(--table-hover);
}

/* Compact table variant */
.data-table.compact th,
.data-table.compact td {
    padding: 8px;
    font-size: 12px;
}

/* Text alignment utilities for tables */
.data-table .text-right {
    text-align: right;
}

.data-table .text-center {
    text-align: center;
}

.data-table .text-nowrap {
    white-space: nowrap;
}

/* Numeric column styling */
.data-table .col-number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table .col-currency {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* Action column */
.data-table .col-actions {
    white-space: nowrap;
    text-align: right;
}

/* ==========================================================================
   Filter Bar - Unified Style
   ========================================================================== */
.filter-bar {
    width: 100%;
    max-width: none;
    background: var(--bg-secondary, white);
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    box-shadow: 0 1px 3px var(--shadow, rgba(0,0,0,0.05));
    box-sizing: border-box;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 160px;
    min-width: 140px;
}

.filter-group.flex-1 {
    flex: 2 1 200px;
    min-width: 180px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group input,
.filter-group select {
    height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    font-size: 14px;
    background: var(--bg-primary, #f5f5f5);
    color: var(--text-primary, #333);
    box-sizing: border-box;
    width: 100%;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--accent, #722F37);
    box-shadow: 0 0 0 2px rgba(114, 47, 55, 0.1);
}

.filter-group input::placeholder {
    color: var(--text-muted, #999);
}

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 0 0 auto;
}

.filter-actions .btn {
    height: 44px;
    padding: 0 18px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.filter-actions .btn-clear {
    background: var(--bg-primary, #f5f5f5);
    color: var(--text-secondary, #666);
}

.filter-actions .btn-clear:hover {
    background: #e0e0e0;
}

/* Pill-style toggles inside a .filter-group (anchor links acting as filters). */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    min-height: 32px;
    border-radius: 999px;
    background: var(--bg-primary, #f5f5f5);
    color: var(--text-secondary, #555);
    border: 1px solid var(--border-color, #e0e0e0);
    font-size: 13px;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.filter-pill:hover {
    color: var(--accent, #722F37);
    border-color: var(--accent, #722F37);
    background: var(--bg-secondary, #fff);
}

.filter-pill.active {
    background: var(--accent, #722F37);
    color: #fff;
    border-color: var(--accent, #722F37);
}

.filter-pill.active:hover {
    background: var(--accent, #722F37);
    color: #fff;
    opacity: 0.92;
}

/* Filter summary/count */
.filter-summary {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-secondary, #666);
    padding: 8px 0;
    flex: 0 0 auto;
}

/* Tablet/Mobile filter */
@media (max-width: 768px) {
    .filter-bar {
        padding: 10px;
        gap: 8px;
        border-radius: 10px;
    }

    .filter-group {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .filter-group label {
        font-size: 10px;
    }

    .filter-group input,
    .filter-group select {
        height: 42px;
        font-size: 14px;
        padding: 8px 10px;
    }

    .filter-group.flex-1 {
        flex: 1 1 100%;
        min-width: 0;
    }

    .filter-group.half {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .filter-actions {
        flex: 1 1 100%;
        justify-content: stretch;
    }

    .filter-actions .btn {
        flex: 1;
        text-align: center;
    }

    .filter-summary {
        width: 100%;
        text-align: center;
        margin-left: 0;
    }
}

/* ==========================================================================
   Badges - Unified Style
   ========================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Status badges */
.badge-active,
.badge-success,
.badge-paid,
.badge-reconciled {
    background: var(--status-success-bg);
    color: var(--status-success);
}

.badge-inactive,
.badge-closed {
    background: #f5f5f5;
    color: #4a4a4a;
}

.badge-pending,
.badge-warning,
.badge-attention {
    background: var(--status-warning-bg);
    color: var(--status-warning);
}

.badge-error,
.badge-unpaid,
.badge-failed,
.badge-overdue {
    background: var(--status-error-bg);
    color: var(--status-error);
}

.badge-info,
.badge-open,
.badge-rsvp {
    background: var(--status-info-bg);
    color: var(--status-info);
}

.badge-planning {
    background: #f3e5f5;
    color: #7b1fa2;
}

/* Role badges */
.badge-admin {
    background: var(--role-admin-bg);
    color: var(--role-admin);
}

.badge-committee {
    background: var(--role-committee-bg);
    color: var(--role-committee);
}

.badge-cellar,
.badge-cellar_master {
    background: var(--role-cellar-bg);
    color: var(--role-cellar);
}

.badge-member {
    background: var(--role-member-bg);
    color: var(--role-member);
}

/* Wine type badges */
.badge-red {
    background: var(--wine-red-bg);
    color: var(--wine-red);
}

.badge-white {
    background: var(--wine-white-bg);
    color: var(--wine-white);
}

.badge-sparkling {
    background: var(--wine-sparkling-bg);
    color: var(--wine-sparkling);
}

.badge-rose {
    background: var(--wine-rose-bg);
    color: var(--wine-rose);
}

.badge-fortified {
    background: var(--wine-fortified-bg);
    color: var(--wine-fortified);
}

.badge-dessert {
    background: var(--wine-dessert-bg);
    color: var(--wine-dessert);
}

/* Category badges */
.badge-general {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-premium {
    background: #fff3e0;
    color: #e65100;
}

.badge-icon {
    background: #fce4ec;
    color: #c2185b;
}

.badge-ladies {
    background: #f3e5f5;
    color: #7b1fa2;
}

.badge-special {
    background: #e3f2fd;
    color: #1565c0;
}

/* Entity type badges (for audit log) */
.badge-entity-event { background: #e3f2fd; color: #1565c0; }
.badge-entity-survey { background: #f3e5f5; color: #7b1fa2; }
.badge-entity-cellar { background: #fff3e0; color: #e65100; }
.badge-entity-photo { background: #e8f5e9; color: #2e7d32; }
.badge-entity-member { background: #fce4ec; color: #c2185b; }
.badge-entity-user { background: #ffebee; color: #c62828; }
.badge-entity-auth { background: #e8eaf6; color: #3f51b5; }
.badge-entity-transaction { background: #e0f2f1; color: #00695c; }

/* Tier badges */
.badge-esteemed {
    background: linear-gradient(135deg, #ffd700, #ffb300);
    color: #5d4037;
}

.badge-senior {
    background: linear-gradient(135deg, #90caf9, #64b5f6);
    color: #0d47a1;
}

.badge-ordinary {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-life {
    background: linear-gradient(135deg, #ce93d8, #ba68c8);
    color: #4a148c;
}

.badge-guest {
    background: #f5f5f5;
    color: #666;
}

/* Small badge variant */
.badge-sm {
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 8px;
}

/* Large badge variant */
.badge-lg {
    padding: 5px 14px;
    font-size: 13px;
    border-radius: 16px;
}

/* ==========================================================================
   Mobile Cards - Data Display
   ========================================================================== */
.mobile-cards {
    display: none;
}

.data-card {
    background: var(--bg-secondary, white);
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px var(--shadow, rgba(0,0,0,0.1));
}

.data-card-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #722F37 0%, #8B4049 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.data-card-header > div:first-child {
    flex: 1;
    min-width: 0;
}

.data-card-title {
    font-weight: 600;
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-card-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-card-body {
    padding: 4px 16px;
}

.data-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--table-border);
    font-size: 14px;
    min-height: 40px;
}

.data-card-row:last-child {
    border-bottom: none;
}

.data-card-label {
    color: var(--text-secondary, #666);
    font-weight: 500;
}

.data-card-value {
    color: var(--text-primary, #333);
    text-align: right;
    font-weight: 500;
}

.data-card-footer {
    padding: 10px 16px 14px;
    background: var(--bg-primary, #f5f5f5);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.data-card-footer .btn,
.data-card-footer a,
.data-card-footer button {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex: 1;
    text-align: center;
    text-decoration: none;
}

/* Card stats grid */
.data-card-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 12px 15px;
    background: var(--bg-primary, #f5f5f5);
}

.data-card-stat {
    text-align: center;
}

.data-card-stat .value {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent, #722F37);
}

.data-card-stat .label {
    font-size: 10px;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
}

/* Mobile breakpoint - show cards, hide table */
@media (max-width: 768px) {
    .desktop-table {
        display: none !important;
    }

    .mobile-cards {
        display: block;
    }

    .data-card-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .data-card-footer {
        gap: 6px;
    }
}

/* ==========================================================================
   Action Buttons - Table Actions
   ========================================================================== */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.15s;
}

.action-btn-edit {
    background: #e3f2fd;
    color: #1565c0;
}

.action-btn-edit:hover {
    background: #bbdefb;
}

.action-btn-delete {
    background: #ffebee;
    color: #c62828;
}

.action-btn-delete:hover {
    background: #ffcdd2;
}

.action-btn-view {
    background: #f5f5f5;
    color: #666;
}

.action-btn-view:hover {
    background: #e0e0e0;
}

.action-btn-money {
    background: #e8f5e9;
    color: #2e7d32;
}

.action-btn-money:hover {
    background: #c8e6c9;
}

/* Action button group */
.action-btns {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary, #666);
    background: var(--bg-secondary, white);
    border-radius: 8px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.empty-state h3 {
    margin: 0 0 10px;
    color: var(--text-primary, #333);
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* ==========================================================================
   Stats Cards - Summary Display
   ========================================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-secondary, white);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 3px var(--shadow, rgba(0,0,0,0.08));
}

.stat-card-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent, #722F37);
    line-height: 1.2;
}

.stat-card-label {
    font-size: 12px;
    color: var(--text-secondary, #666);
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.success .stat-card-value { color: var(--status-success); }
.stat-card.warning .stat-card-value { color: var(--status-warning); }
.stat-card.error .stat-card-value { color: var(--status-error); }
.stat-card.info .stat-card-value { color: var(--status-info); }

/* Named color variants */
.stat-card.green .stat-card-value { color: #2e7d32; }
.stat-card.blue .stat-card-value { color: #1976d2; }
.stat-card.purple .stat-card-value { color: #7b1fa2; }
.stat-card.orange .stat-card-value { color: #e65100; }
.stat-card.red .stat-card-value { color: #c62828; }

/* Solid accent variant: white text on burgundy background */
.stat-card.accent { background: var(--accent, #722F37); border-color: var(--accent, #722F37); }
.stat-card.accent .stat-card-value,
.stat-card.accent .stat-card-label { color: white; }

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 16px;
    }

    .stat-card {
        padding: 12px 8px;
    }

    .stat-card-value {
        font-size: 20px;
    }

    .stat-card-label {
        font-size: 10px;
        letter-spacing: 0.3px;
    }
}

@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==========================================================================
   FY Selector
   ========================================================================== */
.fy-selector {
    display: flex;
    gap: 10px;
    align-items: center;
}

.fy-selector select {
    padding: 8px 15px;
    border: 2px solid var(--accent, #722F37);
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-secondary, white);
    color: var(--text-primary, #333);
}

/* ==========================================================================
   Page Header - Consistent Style
   ========================================================================== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-header h2 {
    color: var(--accent, #722F37);
    margin: 0;
    font-size: 24px;
}

.page-header h2 a {
    color: inherit;
    text-decoration: none;
}

.page-header h2 a:hover {
    text-decoration: underline;
}

.page-header p {
    color: var(--text-secondary, #666);
    margin: 0;
    font-size: 14px;
    width: 100%;
}

@media (max-width: 768px) {
    .page-header {
        gap: 10px;
        margin-bottom: 16px;
    }

    .page-header h2 {
        font-size: 20px;
    }
}

/* ==========================================================================
   Alerts & Messages
   ========================================================================== */
.alert {
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.alert-success {
    background: var(--status-success-bg);
    color: var(--status-success);
    border: 1px solid #c8e6c9;
}

.alert-error {
    background: var(--status-error-bg);
    color: var(--status-error);
    border: 1px solid #ffcdd2;
}

.alert-warning {
    background: var(--status-warning-bg);
    color: var(--status-warning);
    border: 1px solid #ffe0b2;
}

.alert-info {
    background: var(--status-info-bg);
    color: var(--status-info);
    border: 1px solid #bbdefb;
}

/* ==========================================================================
   Button Base Normalization
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 44px;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
    transition: background 0.15s, opacity 0.15s;
    vertical-align: middle;
}

/* ==========================================================================
   Button Sizes
   ========================================================================== */
.btn-sm {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
}

.btn-xs {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
}

.btn-lg {
    height: 52px;
    padding: 0 28px;
    font-size: 16px;
}

/* Full-width button */
.btn-block {
    display: flex;
    width: 100%;
    text-align: center;
}

/* Mobile: enforce minimum 44px touch targets on all buttons */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding: 0 18px;
    }

    .btn-sm {
        min-height: 40px;
        padding: 0 14px;
        font-size: 13px;
    }

    .btn-xs {
        min-height: 36px;
        padding: 0 12px;
        font-size: 12px;
    }
}

/* ==========================================================================
   Button Variants
   ========================================================================== */
.btn-secondary {
    background: #666;
    color: white;
}

.btn-secondary:hover {
    background: #555;
}

.btn-light {
    background: #f5f5f5;
    color: #333;
}

.btn-light:hover {
    background: #e0e0e0;
}

.btn-success {
    background: var(--status-success);
    color: white;
}

.btn-success:hover {
    background: #1b5e20;
}

.btn-danger {
    background: var(--status-error);
    color: white;
}

.btn-danger:hover {
    background: #b71c1c;
}

.btn-warning {
    background: var(--status-warning);
    color: white;
}

.btn-warning:hover {
    background: #bf360c;
}

.btn-info {
    background: #1976d2;
    color: white;
}

.btn-info:hover {
    background: #1565c0;
}

.btn-purple {
    background: #7c3aed;
    color: white;
}

.btn-purple:hover {
    background: #6d28d9;
}

/* Ghost button — for use on solid coloured backgrounds (accent panels, gradient headers) */
.btn-ghost {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.4);
}

.btn-ghost:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.6);
}

/* Cancel button - gray */
.btn-cancel {
    background: #666;
    color: white;
}

.btn-cancel:hover {
    background: #555;
}

/* Outline variants */
.btn-outline {
    background: transparent;
    border: 1px solid currentColor;
}

.btn-outline:hover {
    opacity: 0.8;
}

/* ==========================================================================
   Button Row - Form Action Buttons
   ========================================================================== */
.btn-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.btn-row .btn,
.btn-row button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 20px;
    font-size: 14px;
    box-sizing: border-box;
    margin: 0; /* Reset all margins including browser default button margin */
}

.btn-row .btn-delete,
.btn-row .btn-danger {
    background: #c62828;
    color: white;
}

.btn-row .btn-delete:hover,
.btn-row .btn-danger:hover {
    background: #b71c1c;
}

@media (max-width: 768px) {
    .btn-row {
        flex-direction: column;
        gap: 8px;
    }

    .btn-row .btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
}

/* ==========================================================================
   Dark Mode Overrides
   ========================================================================== */
[data-theme="dark"] .data-table-wrapper,
[data-theme="dark"] .filter-bar,
[data-theme="dark"] .data-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .empty-state {
    background: var(--bg-secondary);
}

[data-theme="dark"] .data-table td {
    border-color: var(--border-color);
}

[data-theme="dark"] .data-table tbody tr:hover {
    background: var(--bg-primary);
}

[data-theme="dark"] .data-card-header {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
}

[data-theme="dark"] .data-card-footer,
[data-theme="dark"] .data-card-stats {
    background: var(--bg-primary);
}

[data-theme="dark"] .filter-group input,
[data-theme="dark"] .filter-group select {
    background: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Status-tinted panels (alert-info, info-box, etc.) — readable on dark */
[data-theme="dark"] {
    --status-info-bg: rgba(21, 101, 192, 0.18);
    --status-success-bg: rgba(46, 125, 50, 0.18);
    --status-warning-bg: rgba(230, 81, 0, 0.18);
    --status-error-bg: rgba(198, 40, 40, 0.18);
}
[data-theme="dark"] .info-box {
    background: var(--status-info-bg) !important;
    color: var(--text-primary);
}
[data-theme="dark"] .info-box strong,
[data-theme="dark"] .info-box h4 { color: var(--text-primary); }

[data-theme="dark"] .action-btn-edit {
    background: rgba(21, 101, 192, 0.2);
}

[data-theme="dark"] .action-btn-delete {
    background: rgba(198, 40, 40, 0.2);
}

[data-theme="dark"] .action-btn-view {
    background: var(--bg-primary);
}

[data-theme="dark"] .btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
[data-theme="dark"] .btn-secondary:hover {
    background: var(--bg-primary);
    border-color: var(--text-secondary);
}

[data-theme="dark"] .bnb-toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
[data-theme="dark"] .bnb-toast-success { background: #1b3a1b; border-left-color: #4CAF50; }
[data-theme="dark"] .bnb-toast-error { background: #3a1b1b; border-left-color: #f44336; }
[data-theme="dark"] .bnb-toast-warning { background: #3a351b; border-left-color: #ff9800; }
[data-theme="dark"] .bnb-toast-info { background: #1b2a3a; border-left-color: #2196F3; }
[data-theme="dark"] .bnb-toast-close { color: var(--text-secondary); }
[data-theme="dark"] .bnb-confirm-dialog {
    background: var(--bg-secondary);
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
[data-theme="dark"] .bnb-confirm-dialog p { color: var(--text-primary); }

/* Badge dark-mode overrides */
[data-theme="dark"] .badge-inactive,
[data-theme="dark"] .badge-closed {
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
}

[data-theme="dark"] .badge-planning {
    background: rgba(123,31,162,0.22);
    color: #ce93d8;
}

[data-theme="dark"] .badge-general {
    background: rgba(46,125,50,0.22);
    color: #81c784;
}

[data-theme="dark"] .badge-premium {
    background: rgba(230,81,0,0.22);
    color: #ffb74d;
}

[data-theme="dark"] .badge-icon {
    background: rgba(194,24,91,0.22);
    color: #f48fb1;
}

[data-theme="dark"] .badge-ladies {
    background: rgba(123,31,162,0.22);
    color: #ce93d8;
}

[data-theme="dark"] .badge-special {
    background: rgba(21,101,192,0.22);
    color: #90caf9;
}

[data-theme="dark"] .badge-entity-event {
    background: rgba(21,101,192,0.22);
    color: #90caf9;
}

[data-theme="dark"] .badge-entity-survey {
    background: rgba(123,31,162,0.22);
    color: #ce93d8;
}

[data-theme="dark"] .badge-entity-cellar {
    background: rgba(230,81,0,0.22);
    color: #ffb74d;
}

[data-theme="dark"] .badge-entity-photo {
    background: rgba(46,125,50,0.22);
    color: #81c784;
}

[data-theme="dark"] .badge-entity-member {
    background: rgba(194,24,91,0.22);
    color: #f48fb1;
}

[data-theme="dark"] .badge-entity-user {
    background: rgba(198,40,40,0.22);
    color: #ef9a9a;
}

[data-theme="dark"] .badge-entity-auth {
    background: rgba(63,81,181,0.22);
    color: #9fa8da;
}

[data-theme="dark"] .badge-entity-transaction {
    background: rgba(0,105,92,0.22);
    color: #80cbc4;
}

[data-theme="dark"] .badge-esteemed {
    background: rgba(255,179,0,0.22);
    color: #ffd54f;
}

[data-theme="dark"] .badge-senior {
    background: rgba(21,101,192,0.22);
    color: #90caf9;
}

[data-theme="dark"] .badge-ordinary {
    background: rgba(46,125,50,0.22);
    color: #81c784;
}

[data-theme="dark"] .badge-life {
    background: rgba(123,31,162,0.22);
    color: #ce93d8;
}

[data-theme="dark"] .badge-guest {
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
#bnb-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 400px;
}

.bnb-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: bnbToastIn 0.3s ease;
    color: #333;
    background: white;
    border-left: 4px solid #666;
}

.bnb-toast-success { border-left-color: var(--status-success); background: var(--status-success-bg); }
.bnb-toast-error { border-left-color: var(--status-error); background: var(--status-error-bg); }
.bnb-toast-warning { border-left-color: var(--status-warning); background: var(--status-warning-bg); }
.bnb-toast-info { border-left-color: var(--status-info); background: var(--status-info-bg); }

.bnb-toast-msg { flex: 1; }

.bnb-toast-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #555;
    padding: 8px;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* .bnb-toast-action — optional action button on a toast (e.g. Undo) */
.bnb-toast-action {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0 14px;
    margin-left: 8px;
    border: 1px solid currentColor;
    border-radius: 9px;
    background: none;
    color: inherit;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    -webkit-appearance: none;
}
.bnb-toast-out {
    animation: bnbToastOut 0.3s ease forwards;
}

@keyframes bnbToastIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes bnbToastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}

@media (max-width: 768px) {
    /* Top on mobile: a bottom toast gets clipped by the home indicator and overlaps
       bottom sheets / sticky footers. */
    #bnb-toast-container {
        left: 10px;
        right: 10px;
        top: calc(env(safe-area-inset-top, 0px) + 64px);
        bottom: auto;
        max-width: none;
    }
}

/* ==========================================================================
   Confirmation Dialog
   ========================================================================== */
.bnb-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.bnb-confirm-dialog {
    background: white;
    border-radius: 10px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.bnb-confirm-dialog p {
    margin: 0 0 20px;
    font-size: 15px;
    color: #333;
    line-height: 1.5;
}

.bnb-confirm-actions {
    display: flex;
    gap: 16px;
    justify-content: flex-end;
}
/* Make the safe action (Cancel) the visually dominant default and give the destructive
   one breathing room, so a withdrawal/deletion isn't triggered by a mis-tap. */
.bnb-confirm-actions .bnb-confirm-cancel { flex: 1; }
.bnb-confirm-actions .bnb-confirm-ok { flex: 1; }

/* ==========================================================================
   Layout Utilities (extracted from header.php)
   ========================================================================== */

/* Card component */
.card {
    background: var(--bg-secondary, white);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color, #eee);
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h3 { margin: 0; }

/* Form components */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 12px; border: 1px solid var(--border-color, #ddd); border-radius: 5px; font-size: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.action-btns form { display: inline; margin: 0; }

/* Panel component */
.panel {
    background: var(--bg-secondary, white);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 5px var(--shadow, rgba(0,0,0,0.1));
}

/* Two-column layout helper */
.two-col-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Sidebar cards */
.sidebar-card {
    background: var(--bg-secondary, white);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

/* Full-width on mobile helper */
.mobile-full-width { width: auto; }

/* Fix modals on mobile */
.modal-content {
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
}

/* Mobile responsive adjustments */
@media (max-width: 900px) {
    .two-col-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .card { padding: 14px; border-radius: 10px; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .form-row { grid-template-columns: 1fr; gap: 12px; }
    .panel { padding: 14px; border-radius: 10px; }
    .sidebar-card { padding: 14px; border-radius: 10px; }
    .mobile-full-width { width: 100%; }
    .modal-content { margin: 10px; padding: 15px; border-radius: 10px; }
}

@media (max-width: 600px) {
    .dashboard-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ==========================================================================
   Dark mode — bare native form controls
   Pages that don't wrap selects/inputs in .filter-group still need themed
   colours in dark mode. Light mode keeps browser default appearance.
   ========================================================================== */
[data-theme="dark"] select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="month"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] textarea {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}
/* Refined Heritage design-system inputs (.input) must use the warm surface in
   dark mode, not the legacy navy palette above. The typed-input selectors there
   (input[type="text"] …) out-specify `.rh/.rh-admin .input`, turning design-system
   fields navy while textareas stay correct. Re-assert the surface for any .input. */
[data-theme="dark"] input.input,
[data-theme="dark"] textarea.input,
[data-theme="dark"] select.input {
    background: var(--surface);
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--line);
}
[data-theme="dark"] select:focus,
[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus {
    border-color: var(--accent);
    outline: none;
}
[data-theme="dark"] select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* ============================================================
   APP-WIDE iOS POLISH (rolled out from the cellar UX fixes, 2026-06-29)
   ============================================================ */
/* iOS Safari zooms when a focused text control has font-size < 16px. Force all text-entry
   controls to 16px on phones (desktop unchanged). !important beats page-local 14/15px
   rules + inline styles; non-text controls excluded so layout is untouched. */
@media (max-width: 767px) {
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]):not([type=button]):not([type=submit]),
    select, textarea { font-size: 16px !important; }
}
/* Search / filter inputs clear the sticky top bar when focus scrolls them up */
input[type="search"], .filter-bar input, .filterbar input, .filter-group input, .set-search, #member-search, #settings-search { scroll-margin-top: 72px; }

/* ---------- Table row-action icon buttons (global; used by users, rules, feed admin, events) ---------- */
.rowacts { display: inline-flex; gap: 5px; }
.tact {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
}
.tact svg { width: 15px; height: 15px; }
.tact:hover { color: var(--burgundy); border-color: color-mix(in srgb, var(--burgundy) 35%, var(--line)); background: var(--surface-2); }
.tact.danger:hover { color: var(--burgundy); }
.tact.go:hover { color: var(--sage-ink); border-color: color-mix(in srgb, var(--sage) 45%, var(--line)); }
