/**
 * User Management Styles for Admin Console — "Sumi-e / Washi" theme.
 * Design tokens (--washi, --ink, --shu, --ai, …) come from admin.css :root.
 * Stat cards (.stat-card / .stat-value / .stat-label) are intentionally styled
 * once, in admin.css, so both dashboards share the same elegant treatment.
 */

/* Stats Grid */
#userStats {
    margin-bottom: 30px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

/* User Controls */
.user-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 18px 20px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
}

#userSearch {
    width: 100%;
    padding: 10px 40px 10px 15px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--sans);
    color: var(--ink);
    background: #fffdf8;
    transition: border-color .15s, box-shadow .15s;
}

#userSearch:focus {
    outline: none;
    border-color: var(--shu);
    box-shadow: 0 0 0 3px var(--shu-tint);
}

.search-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-3);
    pointer-events: none;
}

.controls-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.sort-control {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sort-control label {
    font-size: 14px;
    color: var(--ink-2);
    margin: 0;
}

.sort-control select {
    padding: 8px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--sans);
    color: var(--ink);
    background: #fffdf8;
}

.btn-export {
    background: var(--bamboo);
    color: #f6f8f3;
    border: 1px solid var(--bamboo);
    padding: 10px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--sans);
    font-weight: 600;
    transition: all .2s ease;
}

.btn-export:hover {
    background: #4d6243;
    border-color: #4d6243;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(77,98,67,.22);
}

/* Users Table */
.users-table-container {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th {
    text-align: left;
    padding: 13px 14px;
    background: var(--surface-2);
    color: var(--ink-3);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    border-bottom: 1px solid var(--line-2);
}

.users-table td {
    padding: 14px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink-2);
}

.users-table tr:last-child td { border-bottom: none; }

.users-table tr:hover td {
    background: var(--surface-2);
}

.user-name {
    font-weight: 600;
    color: var(--ink);
}

.user-email {
    color: var(--ai);
    font-weight: 500;
    font-family: var(--mono);
    font-size: 13px;
}

.language-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    color: var(--ink-2);
}

.country-flag {
    font-size: 16px;
}

.conversation-count {
    font-weight: 700;
    font-family: var(--mono);
    color: var(--ink);
    display: inline-block;
    min-width: 30px;
    text-align: center;
}

/* Action Buttons */
.btn-small {
    padding: 6px 13px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--sans);
    font-weight: 600;
    transition: all .2s;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--ai);
    color: #f3f5fa;
    border-color: var(--ai);
}

.btn-primary:hover {
    background: var(--ai-deep);
    border-color: var(--ai-deep);
}

.btn-primary:disabled {
    background: var(--ink-3);
    border-color: var(--ink-3);
    cursor: not-allowed;
    opacity: 0.55;
}

/* Pagination */
.pagination-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background: var(--surface-2);
    border-top: 1px solid var(--line);
    margin-top: 20px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.pagination-info {
    color: var(--ink-3);
    font-size: 13px;
}

.pagination-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}

.pagination-btn {
    padding: 8px 13px;
    border: 1px solid var(--line-2);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 14px;
    transition: all .2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--ink);
    color: var(--washi);
    border-color: var(--ink);
}

.pagination-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--shu);
    color: #fdf6ef;
    border-color: var(--shu);
}

.pagination-controls span {
    padding: 0 8px;
    color: var(--ink-3);
}

/* Loading Overlay */
#userLoadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(32, 28, 23, 0.34);
    backdrop-filter: blur(1.5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

#userLoadingOverlay.active {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--line);
    border-top: 4px solid var(--shu);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* No data state */
.text-center {
    text-align: center;
}

.py-8 {
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.text-gray-500 {
    color: var(--ink-3);
}

/* Responsive */
@media (max-width: 768px) {
    .user-controls {
        flex-direction: column;
    }

    .search-box {
        max-width: 100%;
        width: 100%;
    }

    .controls-right {
        width: 100%;
        justify-content: space-between;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .users-table {
        font-size: 12px;
    }

    .users-table th,
    .users-table td {
        padding: 8px 6px;
    }

    .pagination-section {
        flex-direction: column;
        gap: 15px;
    }
}
