/* =========================================================================
Admin Control Panel — System
   =========================================================================

Extracted from the Leptos `<style>` blocks that used to sit inside these
components. Those blocks only existed in the DOM while their component was
mounted, which made cross-panel styling depend on what happened to be on
screen, and made the same rule easy to declare twice with different values.

Sources:
     - apps/frontend-admin/src/ui/panels/admin/system/
   ========================================================================= */

/* ---- system.rs ---- */
    .system-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: var(--space-6);
        margin-top: var(--space-8);
    }
    .health-card {
        background: color-mix(in srgb, var(--text-color) 5%, transparent);
        border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
        border-radius: var(--radius-lg);
        padding: var(--space-6);
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        position: relative;
    }
    .status-indicator {
        width: 12px;
        height: 12px;
        border-radius: var(--radius-round);
        background: var(--danger-color);
        margin-bottom: var(--space-4);
        box-shadow: 0 0 10px var(--danger-border);
        transition: all 0.3s ease;
    }
    .status-indicator.online {
        background: var(--success-color);
        box-shadow: 0 0 10px var(--success-border);
    }
    .status-indicator.warning {
        background: var(--warning-color);
        box-shadow: 0 0 10px var(--warning-border);
    }
    .analytics-row {
        display: flex;
        flex-direction: column;
        gap: var(--space-8);
        margin-top: var(--space-8);
    }
    .chart-box {
        min-height: 450px;
        width: 100%;
    }
    .api-status-list {
        background: color-mix(in srgb, var(--text-color) 5%, transparent);
        border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
        border-radius: var(--radius-lg);
        padding: var(--space-6);
    }
    .api-status-list h3 {
        margin: 0 0 var(--space-6) 0;
        font-size: 0.9rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    /* Two columns (or more) once there is the width for them. */
    .api-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
        column-gap: var(--space-8);
        row-gap: var(--space-4);
    }
    .api-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: var(--space-3);
        border-bottom: 1px solid color-mix(in srgb, var(--text-color) 5%, transparent);
    }
    .api-item:last-child {
        border-bottom: none;
    }
    .api-info {
        display: flex;
        flex-direction: column;
        flex: 1;
    }
    .api-top {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        margin-bottom: var(--space-1);
    }
    .api-name {
        font-weight: 500;
        font-size: 1rem;
    }
    .status-tag {
        font-size: 0.7rem;
        padding: var(--space-px) var(--space-1-5);
        border-radius: var(--radius-sm);
        background: var(--danger-bg);
        color: var(--danger-color);
        text-transform: uppercase;
        font-weight: 600;
    }
    .status-tag.online {
        background: var(--success-bg);
        color: var(--success-color);
    }
    .status-tag.warning {
        background: var(--warning-bg);
        color: var(--warning-color);
    }
    .api-meta {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: var(--space-1) var(--space-4);
        padding-right: var(--space-6);
    }
    .api-calls {
        font-size: 0.75rem;
        color: var(--text-secondary);
    }
    .api-meta .api-timestamp { margin-left: auto; }
    .api-latency {
        font-size: 0.85rem;
        color: var(--success-color);
        font-family: monospace;
        font-weight: 600;
    }
    .api-timestamp {
        font-size: 0.75rem;
        color: var(--text-muted);
    }
    .status-dot {
        width: 10px;
        height: 10px;
        border-radius: var(--radius-round);
        background: var(--danger-color);
        box-shadow: 0 0 8px var(--danger-border);
    }
    .status-dot.online {
        background: var(--success-color);
        box-shadow: 0 0 8px var(--success-border);
    }
    .status-dot.warning {
        background: var(--warning-color);
        box-shadow: 0 0 8px var(--warning-border);
    }
    .error-state {
        padding: var(--space-8);
        text-align: center;
        color: var(--danger-color);
        background: var(--danger-bg);
        border-radius: var(--radius-lg);
        margin-top: var(--space-8);
    }
    .capacity-card {
        background: color-mix(in srgb, var(--text-color) 5%, transparent);
        border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
        border-radius: var(--radius-lg);
        padding: var(--space-6);
    }
    .capacity-card h3 {
        margin: 0 0 var(--space-4) 0;
        font-size: 0.9rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    .capacity-metrics {
        display: flex;
        align-items: baseline;
        gap: var(--space-1);
        margin-bottom: var(--space-4);
    }
    .capacity-metrics .used {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--button-primary-text);
    }
    .capacity-metrics .divider {
        color: var(--chart-cat-14);
    }
    .capacity-metrics .total {
        font-weight: 600;
        color: var(--text-muted);
    }
    .capacity-metrics .percentage {
        margin-left: auto;
        font-weight: 600;
        color: var(--color-accent);
    }
    .progress-bar-bg {
        height: 12px;
        background: color-mix(in srgb, var(--text-color) 5%, transparent);
        border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
        border-radius: var(--radius-md);
        overflow: hidden;
        margin-bottom: var(--space-3);
    }
    .progress-bar-fill {
        height: 100%;
        background: var(--accent-color);
        border-radius: var(--radius-md);
        transition: width 0.5s ease;
    }
    .progress-bar-fill.warning {
        background: var(--warning-color);
    }
    .progress-bar-fill.danger {
        background: var(--danger-color);
    }
    .capacity-footer {
        display: flex;
        justify-content: space-between;
        font-size: 0.8rem;
        color: var(--text-muted);
    }
    .capacity-footer .warning { color: var(--warning-color); font-weight: 600; }
    .capacity-footer .danger { color: var(--danger-color); font-weight: 700; }

    @media (max-width: 768px) {
        .system-grid {
            gap: var(--space-3);
            margin-top: var(--space-4);
            grid-template-columns: 1fr 1fr;
        }
        .health-card {
            padding: var(--space-4);
            border-radius: var(--radius-xl);
        }
        .status-indicator {
            margin-bottom: var(--space-2);
            width: 10px;
            height: 10px;
        }
        .health-card h3 {
            font-size: 0.9rem;
        }
        .status-text {
            font-size: 0.9rem;
        }
        .meta {
            font-size: 0.75rem;
        }
        .analytics-row {
            gap: var(--space-4);
            margin-top: var(--space-4);
        }
        .api-status-list, .capacity-card {
            padding: var(--space-4);
        }
        .api-item {
            padding-bottom: var(--space-2);
        }
        .api-name {
            font-size: 0.9rem;
        }
        .api-latency {
            font-size: 0.75rem;
        }
        .api-timestamp {
            font-size: 0.7rem;
        }
        .chart-box {
            min-height: 350px;
        }
        .capacity-metrics .used {
            font-size: 1.25rem;
        }
    }

    @media (max-width: 480px) {
        .system-grid {
            grid-template-columns: 1fr;
        }
        .health-card {
            flex-direction: row;
            align-items: center;
            text-align: left;
            gap: var(--space-3);
            justify-content: flex-start;
        }
        .status-indicator {
            margin-bottom: 0;
        }
    }

.memory-section { margin-top: var(--space-10); }
.mem-header { border-top: 1px solid color-mix(in srgb, var(--text-color) 8%, transparent); padding-top: var(--space-8); }
.mem-overview { display: flex; flex-direction: column; gap: var(--space-6); margin-top: var(--space-6); }
.mem-top-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: var(--space-6);
    align-items: stretch;
}
.mem-cache-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
}
.mem-stat-card { justify-content: center; }
.mem-rss-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}
.mem-rss-head h3 { margin: 0; }
.mem-rss-bar { position: relative; }
.mem-threshold-marker {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: var(--warning-color);
    box-shadow: 0 0 4px var(--warning-color);
}
.mem-unavailable { color: var(--text-muted); font-size: 0.9rem; margin: var(--space-2) 0 var(--space-4) 0; }
.mem-kv-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: var(--space-1-5) 0;
    border-bottom: 1px solid color-mix(in srgb, var(--text-color) 5%, transparent);
}
.mem-kv-row:last-child { border-bottom: none; }
.mem-kv-val { color: var(--button-primary-text); font-family: monospace; font-weight: 600; }

/* Overview stays compact; diagnostic tables mount only in their selected view. */
.system-detail { min-width: 0; }
.system-detail-stack { display: flex; flex-direction: column; gap: var(--space-6); }
.system-panel .memory-section { margin-top: 0; }
.system-panel .mem-header { border-top: 0; padding-top: 0; }
.system-overview-heading {
    display: flex; justify-content: space-between; align-items: start;
    flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-5);
}
.system-overview-heading h3 { margin: 0; }
.system-uptime { color: var(--text-muted); font-size: 0.85rem; }
.system-health-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: var(--space-4);
}
.system-health-widget {
    display: flex; flex-direction: column; gap: var(--space-3);
    min-width: 0; padding: var(--space-5); text-align: left;
    background: var(--panel-bg-opaque); color: var(--text-color);
    border: 1px solid var(--border-primary); border-radius: var(--radius-lg);
    cursor: pointer; font: inherit;
}
.system-health-widget:hover { border-color: var(--accent-color); background: var(--bg-tertiary); }
.system-health-widget:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
.system-widget-heading, .system-widget-footer {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: var(--space-2);
}
.system-widget-heading { font-weight: 600; }
.system-widget-value { font-size: 1.55rem; line-height: 1.25; overflow-wrap: anywhere; }
.system-widget-detail, .system-widget-footer { font-size: 0.85rem; color: var(--text-muted); }
.system-widget-footer { margin-top: auto; padding-top: var(--space-2); }
.system-stale { color: var(--warning-color); }
.system-panel .status-tag.unknown { color: var(--text-muted); background: var(--bg-tertiary); }
@media (max-width: 768px) {
    .mem-top-row { grid-template-columns: 1fr; }
    .mem-cache-row { grid-template-columns: 1fr; }
}


.system-panel .status-dot.unknown { background: var(--text-muted); box-shadow: none; }

.gates-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }

.user-account-id { font-family: monospace; font-size: 0.72rem; color: var(--text-muted); overflow-wrap: anywhere; }
.user-status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.admin-users-container .user-row-actions { display: grid; grid-template-columns: repeat(3, max-content); gap: var(--space-2); }

/* ── Jobs (System → Jobs) ─────────────────────────────────────────────
   Grouped by when each job runs; the description is clamped to one line
   and opens out while the row is hovered or holds focus. A running job's
   progress sits in its own row underneath it. */
.jobs-table .jobs-group-row th {
    padding-top: var(--space-4);
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted); text-align: left;
    border-bottom: 1px solid var(--border-primary);
}
.jobs-table .jobs-name-cell { min-width: 16rem; max-width: 30rem; }
.jobs-title { font-weight: 600; color: var(--text-primary); }
.jobs-key { font-size: 0.72rem; color: var(--text-muted); }
.jobs-description {
    margin: var(--space-1) 0 0; font-size: 0.8rem; color: var(--text-secondary);
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.jobs-row:hover .jobs-description,
.jobs-row:focus-within .jobs-description { -webkit-line-clamp: unset; }
.jobs-schedule { white-space: nowrap; color: var(--text-secondary); font-size: 0.85rem; }
.jobs-overdue { margin-top: var(--space-1); display: inline-block; }
.jobs-error { margin-top: var(--space-1); color: var(--danger-color); font-size: 0.78rem; overflow-wrap: anywhere; }
.jobs-actions { white-space: nowrap; }
.jobs-actions .btn + .btn { margin-left: var(--space-1-5); }
.jobs-actions .btn { display: inline-flex; align-items: center; gap: var(--space-1); }
.jobs-actions .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.jobs-actions-head { text-align: left; }
.jobs-row.running-row td:first-child { box-shadow: inset 3px 0 0 var(--accent-color); }
.jobs-progress-row td { padding-top: 0; border-top: none; }
.jobs-summary { font-size: 0.8rem; color: var(--text-secondary); overflow-wrap: anywhere; }
.status-badge.neutral { background: var(--bg-tertiary); color: var(--text-muted); }

.job-progress { display: flex; flex-direction: column; gap: var(--space-1-5); padding: var(--space-1) 0 var(--space-2); }
.job-progress-head { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; }
.job-progress-head .sync-spinner {
    width: 0.9em; height: 0.9em; border-radius: var(--radius-round);
    border: 2px solid var(--border-primary); border-top-color: var(--accent-color);
    animation: spin 0.75s linear infinite;
}
.job-progress-phase { color: var(--text-primary); }
.job-progress-count { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.job-progress-bar {
    position: relative; height: 0.4rem; overflow: hidden;
    background: var(--bg-tertiary); border-radius: var(--radius-pill);
}
.job-progress-fill { height: 100%; background: var(--accent-color); border-radius: inherit; transition: width 0.3s; }
/* No count reported: a sweep says it is working without claiming a share done. */
.job-progress-bar.indeterminate .job-progress-fill {
    position: absolute; inset: 0 auto 0 0; width: 30%;
    animation: job-progress-sweep 1.4s ease-in-out infinite;
}
@keyframes job-progress-sweep {
    from { transform: translateX(-100%); }
    to { transform: translateX(340%); }
}
@media (prefers-reduced-motion: reduce) {
    .job-progress-bar.indeterminate .job-progress-fill { animation: none; width: 100%; opacity: 0.5; }
}
