/* FidesIA — Admin Dashboard */

body { background: var(--bg-primary); color: var(--text-primary); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }

/* Header */
.admin-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 10;
}
.admin-back {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}
.admin-back:hover { color: var(--accent-hover); }
.admin-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
}
.admin-period {
    display: flex;
    gap: 4px;
}
.period-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.period-btn:hover { border-color: var(--accent); color: var(--accent); }
.period-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Tabs */
.admin-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    padding: 0 24px;
    background: var(--bg-primary);
    position: sticky;
    top: 53px;
    z-index: 9;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.admin-tab {
    padding: 12px 18px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: all var(--transition);
    font-family: inherit;
}
.admin-tab:hover { color: var(--text-secondary); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Main content */
.admin-main {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    overflow-x: hidden;
}
.admin-section { animation: adminFadeIn 0.2s ease; }
@keyframes adminFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Loading */
.admin-loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 14px 16px;
    border: 1px solid var(--border-light);
}
.kpi-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}
.kpi-value.accent { color: var(--accent); }

/* Section titles */
.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 24px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}
.section-title:first-child { margin-top: 0; }

/* Chart containers */
.chart-box {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
}
.chart-container {
    position: relative;
    height: 280px;
}
.chart-container.tall { height: 350px; }

/* Granularity selector */
.granularity-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}
.gran-btn {
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.gran-btn:hover { border-color: var(--gold); color: var(--gold); }
.gran-btn.active { background: var(--gold); color: white; border-color: var(--gold); }

/* Tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 16px;
}
.admin-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}
.admin-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}
.admin-table tr:hover td { background: var(--bg-secondary); }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Two column layout */
.admin-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

/* AI Analysis */
.ai-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.ai-btn {
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
    font-family: inherit;
}
.ai-btn:hover { background: var(--accent-hover); }
.ai-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.ai-check input { accent-color: var(--accent); }
.ai-result {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    font-size: 14px;
    line-height: 1.7;
    border: 1px solid var(--border-light);
}
.ai-result h1, .ai-result h2, .ai-result h3 {
    color: var(--accent);
    margin: 16px 0 8px;
}
.ai-result h1:first-child, .ai-result h2:first-child, .ai-result h3:first-child { margin-top: 0; }
.ai-result ul, .ai-result ol { margin-left: 20px; margin-bottom: 12px; }
.ai-result strong { color: var(--text-primary); }
.ai-result p { margin-bottom: 10px; }

/* Archive button */
.ai-btn-archive { background: #2c5f2d; }
.ai-btn-archive:hover { background: #3a7a3c; }

/* Follow-up input */
.ai-followup-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.ai-followup-input:focus { border-color: var(--accent); }
.ai-followup-input:disabled { opacity: 0.5; }

/* AI History list */
.ai-history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ai-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    color: var(--text-secondary);
    width: 100%;
}
.ai-history-item:hover { border-color: var(--accent); color: var(--accent); }
.ai-history-item.active { border-color: var(--accent); background: var(--accent); color: white; }
.ai-history-item.active .ai-history-meta { color: rgba(255,255,255,0.7); }
.ai-history-date {
    font-weight: 600;
    white-space: nowrap;
    min-width: 120px;
}
.ai-history-meta {
    color: var(--text-muted);
    font-size: 12px;
}

/* Reconnection stats inline */
.stats-inline {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.stat-item {
    font-size: 13px;
    color: var(--text-secondary);
}
.stat-item strong {
    display: block;
    font-size: 20px;
    color: var(--text-primary);
    font-weight: 700;
}

/* Management tab */
.mgmt-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.mgmt-search-input {
    flex: 1;
    min-width: 200px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.mgmt-search-input:focus { border-color: var(--accent); }
.mgmt-sort {
    display: flex;
    gap: 4px;
}
.mgmt-sort .period-btn { font-size: 11px; padding: 5px 10px; }

/* Scrollable table wrapper (generic) */
.admin-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
/* Management table: wide (8 cols + action buttons) */
.mgmt-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}
.mgmt-table-scroll .admin-table {
    min-width: 800px;
}

/* Action buttons per user row */
.mgmt-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.mgmt-btn {
    padding: 4px 10px;
    border: none;
    border-radius: var(--radius);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    color: white;
    font-family: inherit;
    transition: opacity var(--transition);
    white-space: nowrap;
}
.mgmt-btn:hover { opacity: 0.85; }
.mgmt-btn-contact { background: #2b6cb0; }
.mgmt-btn-export { background: #2c7a3a; }
.mgmt-btn-reset { background: #c47f17; }
.mgmt-btn-delconv { background: #8b3a3a; }
.mgmt-btn-danger { background: #c0392b; }
.mgmt-btn-modo { background: #6b46c1; }
.mgmt-btn-modo-active { background: #553c9a; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.3); }

/* Moderation link in header */
.admin-moderation-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius);
    transition: all var(--transition);
}
.admin-moderation-link:hover { color: var(--accent); background: var(--bg-secondary); }
.admin-moderation-link svg { flex-shrink: 0; }
.moderation-badge {
    background: #c0392b;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 9px;
    padding: 0 5px;
    position: absolute;
    top: -2px;
    right: -4px;
}

/* Newsletter textarea */
.newsletter-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: vertical;
    min-height: 160px;
    box-sizing: border-box;
    transition: border-color var(--transition);
}
.newsletter-textarea:focus { border-color: var(--accent); }

/* Confirmation overlay */
.mgmt-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: adminFadeIn 0.15s ease;
}
.mgmt-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}
.mgmt-overlay-box {
    position: relative;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.mgmt-overlay-box h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: var(--text-primary);
}
.mgmt-overlay-box p {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.mgmt-overlay-box input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    margin-bottom: 12px;
    box-sizing: border-box;
}
.mgmt-overlay-box input[type="password"]:focus { border-color: var(--accent); }
.mgmt-overlay-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.mgmt-overlay-actions button {
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity var(--transition);
}
.mgmt-overlay-actions button:hover { opacity: 0.85; }
.mgmt-overlay-actions .mgmt-cancel {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.mgmt-overlay-actions .mgmt-confirm {
    background: #c0392b;
    color: white;
}
.mgmt-overlay-actions .mgmt-confirm-safe {
    background: var(--accent);
    color: white;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-header { flex-wrap: wrap; padding: 12px 16px; gap: 8px; position: static; }
    .admin-title { font-size: 16px; }
    .admin-main { padding: 16px; }
    .admin-tabs { padding: 0 12px; position: static; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-row { grid-template-columns: 1fr; }
    .chart-container { height: 220px; }
    .mgmt-controls { gap: 8px; }
    .mgmt-search-input { min-width: 0; }
    .mgmt-actions { gap: 3px; }
    .mgmt-btn { font-size: 10px; padding: 3px 7px; }
    .admin-table td, .admin-table th { padding: 6px 8px; font-size: 12px; }
    .admin-moderation-link { padding: 4px 6px; }
    .newsletter-textarea { min-height: 120px; }
    .newsletter-form .mgmt-search-input { min-width: 0; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .kpi-value { font-size: 20px; }
    .mgmt-actions { flex-direction: column; }
    .mgmt-btn { width: 100%; text-align: center; }
    .admin-period { width: 100%; justify-content: center; }
}
