/**
 * Admin Interface Styles - ZenFlow Design System
 * Development-only database administration UI
 */

/* Page header layout is now handled by css/header.css (single source of truth) */

/* Container */
.admin-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-xl);
}

/* Controls */
.admin-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.search-input {
    min-width: 300px;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    background: var(--surface);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--background);
}

.status-filter,
.type-filter {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.status-filter:hover,
.type-filter:hover {
    border-color: var(--primary-color);
}

.status-filter:focus,
.type-filter:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Button Styles */
.btn-primary,
.btn-secondary {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--background);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Stats Cards */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transition: all var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--text-primary);
}

/* Table */
.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--background);
}

.admin-table thead {
    background: var(--surface);
    border-bottom: 2px solid var(--border);
}

.admin-table th {
    padding: var(--space-md);
    text-align: left;
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
}

.admin-table th:hover {
    background: rgba(0, 0, 0, 0.02);
}

.admin-table th[data-sort]::after {
    content: ' ⇅';
    opacity: 0.5;
    font-size: var(--font-size-sm);
}

.admin-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background-color var(--transition-fast);
}

.admin-table tbody tr:hover {
    background: var(--surface);
}

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

.admin-table td {
    padding: var(--space-md);
    font-size: var(--font-size-base);
    color: var(--text-primary);
}

/* Invoice Link Styling */
.invoice-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.invoice-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Type and Status Badges */
.type-badge,
.status-badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
}

.type-badge.ticket {
    background-color: #d1fae5;
    color: #065f46;
}

.type-badge.facture {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-badge.pending {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
}

.status-badge.validated {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success-color);
}

.status-badge.finalized {
    background: rgba(6, 182, 212, 0.1);
    color: #0891b2;
}

/* Error and warning status badges */
.status-badge.extraction-failed {
    background: rgba(220, 38, 38, 0.15);
    color: #991b1b;
    font-weight: 700;
    border-left: 3px solid #dc2626;
    padding-left: calc(var(--space-sm) - 3px);
}

.status-badge.partial-extraction {
    background: rgba(251, 146, 60, 0.15);
    color: #92400e;
    font-weight: 600;
    border-left: 3px solid #f97316;
    padding-left: calc(var(--space-sm) - 3px);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

.action-btn {
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    background: var(--background);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.action-btn:hover {
    background: var(--surface);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.action-btn.view {
    border-color: var(--success-color);
    color: var(--success-color);
}

.action-btn.view:hover {
    background: rgba(5, 150, 105, 0.1);
    border-color: var(--success-color);
}

.action-btn.delete {
    border-color: var(--error-color);
    color: var(--error-color);
    min-width: 70px;
    transition: background var(--transition-fast), border var(--transition-fast), transform var(--transition-fast);
    text-align: center;
}

.action-btn.delete:hover {
    background: rgba(220, 38, 38, 0.1);
    border-color: var(--error-color);
}

/* Two-Click Delete Pattern: Confirm Mode with Center Expansion */
.action-btn.delete.confirm-mode {
    background: var(--error-color);
    color: white;
    font-weight: 600;
    border-color: var(--error-color);
    /* Fixed width prevents table layout shift */
    min-width: 70px;
}

.action-btn.delete.confirm-mode:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.modal-content {
    position: relative;
    background: var(--background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1001;
}

.modal-content.modal-large {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    color: var(--text-primary);
    margin: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: var(--font-size-2xl);
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color var(--transition-fast);
    padding: 0;
    width: 32px;
    height: 32px;
}

.modal-close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-top: 1px solid var(--border);
}

/* SQL Console */
.sql-console {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.sql-textarea {
    width: 100%;
    min-height: 150px;
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'Courier New', monospace;
    font-size: var(--font-size-sm);
    resize: vertical;
    background: var(--surface);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.sql-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--background);
}

.sql-results {
    max-height: 400px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    background: var(--surface);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'Courier New', monospace;
    font-size: var(--font-size-sm);
}

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

.sql-results th,
.sql-results td {
    padding: var(--space-sm);
    border: 1px solid var(--border);
    text-align: left;
}

.sql-results th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-secondary);
}

.sql-error {
    color: var(--error-color);
    padding: var(--space-md);
    background: rgba(220, 38, 38, 0.1);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--error-color);
}

.sql-success {
    color: var(--success-color);
    padding: var(--space-md);
    background: rgba(5, 150, 105, 0.1);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--success-color);
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    gap: var(--space-md);
}

.loading-indicator p {
    color: var(--text-secondary);
    font-size: var(--font-size-base);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-secondary);
    font-size: var(--font-size-lg);
}

/* Dev Badge */
.dev-badge {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Responsive */
@media (max-width: 1024px) {
    .admin-container {
        padding: var(--space-md);
    }

    .admin-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        width: 100%;
    }

    .search-input {
        width: 100%;
        min-width: auto;
    }

    .admin-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .admin-container {
        padding: var(--space-sm);
    }

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

    .admin-table {
        font-size: var(--font-size-sm);
    }

    .admin-table th,
    .admin-table td {
        padding: var(--space-sm);
    }

    .action-buttons {
        flex-direction: column;
        gap: var(--space-xs);
    }

    .action-btn.delete.confirm-mode {
        min-width: 80px;
    }
}

/* Workspace Management Styles */
.workspace-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border);
}

.section-header {
    /* Typography controlled by css/header.css (h2 semantic) */
    margin-bottom: var(--space-lg);
}

.section-subtitle {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    margin-top: 0.25rem;
    margin: 0;
}

/* Status Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
}

.badge-active {
    background-color: #d4edda;
    color: #155724;
}

.badge-archived {
    background-color: #fff3cd;
    color: #856404;
}

.badge-superadmin {
    background-color: #dc2626;
    color: white;
}

.badge-admin {
    background-color: #2563eb;
    color: white;
}

/* Workspace-specific action buttons */
.action-btn.archive {
    border-color: #ffc107;
    color: #856404;
}

.action-btn.archive:hover {
    background: #fff3cd;
}

.action-btn.unarchive {
    border-color: #28a745;
    color: #155724;
    min-width: 90px;
}

.action-btn.unarchive:hover {
    background: #d4edda;
}

.action-btn.unarchive.confirm-mode {
    background: #28a745;
    color: white;
    font-weight: 600;
}

/* Metrics Section */
.metrics-section {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.metric-card {
    padding: var(--space-lg);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-align: center;
    transition: all var(--transition-fast);
}

.metric-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--space-xs);
    font-family: 'Monaco', 'Courier New', monospace;
}

.metric-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Print Styles */
@media print {
    .top-nav,
    .footer,
    .admin-controls,
    .action-buttons {
        display: none;
    }

    .table-container {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
