/**
 * EASME System View Styles
 * 
 * Consolidated styles for the System view (hosts, runtime, deployment).
 * Migrated from embedded <style> blocks in system.php + modal.css
 * 
 * Structure:
 *   1. Base section styling
 *   2. Hosts table
 *   3. Unified form (host add/edit)
 *   4. Modals (validate, runtime, deploy)
 *   5. Status indicators & badges
 *   6. SSH keys summary
 */

/* ============================================================================
   1. BASE SECTION
   ============================================================================ */

.system h2 {
    margin-bottom: 1rem;
}

/* ============================================================================
   2. HOSTS TABLE
   ============================================================================ */

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

.system td,
.system th {
    padding: 0.5rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
}

.system th {
    background: var(--gray-100, #f3f4f6);
    font-size: 0.85em;
    font-weight: 600;
    color: var(--gray-600, #4b5563);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.system th.th-actions {
    text-align: right;
    width: 120px;
}

.system td.actions {
    text-align: right;
    white-space: nowrap;
}

.system code {
    background: var(--gray-100, #f3f4f6);
    padding: 0.1rem 0.35rem;
    font-size: 0.85em;
    border-radius: 0.25rem;
    font-family: 'SF Mono', Consolas, monospace;
}

/* Local host row highlight */
tr.host-local {
    background: rgba(22, 163, 74, 0.04);
}

tr.host-local td:first-child b {
    color: var(--success, #16a34a);
}

/* ============================================================================
   3. UNIFIED FORM (Host Add/Edit)
   ============================================================================ */

.system .unified-form {
    background: var(--gray-50, #f9fafb);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-top: 0.75rem;
}

.system .form-section {
    margin-bottom: 0.75rem;
}

.system .form-subsection {
    background: white;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 0.25rem;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.system .section-label {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--gray-600, #4b5563);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.system .subsection-label {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--gray-500, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

/* Form grid layout */
.system .form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

@media (max-width: 768px) {
    .system .form-grid-3 {
        grid-template-columns: 1fr;
    }
}

.system .form-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.system .form-field.span-2 {
    grid-column: span 2;
}

.system .form-field.span-3 {
    grid-column: span 3;
}

.system .form-field label {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--gray-600, #4b5563);
}

.system .form-field input[type="text"],
.system .form-field input[type="number"],
.system .form-field select,
.system .form-field textarea {
    padding: 0.08em 0.375em;
    border: 1px solid var(--gray-300, #d1d5db);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.system .form-field input:focus,
.system .form-field select:focus,
.system .form-field textarea:focus {
    outline: none;
    border-color: var(--primary, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.system .form-field textarea {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.8125rem;
    resize: vertical;
}

.system .form-field select {
    cursor: pointer;
}

/* Form warnings/hints */
.system .field-warning {
    font-size: 0.8em;
    color: var(--color-warning);
    margin-top: 0.25rem;
    padding: 0.375rem 0.5rem;
    background: var(--color-warning-lt);
    border-radius: 0.25rem;
    border: 1px solid rgba(191,117,24,0.35);
}

.system .field-warning a {
    color: var(--primary, #2563eb);
    text-decoration: underline;
}

.system .field-hint {
    font-size: 0.75em;
    color: var(--gray-500, #6b7280);
    margin-top: 0.25rem;
}

/* Form actions */
.system .form-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    margin-top: 0.75rem;
}

.system .form-status {
    font-size: 0.85em;
    margin-left: auto;
}

.system .form-status.error {
    color: var(--danger, #dc2626);
}

.system .form-status.success {
    color: var(--success, #16a34a);
}

/* Optional section toggle */
.system .optional-section {
    margin-bottom: 0;
}

.system .toggle-btn {
    background: none;
    border: none;
    padding: 0.25rem 0;
    font-size: 0.85em;
    color: var(--gray-600, #4b5563);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.system .toggle-btn:hover {
    color: var(--gray-800, #1f2937);
}

/* File upload label */
.system .file-label {
    display: inline;
    font-size: 0.85em;
    color: var(--primary, #2563eb);
    cursor: pointer;
    margin-left: 0.5rem;
}

.system .file-label:hover {
    text-decoration: underline;
}

.system .file-label input[type="file"] {
    display: none;
}

/* Checkbox label styling */
.system .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    cursor: pointer;
}

.system .checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* ============================================================================
   4. MODALS (Validate, Runtime, Deploy)
   ============================================================================ */

/* Modal overlay - dark theme */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* Modal content - dark theme */
.modal-overlay .modal-content {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    color: #e5e7eb;
}

.modal-overlay h3 {
    margin: 0 0 0.625rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #333;
    font-size: 1rem;
    color: #f3f4f6;
}

.modal-overlay h3 .muted {
    font-weight: normal;
    font-size: 0.85em;
    color: #9ca3af;
}

.modal-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* --- Validation Modal --- */
.validate-modal {
    max-width: 600px;
}

.validate-summary {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background: #252525;
    border-radius: 0.375rem;
    border: 1px solid #333;
}

.validate-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: #222;
    border-radius: 0.375rem;
    border: 1px solid #333;
}

.validate-list > li {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #333;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-start;
}

.validate-list > li:last-child {
    border-bottom: none;
}

.val-icon {
    width: 1.25em;
    text-align: center;
    flex-shrink: 0;
}

.val-ok { color: var(--color-success); }
.val-warn { color: var(--color-warning); }
.val-fail { color: var(--color-danger); }
.val-skip { color: var(--text-muted); }
.val-pending { color: var(--text-muted); }
.val-running { color: var(--color-info); }

/* tiny inline spinner for running steps */
.spinner-tiny {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border: 2px solid #3b82f6;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.val-details {
    width: 100%;
    margin: 0.25rem 0 0 1.5rem;
    padding: 0;
    font-size: 0.85em;
    list-style: none;
}

.val-details li {
    color: #9ca3af;
}

/* Validation spinner/progress */
.validate-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: #9ca3af;
}

.validate-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
}

.validate-step.pending { color: var(--text-muted); }
.validate-step.running { color: var(--color-info); }
.validate-step.ok { color: var(--color-success); }
.validate-step.warn { color: var(--color-warning); }
.validate-step.fail { color: var(--color-danger); }

.step-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #333;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Runtime Config Modal --- */
.runtime-modal {
    max-width: 700px;
}

.runtime-section {
    margin-bottom: 0.625rem;
}

.runtime-section > label {
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 500;
    font-size: 0.85em;
    color: #e5e7eb;
}

.runtime-section label.sub {
    font-size: 0.8em;
    color: #9ca3af;
    font-weight: normal;
}

/* Modal inputs inherit global sizing, just style colors */
.runtime-input {
    width: 100%;
    padding: 0.08em 0.375em;
    background: #222;
    border: 1px solid #444;
    border-radius: 0.25rem;
    color: #e5e7eb;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.875rem;
}

.runtime-input:focus {
    outline: none;
    border-color: #666;
}

.runtime-input:disabled {
    background: #181818;
    color: #6b7280;
    cursor: not-allowed;
    border-color: #333;
}

.runtime-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.runtime-grid > div {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

/* --- Deploy Modal --- */
.deploy-modal {
    max-width: 650px;
}

.deploy-section {
    margin-bottom: 0.5rem;
}

.deploy-section > label {
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 500;
    font-size: 0.85em;
    color: #e5e7eb;
}

/* Modal inputs inherit global sizing, just style colors */
.deploy-input {
    width: 100%;
    padding: 0.08em 0.375em;
    background: #222;
    border: 1px solid #444;
    border-radius: 0.25rem;
    color: #e5e7eb;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.875rem;
}

.deploy-input:focus {
    outline: none;
    border-color: #666;
}

/* Field hints in dark modals */
.deploy-section .field-hint,
.runtime-section .field-hint {
    font-size: 0.7em;
    color: #6b7280;
    margin-top: 0.125rem;
}

/* Compact inline checkboxes */
.deploy-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem 1rem;
}

.deploy-checkboxes .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: #e5e7eb;
    font-size: 0.85em;
    white-space: nowrap;
}

.deploy-checkboxes .checkbox-label .muted {
    color: #6b7280;
    font-size: 0.9em;
}

/* Deploy progress - taller status box */
.deploy-progress {
    background: #111;
    border: 1px solid #333;
    border-radius: 0.375rem;
    margin-top: 0.75rem;
}

.progress-header {
    padding: 0.375rem 0.625rem;
    border-bottom: 1px solid #333;
    font-weight: 500;
    font-size: 0.85em;
    color: #9ca3af;
}

.progress-log {
    padding: 0.5rem 0.625rem;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.8125rem;
    min-height: 180px;
    max-height: 280px;
    overflow-y: auto;
    white-space: pre-wrap;
    color: #9ca3af;
}

.progress-log .log-ok { color: var(--color-success); }
.progress-log .log-warn { color: var(--color-warning); }
.progress-log .log-fail { color: var(--color-danger); }
.progress-log .log-info { color: var(--color-info); }

/* ============================================================================
   5. STATUS INDICATORS
   ============================================================================ */

/* Status cell — avoid display:flex on <td> (breaks table-cell alignment) */
.status-cell {
    white-space: nowrap;
}

.status-cell > * {
    vertical-align: middle;
}

.status-cell > * + * {
    margin-left: 0.25rem;
}

/* Status keyword text */
.status-keyword {
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500, #6b7280);
}

/* Refresh spinner — animated rotation on the refresh button */
.btn-refreshing {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0.9;
}

.btn-refreshing::before {
    content: '';
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    border: 2px solid var(--color-info, #3b82f6);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Row-level busy state — dims non-active controls during async ops */
tr.row-busy td.actions button:not(.btn-refreshing) {
    opacity: 0.35;
    pointer-events: none;
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============================================================================
   6. SSH KEYS SUMMARY
   ============================================================================ */

.system .keys-summary {
    margin-top: 1.25rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.system .keys-label {
    color: var(--gray-600, #4b5563);
    font-weight: 500;
}

.system .key-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--gray-100, #f3f4f6);
    padding: 0.25rem 0.625rem;
    border-radius: 0.25rem;
    font-size: 0.8125rem;
    font-family: 'SF Mono', Consolas, monospace;
}

.system .key-default {
    color: var(--color-warning);
}

/* ============================================================================
   7. UTILITIES
   ============================================================================ */

.system .muted {
    color: var(--gray-500, #6b7280);
}

.system .tiny {
    font-size: 0.75em;
}
