/* Platform Members Styling */

/* Stat Loading Spinner */
.stat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
}

.stat-loading-icon {
    width: 44px;
    height: auto;
    object-fit: contain;
    animation: statPulse 1.2s ease-in-out infinite;
}

@keyframes statPulse {
    0%, 100% {
        opacity: 0.4;
        transform: scale(0.95);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
}

.platform-members-header {
    margin-bottom: 2rem;
    text-align: center;
}

.platform-members-header h1 {
    font-size: 40px;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.platform-members-header p {
    color: #666;
    font-size: 1rem;
}

/* Platform Tabs */
.platform-tabs-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid #e5e7eb;
    justify-content: center;
}

.platform-members-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    font-weight: 500;
    color: #666;
}

.platform-members-tab:hover {
    color: #1a1a1a;
    background: #f9fafb;
}

.platform-members-tab.active {
    color: #007a33;
    border-bottom-color: #007a33;
    background: #f0fdf4;
}

.platform-members-tab .tab-icon {
    font-size: 1.5rem;
}

.platform-members-tab .tab-label {
    font-weight: 600;
}

/* Stats Cards */
.platform-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.stat-primary .stat-icon {
    background: #eff6ff;
}

.stat-success .stat-icon {
    background: #f0fdf4;
}

.stat-info .stat-icon {
    background: #eff6ff;
}

.stat-warning .stat-icon {
    background: #fffbeb;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-primary .stat-value {
    color: #1e40af;
}

.stat-success .stat-value {
    color: #15803d;
}

.stat-info .stat-value {
    color: #1e40af;
}

.stat-warning .stat-value {
    color: #b45309;
}

.stat-label {
    font-size: 0.875rem;
    color: #666;
    font-weight: 500;
}

/* Import Section */
.import-section {
    margin-bottom: 2rem;
}

.import-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.import-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.import-header p {
    color: #666;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.import-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.import-note {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-size: 0.875rem;
    color: #78350f;
}

/* API Sync Section */
.api-sync-section {
    margin-bottom: 2rem;
}

.api-sync-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #00a88f;
}

.api-sync-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.api-sync-header p {
    color: #666;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.api-sync-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Filters */
.members-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 200px;
}

.filter-input,
.filter-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: #007a33;
    box-shadow: 0 0 0 3px rgba(0, 122, 51, 0.1);
}

.filter-result {
    margin-left: auto;
    color: #666;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Members Table */
.members-table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
    max-width: 100%;
}

.members-table {
    width: 100%;
    min-width: 1400px;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.members-table thead {
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
}

.members-table th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.members-table th:hover {
    background: #f3f4f6;
}

.sort-indicator {
    margin-left: 0.5rem;
    color: #007a33;
    font-size: 0.75rem;
}

.members-table tbody tr {
    border-bottom: 1px solid #e5e7eb;
    transition: background-color 0.2s ease;
}

.members-table tbody tr:hover {
    background: #f9fafb;
}

.members-table tbody tr:last-child {
    border-bottom: none;
}

.members-table td {
    padding: 1rem 1.5rem;
    color: #374151;
    vertical-align: middle;
}

/* Status Badges */
.status-badge,
.validation-badge,
.invitation-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Status Colors */
.status-active {
    background: #dcfce7;
    color: #15803d;
}

.status-pending {
    background: #fef3c7;
    color: #b45309;
}

.status-deleted {
    background: #fee2e2;
    color: #b91c1c;
}

.status-default {
    background: #f3f4f6;
    color: #6b7280;
}

/* Validation Colors */
.validated {
    background: #dbeafe;
    color: #1e40af;
}

.not-validated {
    background: #f3f4f6;
    color: #6b7280;
}

/* Invitation Colors */
.invited {
    background: #e0e7ff;
    color: #4338ca;
}

.not-invited {
    background: #f3f4f6;
    color: #9ca3af;
}

/* Role Badge */
.role-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.5px;
    margin: 2px 0;
}

.role-badges-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Role-specific colors */
.role-cashier {
    background: #dbeafe;
    color: #1e40af;
}

.role-manager {
    background: #fef3c7;
    color: #92400e;
}

.role-owner {
    background: #dcfce7;
    color: #15803d;
}

.role-test {
    background: #fef3c7;
    color: #d97706;
}

.role-telesales {
    background: #ede9fe;
    color: #6d28d9;
}

.role-default {
    background: #f3f4f6;
    color: #6b7280;
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    background: white;
    border-top: 1px solid #e5e7eb;
    border-radius: 0 0 12px 12px;
    margin-top: -1px;
}

.pagination-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: #007a33;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: #006328;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 122, 51, 0.2);
}

.pagination-btn:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.pagination-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pagination-info span {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .platform-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .platform-stats-grid {
        grid-template-columns: 1fr;
    }

    .members-filters {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .filter-result {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }

    .import-controls {
        flex-direction: column;
    }

    .import-controls button {
        width: 100%;
    }

    .members-table-container {
        overflow-x: auto;
    }

    .members-table {
        min-width: 800px;
    }

    .platform-tabs-container {
        flex-direction: column;
        gap: 0;
    }

    .platform-members-tab {
        border-bottom: 1px solid #e5e7eb;
        border-left: 3px solid transparent;
    }

    .platform-members-tab.active {
        border-bottom-color: transparent;
        border-left-color: #007a33;
    }
}

/* Button Overrides for Platform Members */
.import-controls .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.import-controls .btn-primary {
    background: #007a33;
    color: white;
}

.import-controls .btn-primary:hover {
    background: #006329;
}

.import-controls .btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.import-controls .btn-secondary:hover {
    background: #e5e7eb;
}

.import-controls .btn-danger {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.import-controls .btn-danger:hover {
    background: #fecaca;
    color: #991b1b;
}

/* Platform Members Section Override */
#platformMembersSection .page-content {
    max-width: 100%;
    padding: 2rem;
}

/* Loading State */
.member-row.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* Empty State */
.members-table tbody tr td[colspan] {
    text-align: center;
    padding: 3rem 2rem;
    color: #9ca3af;
}

.members-table tbody tr td[colspan]::before {
    content: "📋";
    display: block;
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* ============================================================
   User Management Section
   ============================================================ */

.um-header {
    margin-bottom: 2rem;
    text-align: center;
}

.um-header h1 {
    font-size: 40px;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.um-header p {
    color: #666;
    font-size: 1rem;
}

/* Stats grid (reuses .um-stats-grid similar to platform stats) */
.um-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (max-width: 900px) {
    .um-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
    .um-stats-grid { grid-template-columns: 1fr; }
}

/* User Management mobile polish */
@media (max-width: 900px) {
    .um-tabs-container {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    .um-tab {
        flex: 1 1 auto;
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
    }
    .um-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .um-table {
        font-size: 0.8rem;
        min-width: 720px;
    }
    .um-table th,
    .um-table td { padding: 0.55rem 0.5rem; }
    .um-badge,
    .um-platform-badge { font-size: 0.7rem; padding: 1px 6px; }
}

/* Tab bar */
.um-tabs-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.um-tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: #666;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.um-tab:hover { color: #1a1a1a; }

.um-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

/* Tab panels */
.um-tab-panel { display: none; }
.um-tab-panel.active { display: block; }

/* Filters row */
.um-filters {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.um-filters .filter-input { flex: 1; min-width: 200px; }
.um-filters .filter-select { min-width: 160px; }
.um-filters .filter-result {
    margin-left: auto;
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
}

/* Table wrapper */
.um-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    margin-bottom: 1rem;
}

/* Empty / error states */
.um-empty {
    text-align: center;
    padding: 2rem;
    color: #999;
    font-size: 0.9rem;
}

.um-error { color: #dc2626; }

/* Inline code-style account code */
.um-code {
    font-family: monospace;
    font-size: 0.85em;
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 4px;
    color: #374151;
}

/* Badges */
.um-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
}

.um-badge-success  { background: #dcfce7; color: #16a34a; }
.um-badge-warning  { background: #fef9c3; color: #ca8a04; }
.um-badge-muted    { background: #f3f4f6; color: #9ca3af; }
.um-badge-cashier  { background: #dbeafe; color: #1d4ed8; }
.um-badge-retailer { background: #fce7f3; color: #be185d; }
.um-badge-admin    { background: #e0e7ff; color: #4338ca; }

/* Platform badges inside the members table */
.um-platform-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
}

.um-platform-jti4u    { background: #ede9fe; color: #7c3aed; }
.um-platform-achievers { background: #fef3c7; color: #d97706; }

.um-badge-manager { background: #e0f2fe; color: #0369a1; }

/* Dark-mode overrides for badges and table chrome */
body.dark-mode .um-badge-success  { background: #064e3b; color: #6ee7b7; }
body.dark-mode .um-badge-warning  { background: #422006; color: #fcd34d; }
body.dark-mode .um-badge-muted    { background: #374151; color: #d1d5db; }
body.dark-mode .um-badge-cashier  { background: #1e3a8a; color: #93c5fd; }
body.dark-mode .um-badge-retailer { background: #831843; color: #f9a8d4; }
body.dark-mode .um-badge-admin    { background: #312e81; color: #c7d2fe; }
body.dark-mode .um-platform-jti4u     { background: #4c1d95; color: #c4b5fd; }
body.dark-mode .um-platform-achievers { background: #78350f; color: #fcd34d; }
body.dark-mode .um-badge-manager  { background: #0c4a6e; color: #7dd3fc; }
body.dark-mode .um-code {
    background: #1f2937;
    color: #e5e7eb;
}
body.dark-mode .um-table-wrapper { border-color: #374151; }
body.dark-mode .um-empty { color: #9ca3af; }
body.dark-mode .um-error { color: #f87171; }

/* User Management uses a wider page area than the default 1200px so the
   table doesn't have to side-scroll on full-width screens. */
#userManagementSection .page-content {
    max-width: 1600px;
}

/* CSV upload bar */
.um-csv-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.um-csv-hint {
    font-size: 0.8rem;
    color: #6b7280;
    font-style: italic;
}

.btn-sm {
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
}

/* Upload prompt state */
.um-upload-prompt {
    color: #9ca3af;
    font-size: 0.95rem;
    padding: 3rem 1rem !important;
}

/* ── Drill-down view: hide non-essential columns in the Accounts table ────
 * When the user clicks User Management → Accounts → Types (or Provinces /
 * Addresses / Phones), umApplyAccountView() adds .um-col-hidden to every
 * <th>/<td> not in the focused set. */
.members-table th.um-col-hidden,
.members-table td.um-col-hidden {
    display: none !important;
}

/* Small badge in the filter row showing the active drill-down view, plus a
 * "Clear" affordance. Sits next to the search/filter controls. */
.um-view-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(0, 168, 143, 0.12);
    color: var(--brand, #00a88f);
    border: 1px solid rgba(0, 168, 143, 0.4);
    border-radius: 999px;
    padding: 0.2rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    margin-left: 0.5rem;
    transition: background 0.15s ease;
}
.um-view-badge:hover {
    background: rgba(0, 168, 143, 0.2);
}

/* ── Focused (drill-down) view ───────────────────────────────────────────────
 * When a sub-category leaf is active (Accounts → Provinces, Contacts → Email,
 * etc.) the section enters "focused" mode: hide the stat tiles, the tab
 * switcher, and any tab panels that aren't the active one. Only the chosen
 * table — and the in-panel filter row containing the View badge — remain.
 * Clicking the User Management parent (or the "Clear" inside the badge) calls
 * umClearFocusedView() to peel this class off and restore the full page. */
.um-focused-view .um-stats-grid,
.um-focused-view .um-tabs-container {
    display: none !important;
}
.um-focused-view .um-tab-panel { display: none !important; }
.um-focused-view .um-tab-panel.active { display: block !important; }
.um-focused-view .um-header h1 {
    /* Slight tonal change so the user understands they're inside a focused view. */
    color: #4b5563;
}
