/*
 * Fleet shared components - Apollo-matched buttons, cards, fields, toggles,
 * segmented pills, badges, modals, spinner and toasts. Consumes tokens.css.
 * Layout-specific chrome (top bar, sidebar, viewer) lives in fleet.css.
 */

/* ─── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    min-height: var(--control-height);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--base-font-size);
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--grad-primary);
    border-color: rgba(var(--primary-rgb), 0.3);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--grad-primary-hover);
    border-color: rgba(var(--primary-rgb), 0.5);
    transform: translateY(-1px);
    box-shadow: var(--shadow-btn-hover);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border-light);
    color: var(--text-color);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(var(--primary-rgb), 0.4);
}

.btn-cancel {
    background: linear-gradient(135deg, #2a2a30 0%, #222228 55%, #1c1c22 100%);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-cancel:hover:not(:disabled) {
    border-color: var(--border-light);
}

.btn-danger {
    background: var(--grad-danger);
    border-color: rgba(200, 60, 60, 0.5);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 58, 58, 0.3);
}

.btn-link {
    background: transparent;
    border: none;
    padding: 6px 10px;
    min-height: auto;
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}

.btn-link:hover:not(:disabled) {
    background: transparent;
    color: var(--text-color);
}

.btn-sm {
    padding: 6px 12px;
    min-height: 36px;
    font-size: var(--small-font-size);
}

.btn-block {
    width: 100%;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:focus-visible,
.btn-nav:focus-visible,
.btn-admin:focus-visible,
.rbac-tab:focus-visible,
.demo-filter-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */

.card {
    position: relative;
    background: var(--grad-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
}

.card.is-interactive {
    cursor: pointer;
}

.card.is-interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card-hover);
    border-color: rgba(var(--primary-rgb), 0.4);
}

.panel {
    background: var(--grad-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-panel);
}

/* ─── Form fields ──────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: var(--small-font-size);
    font-weight: 600;
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: #fff;
    font-size: var(--base-font-size);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
}

.form-group select option {
    background: var(--bg-panel);
    color: var(--text-primary);
}

/* Native select popup: keep option list readable on dark theme (Linux/GTK). */
select.globe-org-select,
.rbac-toolbar select,
.form-group select {
    color-scheme: dark;
}

.form-hint {
    font-size: var(--small-font-size);
    color: var(--text-muted);
    margin-top: 6px;
}

.form-row {
    display: flex;
    gap: var(--space-sm);
}

.form-row > * {
    flex: 1 1 0;
    min-width: 0;
}

.form-error {
    color: var(--color-error);
    font-size: var(--small-font-size);
    margin-top: 8px;
    display: none;
}

.form-error.show {
    display: block;
}

/* ─── Toggle switch ────────────────────────────────────────────────────────── */

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    gap: 10px;
    color: var(--text-color);
    font-size: var(--small-font-size);
    -webkit-tap-highlight-color: transparent;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-track {
    width: 42px;
    height: 24px;
    border-radius: 13px;
    background: rgba(100, 100, 110, 0.3);
    border: 1px solid var(--border);
    transition: background 0.2s var(--ease);
    flex-shrink: 0;
    position: relative;
}

.switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s var(--ease);
}

.switch input:checked + .switch-track {
    background: rgba(var(--primary-rgb), 0.5);
    border-color: rgba(var(--primary-rgb), 0.6);
}

.switch input:checked + .switch-track::after {
    transform: translateX(18px);
}

.switch-label {
    line-height: 1.35;
    flex: 1;
    min-width: 0;
}

/* Inside form groups, field label/input rules must not flatten toggle layout */
.form-group label.switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-color);
    width: auto;
    max-width: 100%;
}

.form-group label.switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    box-shadow: none;
}

.form-group label.switch .switch-label {
    line-height: 1.35;
}

.form-group:has(> label.switch) .form-hint {
    margin-top: 8px;
}

/* ─── Segmented pill control ───────────────────────────────────────────────── */

.seg {
    display: inline-flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.25);
    padding: 3px;
    border-radius: var(--radius-lg);
}

.seg-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--small-font-size);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.seg-btn.active {
    background: var(--grad-pill-active);
    color: #fff;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.4);
}

/* ─── Badges / pills ───────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: var(--small-font-size);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success);
    border-color: rgba(34, 197, 94, 0.25);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--color-warning);
    border-color: rgba(245, 158, 11, 0.25);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-error);
    border-color: rgba(239, 68, 68, 0.25);
}

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--color-info);
    border-color: rgba(59, 130, 246, 0.25);
}

.badge-neutral {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    border-color: var(--border);
}

.badge-primary {
    background: rgba(var(--primary-rgb), 0.15);
    color: var(--primary-light);
    border-color: rgba(var(--primary-rgb), 0.3);
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: var(--z-modal);
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-modal);
    padding: 28px;
    width: 480px;
    max-width: 100%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: var(--large-font-size);
    font-weight: 600;
    color: #fff;
    margin-bottom: 20px;
}

.modal p {
    color: var(--text-muted);
    font-size: var(--small-font-size);
    line-height: 1.5;
    margin-bottom: 16px;
}

.modal p strong {
    color: #fff;
    font-weight: 600;
}

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

/* ─── Catalog upload progress ─────────────────────────────────────────────── */

.catalog-upload-progress {
    margin-top: 12px;
}

.catalog-upload-progress-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
}

.catalog-upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary, #a74e9e);
    border-radius: 4px;
    transition: width 0.15s ease;
}

.catalog-upload-progress-label {
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted, rgba(255, 255, 255, 0.65));
}

/* ─── Spinner ──────────────────────────────────────────────────────────────── */

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

.spinner-lg {
    width: 36px;
    height: 36px;
    border-width: 3px;
}

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

/* ─── Toasts ───────────────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: var(--z-toast);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 240px;
    max-width: min(90vw, 460px);
    padding: 12px 18px;
    background: rgba(20, 20, 28, 0.97);
    border: 1px solid var(--border-light);
    border-left-width: 4px;
    border-radius: var(--radius-md);
    color: #fff;
    font-size: var(--small-font-size);
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
    pointer-events: auto;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success { border-left-color: var(--color-success); }
.toast-error { border-left-color: var(--color-error); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-info { border-left-color: var(--color-info); }

/* QA Recordings modal */
.qa-rec-machine {
    color: var(--text-secondary);
    font-size: var(--small-font-size);
    margin: -6px 0 var(--space-md);
}

.qa-rec-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: var(--space-md);
}

.qa-rec-empty {
    color: var(--text-secondary);
    font-size: var(--small-font-size);
    padding: 18px 0;
    text-align: center;
}

.qa-rec-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.qa-rec-info { min-width: 0; }

.qa-rec-title {
    font-weight: 600;
    font-size: var(--base-font-size);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qa-rec-sub {
    color: var(--text-secondary);
    font-size: var(--small-font-size);
}

.qa-rec-links {
    display: inline-flex;
    gap: 8px;
    flex-shrink: 0;
}

.qa-rec-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--small-font-size);
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.qa-rec-link:hover { border-color: var(--primary); }

/* --- Demo / Real sifting filter (shared by demo-filter.js) --- */

.demo-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 7px;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-warning);
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: var(--radius-pill);
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}

.demo-filter {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
}

.demo-filter-label {
    font-size: var(--small-font-size);
    color: var(--text-secondary);
}

.demo-filter-group {
    display: inline-flex;
    padding: 2px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
}

.demo-filter-btn {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--small-font-size);
    font-weight: 600;
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--ease) 0.15s, color var(--ease) 0.15s;
}

.demo-filter-btn:hover { color: var(--text-primary); }

.demo-filter-btn.active {
    background: var(--grad-pill-active);
    color: var(--text-primary);
    box-shadow: var(--shadow-btn-hover);
}

.group-org-filter {
    flex-wrap: wrap;
}

.fw-group-scope .demo-filter-btn,
.rbac-group-scope .demo-filter-btn,
.globe-group-scope .demo-filter-btn {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rbac-group-scope {
    display: flex;
    align-items: center;
}
