/* ============================================
   ChatGPT Team Management Dashboard
   Light theme, polished, modern
   ============================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    color: #0f172a;
    min-height: 100vh;
    line-height: 1.65;
}

code, pre, .mono,
table td, table th {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.88em;
}

a { color: #4f46e5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* --- Login --- */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.04);
    border: 1px solid #e2e8f0;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 6px;
    font-size: 1.5em;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.02em;
}

.login-card .subtitle {
    text-align: center;
    color: #64748b;
    margin-bottom: 32px;
    font-size: 0.9em;
}

.login-card .form-group { margin-bottom: 16px; }

.login-card label {
    display: block;
    margin-bottom: 6px;
    color: #475569;
    font-size: 0.88em;
    font-weight: 500;
}

.login-card input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 1em;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.login-card input[type="password"]:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
    background: #fff;
}

.login-card .login-btn {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
}

.login-error {
    color: #dc2626;
    text-align: center;
    margin-top: 12px;
    font-size: 0.88em;
    min-height: 1.4em;
}

/* --- Header --- */
.app-header {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header h1 {
    font-size: 1.15em;
    color: #0f172a;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* --- Auto-Refresh Toggle --- */
.auto-refresh-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82em;
    color: #64748b;
    cursor: pointer;
    user-select: none;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-switch.on { background: #4f46e5; }

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.toggle-switch.on::after { transform: translateX(16px); }

/* --- Stats Bar --- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 20px 0;
}

.stat-card {
    background: #fff;
    border-radius: 14px;
    padding: 18px 22px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.stat-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.stat-card .stat-value {
    font-size: 1.9em;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.82em;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
}

.stat-detail {
    margin-top: 8px;
    font-size: 0.82em;
    color: #64748b;
    line-height: 1.6;
}

.stat-detail .tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    margin-right: 2px;
}

.stat-card.stat-accounts { border-left: 3px solid #4f46e5; }
.stat-card.stat-accounts .stat-value { color: #4f46e5; }

.stat-card.stat-seats { border-left: 3px solid #059669; }
.stat-card.stat-seats .stat-value { color: #059669; }

.stat-card.stat-invited { border-left: 3px solid #d97706; }
.stat-card.stat-invited .stat-value { color: #d97706; }

/* --- Tabs --- */
.tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 20px;
}

.tab-btn {
    background: none;
    border: none;
    color: #94a3b8;
    padding: 12px 20px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 8px 8px 0 0;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.tab-btn:hover { color: #475569; background: #f8fafc; }

.tab-btn.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
    font-weight: 600;
}

.tab-content {
    display: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.tab-content.active { display: block; opacity: 1; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.88em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #fff;
    white-space: nowrap;
    letter-spacing: 0.01em;
    position: relative;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: #4f46e5; box-shadow: 0 1px 2px rgba(79,70,229,0.2); }
.btn-primary:hover { background: #4338ca; box-shadow: 0 2px 4px rgba(79,70,229,0.25); }
.btn-success { background: #059669; box-shadow: 0 1px 2px rgba(5,150,105,0.2); }
.btn-success:hover { background: #047857; box-shadow: 0 2px 4px rgba(5,150,105,0.25); }
.btn-danger { background: #dc2626; box-shadow: 0 1px 2px rgba(220,38,38,0.2); }
.btn-danger:hover { background: #b91c1c; box-shadow: 0 2px 4px rgba(220,38,38,0.25); }

.btn-outline {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #475569;
}

.btn-outline:hover {
    border-color: #94a3b8;
    background: #f8fafc;
    color: #334155;
}

.btn-sm { padding: 4px 10px; font-size: 0.8em; }

.btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Button loading state */
.btn-loading {
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    top: 50%;
    left: 50%;
    margin-top: -8px;
    margin-left: -8px;
}
.btn-outline.btn-loading::after {
    border-color: rgba(0,0,0,0.1);
    border-top-color: #64748b;
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    overflow: hidden;
}

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

thead th {
    background: #f8fafc;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8em;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1.5px solid #e2e8f0;
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    font-size: 0.85em;
}

tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: #f1f5f9; }
tbody tr:last-child td { border-bottom: none; }

.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
}

.cell-email {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge-pending { background: #f1f5f9; color: #64748b; }
.badge-active, .badge-success { background: #ecfdf5; color: #059669; }
.badge-full { background: #fffbeb; color: #d97706; }
.badge-disabled, .badge-error, .badge-failed { background: #fef2f2; color: #dc2626; }
.badge-invited { background: #eef2ff; color: #4f46e5; }
.badge-locked { background: #fffbeb; color: #d97706; }
.badge-conflict { background: #fefce8; color: #a16207; }

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.open { opacity: 1; }

.modal {
    background: #fff;
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 540px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0,0,0,0.15);
    transform: translateY(8px);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal h2 {
    margin-bottom: 16px;
    font-size: 1.2em;
    color: #0f172a;
    font-weight: 700;
}

.modal .form-group { margin-bottom: 16px; }

.modal label {
    display: block;
    margin-bottom: 6px;
    color: #475569;
    font-size: 0.88em;
    font-weight: 500;
}

.modal textarea,
.modal input[type="text"],
.modal input[type="number"] {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #0f172a;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.88em;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal textarea:focus,
.modal input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.format-toggle {
    display: flex;
    gap: 0;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.format-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: #f8fafc;
    color: #64748b;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.format-btn + .format-btn {
    border-left: 1.5px solid #e2e8f0;
}

.format-btn.active {
    background: #4f46e5;
    color: #fff;
}

.format-btn:hover:not(.active) {
    background: #f1f5f9;
}

/* --- Confirm Dialog --- */
.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.4);
    backdrop-filter: blur(4px);
    z-index: 1100;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.confirm-overlay.open { opacity: 1; }

.confirm-dialog {
    background: #fff;
    border-radius: 16px;
    padding: 28px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 16px 48px rgba(0,0,0,0.15);
    text-align: center;
    transform: translateY(8px);
    transition: transform 0.2s ease;
}
.confirm-overlay.open .confirm-dialog { transform: translateY(0); }

.confirm-dialog h3 {
    font-size: 1.1em;
    color: #0f172a;
    margin-bottom: 8px;
    font-weight: 700;
}

.confirm-dialog p {
    font-size: 0.9em;
    color: #64748b;
    margin-bottom: 24px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* --- Members Table --- */
.members-table {
    width: 100%;
    border-collapse: collapse;
}
.members-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    border-bottom: 2px solid #f1f5f9;
    font-weight: 600;
}
.members-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.88em;
}
.members-table tr:last-child td { border-bottom: none; }
.members-table tr:hover td { background: #f8fafc; }

.member-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78em;
    font-weight: 600;
    line-height: 1.6;
}
.member-tag.tag-admin    { background: #eff6ff; color: #2563eb; }
.member-tag.tag-system   { background: #f0fdf4; color: #16a34a; }
.member-tag.tag-external { background: #fef2f2; color: #dc2626; }
.member-tag.tag-active   { background: #f0fdf4; color: #16a34a; }
.member-tag.tag-pending  { background: #fffbeb; color: #d97706; }

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar select {
    padding: 8px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    font-size: 0.88em;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.toolbar input[type="text"] {
    padding: 8px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    font-size: 0.88em;
    outline: none;
    min-width: 200px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.toolbar input[type="text"]:focus,
.toolbar select:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.toolbar-spacer { flex: 1; }

/* --- Upload Area --- */
.upload-area {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.upload-area h3 {
    margin-bottom: 12px;
    font-size: 1em;
    color: #0f172a;
    font-weight: 600;
}

.upload-area textarea {
    width: 100%;
    min-height: 100px;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #0f172a;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.88em;
    resize: vertical;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.upload-area textarea:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.upload-actions {
    display: flex;
    gap: 8px;
}

/* --- Progress Bar --- */
.progress-container {
    margin-bottom: 20px;
    display: none;
}

.progress-container.visible { display: block; }

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.82em;
    color: #64748b;
    font-weight: 500;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #818cf8);
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-bar-fill.animated::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.35) 50%, transparent 100%);
    animation: progress-shimmer 1.5s infinite;
}

@keyframes progress-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    padding: 12px 0;
}

.pagination .page-info {
    color: #64748b;
    font-size: 0.88em;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 20px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    animation: toast-in 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.toast-out { animation: toast-out 0.3s ease forwards; }
.toast-success { border-left: 4px solid #059669; }
.toast-error { border-left: 4px solid #dc2626; }
.toast-info { border-left: 4px solid #4f46e5; }

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-success .toast-icon { color: #059669; }
.toast-error .toast-icon { color: #dc2626; }
.toast-info .toast-icon { color: #4f46e5; }

.toast .toast-msg { flex: 1; font-size: 0.88em; color: #334155; font-weight: 500; }

.toast .toast-close {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 4px;
}

.toast .toast-close:hover { color: #475569; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* --- Skeleton Loading --- */
.skeleton-row td { padding: 12px 16px; }

.skeleton-cell {
    height: 14px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
    width: 80%;
}
.skeleton-cell-short { width: 40%; }
.skeleton-cell-badge { width: 60px; height: 22px; border-radius: 12px; }

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Misc --- */
.hidden { display: none !important; }
.text-muted { color: #94a3b8; }
.text-center { text-align: center; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.mb-20 { margin-bottom: 20px; }

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive --- */
@media (max-width: 768px) {
    .stats-bar {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .stat-card { padding: 14px 16px; }
    .stat-card .stat-value { font-size: 1.5em; }
    .tab-btn { padding: 10px 14px; font-size: 0.88em; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar input[type="text"] { min-width: unset; width: 100%; }
    .modal { width: 95%; padding: 20px; }
    .btn-group { flex-direction: column; gap: 4px; }
    .btn-group .btn-sm { width: 100%; justify-content: center; }
    thead th, tbody td { padding: 10px 12px; font-size: 0.8em; }
    .cell-email { max-width: 160px; }
}

@media (max-width: 480px) {
    .login-card { padding: 28px 24px; margin: 16px; }
    .app-header h1 { font-size: 1em; }
    .stats-bar { grid-template-columns: 1fr; }
}
