/**
 * FieldOps Design System v1.0
 * Canonical UI tokens and component classes for the FieldOps operating system.
 * See Docs/FieldOpsDesignSystem.md for usage guidelines.
 */

/* ── Design tokens (extend app.css :root) ─────────────────────── */
:root {
    --fo-space-xs: 4px;
    --fo-space-sm: 8px;
    --fo-space-md: 12px;
    --fo-space-lg: 16px;
    --fo-space-xl: 24px;
    --fo-space-2xl: 32px;

    --fo-radius-sm: 8px;
    --fo-radius-md: 12px;
    --fo-radius-lg: 14px;
    --fo-radius-pill: 999px;

    --fo-font-xs: 0.65rem;
    --fo-font-sm: 0.78rem;
    --fo-font-md: 0.875rem;
    --fo-font-lg: 1rem;
    --fo-font-xl: 1.15rem;
    --fo-font-2xl: 1.35rem;

    --fo-font-weight-normal: 500;
    --fo-font-weight-semibold: 600;
    --fo-font-weight-bold: 700;
    --fo-font-weight-extrabold: 800;

    --fo-accent: #3b82f6;
    --fo-accent-soft: rgba(59, 130, 246, 0.15);
    --fo-accent-border: rgba(59, 130, 246, 0.35);
    --fo-accent-text: #93c5fd;

    /* ── Button system tokens (shared by .fo-btn and Bootstrap .btn) ── */
    --fo-btn-radius: var(--fo-radius-sm);
    --fo-btn-font-weight: var(--fo-font-weight-semibold);
    --fo-btn-padding-y: 0.55rem;
    --fo-btn-padding-x: 0.9rem;
    --fo-btn-padding-y-sm: 0.35rem;
    --fo-btn-padding-x-sm: 0.65rem;
    --fo-btn-min-height: 2.25rem;
    --fo-btn-min-height-sm: 1.75rem;
    --fo-btn-focus-ring: #93c5fd;

    /* Primary — darker blue + white text (WCAG AA on dark UI) */
    --fo-btn-primary-bg: #2563eb;
    --fo-btn-primary-bg-hover: #1d4ed8;
    --fo-btn-primary-border: #2563eb;
    --fo-btn-primary-text: #ffffff;

    /* Secondary / outline */
    --fo-btn-secondary-bg: var(--fo-card);
    --fo-btn-secondary-bg-hover: var(--fo-card-hover);
    --fo-btn-secondary-border: var(--fo-border);
    --fo-btn-secondary-border-hover: var(--fo-border-hover);
    --fo-btn-secondary-text: var(--fo-text-primary);

    /* Success / danger / warning */
    --fo-btn-success-bg: #15803d;
    --fo-btn-success-bg-hover: #166534;
    --fo-btn-success-text: #ffffff;
    --fo-btn-danger-bg: #dc2626;
    --fo-btn-danger-bg-hover: #b91c1c;
    --fo-btn-danger-text: #ffffff;
    --fo-btn-warning-bg: #d97706;
    --fo-btn-warning-bg-hover: #b45309;
    --fo-btn-warning-text: #1a0a00;

    /* Ghost / text */
    --fo-btn-ghost-text: var(--fo-text-primary);
    --fo-btn-ghost-hover-bg: rgba(var(--fo-shadow-rgb), 0.25);

    /* Disabled */
    --fo-btn-disabled-opacity: 0.55;

    --fo-purple: #8b5cf6;
    --fo-purple-soft: rgba(139, 92, 246, 0.15);

    --fo-duration-fast: 0.15s;
    --fo-duration-normal: 0.3s;
    --fo-ease: ease;

    --fo-z-panel: 1040;
    --fo-z-modal: 1050;
    --fo-z-toast: 1080;
}

/* ── Page shell ───────────────────────────────────────────────── */
.fo-page {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
    background: var(--fo-bg);
    color: var(--fo-text-primary);
}

.fo-page-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: var(--fo-space-lg);
}

/* Shell .content-area is the primary scrollport — avoid nested page scrolling. */
.content-area > .fo-page > .fo-page-body,
.content-area > .fo-page .fo-page-body.fo-page-body--shell-scroll {
    overflow: visible;
    min-height: auto;
}

.fo-page--flush .fo-page-body {
    padding: 0;
}

.fo-page--embedded {
    min-height: auto;
}

/* Lightweight page header for non-command-center pages */
.fo-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--fo-space-md);
    flex-wrap: wrap;
    margin-bottom: var(--fo-space-lg);
}

.fo-page-header-copy {
    min-width: 0;
    flex: 1 1 16rem;
}

.fo-page-title {
    margin: 0;
    font-size: clamp(1.35rem, 2vw, 1.75rem);
    font-weight: var(--fo-font-weight-extrabold);
    line-height: 1.2;
}

.fo-page-subtitle {
    margin: 0.35rem 0 0;
    color: var(--fo-text-tertiary);
    font-size: var(--fo-font-sm);
}

.fo-page-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--fo-space-sm);
}

.fo-panel-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    min-height: 8rem;
    padding: var(--fo-space-lg);
    color: var(--fo-text-tertiary);
    font-size: var(--fo-font-sm);
}

.fo-panel-loading__spinner {
    width: 1.15rem;
    height: 1.15rem;
    border: 2px solid var(--fo-border);
    border-top-color: var(--fo-accent-text, #60a5fa);
    border-radius: 50%;
    animation: fo-spin 0.7s linear infinite;
}

@keyframes fo-spin {
    to { transform: rotate(360deg); }
}

/* ── Workspace header ─────────────────────────────────────────── */
.fo-workspace-header {
    flex-shrink: 0;
    padding: var(--fo-space-md) var(--fo-space-lg);
    border-bottom: 1px solid var(--fo-border);
    background: var(--fo-bg-alt, #172033);
}

.fo-workspace-header-row {
    display: flex;
    align-items: center;
    gap: var(--fo-space-md);
    flex-wrap: wrap;
}

.fo-workspace-title {
    margin: 0;
    font-size: var(--fo-font-xl);
    font-weight: var(--fo-font-weight-bold);
    color: var(--fo-text-primary);
    display: flex;
    align-items: center;
    gap: var(--fo-space-sm);
}

.fo-workspace-subtitle {
    margin: 0;
    font-size: var(--fo-font-sm);
    color: var(--fo-text-tertiary);
}

/* ── Action bar ───────────────────────────────────────────────── */
.fo-action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fo-space-md);
    padding: var(--fo-space-sm) var(--fo-space-lg);
    border-bottom: 1px solid var(--fo-border);
    background: var(--fo-bg-alt, #172033);
    flex-wrap: wrap;
}

.fo-action-bar-actions {
    display: flex;
    align-items: center;
    gap: var(--fo-space-sm);
    margin-left: auto;
}

/* ── KPI card ─────────────────────────────────────────────────── */
.fo-kpi-strip {
    display: flex;
    gap: var(--fo-space-md);
    padding: var(--fo-space-md) var(--fo-space-lg);
    overflow-x: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--fo-border);
    background: rgba(15, 23, 42, 0.85);
    scrollbar-width: thin;
}

.fo-kpi-card {
    flex: 0 0 auto;
    min-width: 168px;
    max-width: 200px;
    padding: var(--fo-space-md);
    border-radius: var(--fo-radius-md);
    border: 1px solid var(--fo-border);
    background: linear-gradient(145deg, var(--fo-card) 0%, var(--fo-bg-alt, #172033) 100%);
}

.fo-kpi-card--pulse {
    animation: fo-pulse 2s ease-in-out infinite;
}

.fo-kpi-card--compact {
    min-width: 120px;
    max-width: 160px;
    padding: var(--fo-space-sm) var(--fo-space-md);
}

.fo-kpi-card--compact .fo-kpi-value {
    font-size: var(--fo-font-xl);
}

.fo-kpi-card--active {
    border-color: var(--fo-accent-border);
    box-shadow: 0 0 0 1px var(--fo-accent-soft);
}

.fo-kpi-card--warn {
    border-color: rgba(var(--fo-yellow-rgb), 0.45);
    background: linear-gradient(
        145deg,
        rgba(var(--fo-yellow-rgb), 0.12) 0%,
        var(--fo-bg-alt) 100%
    );
}

.fo-kpi-card--warn .fo-kpi-value {
    color: var(--fo-yellow);
}

.fo-kpi-card--danger {
    border-color: rgba(var(--fo-red-rgb), 0.45);
    background: linear-gradient(
        145deg,
        rgba(var(--fo-red-rgb), 0.12) 0%,
        var(--fo-bg-alt) 100%
    );
}

.fo-kpi-card--danger .fo-kpi-value {
    color: var(--fo-red);
}

.fo-kpi-card--success {
    border-color: rgba(var(--fo-green-rgb), 0.4);
    background: linear-gradient(
        145deg,
        rgba(var(--fo-green-rgb), 0.1) 0%,
        var(--fo-bg-alt) 100%
    );
}

.fo-kpi-card--success .fo-kpi-value {
    color: var(--fo-green);
}

.fo-kpi-card--info {
    border-color: var(--fo-accent-border);
    background: linear-gradient(
        145deg,
        var(--fo-accent-soft) 0%,
        var(--fo-bg-alt) 100%
    );
}

.fo-kpi-card--info .fo-kpi-value {
    color: var(--fo-accent-text);
}

button.fo-kpi-card:focus-visible,
a.fo-kpi-card:focus-visible {
    outline: 2px solid var(--fo-accent);
    outline-offset: 2px;
}

.fo-kpi-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--fo-space-sm);
    margin-bottom: var(--fo-space-xs);
}

.fo-kpi-label {
    font-size: var(--fo-font-xs);
    font-weight: var(--fo-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fo-text-tertiary);
}

.fo-kpi-value {
    font-size: var(--fo-font-2xl);
    font-weight: var(--fo-font-weight-extrabold);
    color: var(--fo-text-primary);
    line-height: 1.1;
}

.fo-kpi-sub {
    font-size: var(--fo-font-sm);
    color: var(--fo-text-tertiary);
    margin-top: 2px;
}

.fo-kpi-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--fo-space-sm);
    margin-top: var(--fo-space-sm);
}

.fo-kpi-action {
    border: none;
    background: transparent;
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-font-weight-semibold);
    cursor: pointer;
    padding: 0;
}

.fo-kpi-action--primary { color: var(--fo-accent-text); }
.fo-kpi-action--secondary { color: var(--fo-text-tertiary); }

.fo-kpi-action:focus-visible {
    outline: 2px solid var(--fo-accent);
    outline-offset: 2px;
    border-radius: var(--fo-radius-sm);
}

.fo-kpi-updated {
    margin-left: auto;
    font-size: var(--fo-font-xs);
    color: var(--fo-text-tertiary);
}

/* ── Workspace buttons (.fo-btn) ──────────────────────────────── */
/* Anchor buttons must beat global `a { color: ... !important }` from app.css */
.fo-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fo-space-xs);
    padding: var(--fo-btn-padding-y) var(--fo-btn-padding-x);
    min-height: var(--fo-btn-min-height);
    border-radius: var(--fo-btn-radius);
    border: 1px solid var(--fo-btn-secondary-border);
    background: transparent;
    color: var(--fo-btn-secondary-text) !important;
    text-decoration: none !important;
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-btn-font-weight);
    line-height: 1.2;
    cursor: pointer;
    transition: background var(--fo-duration-fast) var(--fo-ease),
                border-color var(--fo-duration-fast) var(--fo-ease),
                color var(--fo-duration-fast) var(--fo-ease),
                box-shadow var(--fo-duration-fast) var(--fo-ease);
}

.fo-btn--sm,
.fo-btn.fo-btn--sm {
    padding: var(--fo-btn-padding-y-sm) var(--fo-btn-padding-x-sm);
    min-height: var(--fo-btn-min-height-sm);
    font-size: var(--fo-font-xs);
    gap: 0.3rem;
}

.fo-btn--icon {
    width: var(--fo-btn-min-height);
    min-width: var(--fo-btn-min-height);
    padding: 0;
}

.fo-btn--icon.fo-btn--sm {
    width: var(--fo-btn-min-height-sm);
    min-width: var(--fo-btn-min-height-sm);
}

.fo-btn:focus-visible {
    outline: 2px solid var(--fo-btn-focus-ring);
    outline-offset: 2px;
}

.fo-btn:disabled,
.fo-btn[disabled],
.fo-btn.is-disabled {
    opacity: var(--fo-btn-disabled-opacity);
    cursor: not-allowed;
    pointer-events: none;
}

.fo-btn--primary {
    background: var(--fo-btn-primary-bg);
    border-color: var(--fo-btn-primary-border);
    color: var(--fo-btn-primary-text) !important;
}

.fo-btn--primary:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-primary-bg-hover);
    border-color: var(--fo-btn-primary-bg-hover);
    color: var(--fo-btn-primary-text) !important;
}

.fo-btn--secondary {
    background: var(--fo-btn-secondary-bg);
    border-color: var(--fo-btn-secondary-border);
    color: var(--fo-btn-secondary-text) !important;
}

.fo-btn--secondary:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-secondary-bg-hover);
    border-color: var(--fo-btn-secondary-border-hover);
    color: var(--fo-btn-secondary-text) !important;
}

.fo-btn--success {
    background: var(--fo-btn-success-bg);
    border-color: var(--fo-btn-success-bg);
    color: var(--fo-btn-success-text) !important;
}

.fo-btn--success:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-success-bg-hover);
    border-color: var(--fo-btn-success-bg-hover);
    color: var(--fo-btn-success-text) !important;
}

.fo-btn--danger {
    background: var(--fo-btn-danger-bg);
    border-color: var(--fo-btn-danger-bg);
    color: var(--fo-btn-danger-text) !important;
}

.fo-btn--danger:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-danger-bg-hover);
    border-color: var(--fo-btn-danger-bg-hover);
    color: var(--fo-btn-danger-text) !important;
}

.fo-btn--warn,
.fo-btn--warning {
    background: var(--fo-btn-warning-bg);
    border-color: var(--fo-btn-warning-bg);
    color: var(--fo-btn-warning-text) !important;
}

.fo-btn--warn:hover:not(:disabled):not([disabled]),
.fo-btn--warning:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-warning-bg-hover);
    border-color: var(--fo-btn-warning-bg-hover);
    color: var(--fo-btn-warning-text) !important;
}

.fo-btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--fo-btn-ghost-text) !important;
}

.fo-btn--ghost:hover:not(:disabled):not([disabled]) {
    background: var(--fo-btn-ghost-hover-bg);
    border-color: var(--fo-btn-secondary-border);
    color: var(--fo-btn-ghost-text) !important;
}

/* Soft warn retained for legacy call sites that used translucent chips */
.fo-btn--warn-soft {
    background: rgba(var(--fo-yellow-rgb), 0.15);
    border-color: rgba(var(--fo-yellow-rgb), 0.35);
    color: var(--fo-yellow) !important;
}

.fo-btn--warn-soft:hover:not(:disabled):not([disabled]) {
    background: rgba(var(--fo-yellow-rgb), 0.25);
    color: var(--fo-yellow) !important;
}

/* ── Stat tiles (dark-theme-safe metric blocks) ───────────────── */
.fo-stat-tile {
    padding: var(--fo-space-md);
    border-radius: var(--fo-radius-md);
    border: 1px solid var(--fo-border);
    background: var(--fo-card);
    color: var(--fo-text-primary);
}

.fo-stat-tile--compact {
    padding: var(--fo-space-sm) var(--fo-space-md);
}

.fo-stat-tile--warn {
    border-color: rgba(var(--fo-yellow-rgb), 0.4);
    background: rgba(var(--fo-yellow-rgb), 0.08);
}

.fo-stat-tile--danger {
    border-color: rgba(var(--fo-red-rgb), 0.4);
    background: rgba(var(--fo-red-rgb), 0.08);
}

.fo-stat-tile--success {
    border-color: rgba(var(--fo-green-rgb), 0.4);
    background: rgba(var(--fo-green-rgb), 0.08);
}

.fo-stat-tile:focus-visible {
    outline: 2px solid var(--fo-accent);
    outline-offset: 2px;
}

/* ── Data card ────────────────────────────────────────────────── */
.fo-card {
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-lg);
    background: var(--fo-card);
    overflow: hidden;
    color: var(--fo-text-primary);
}

.fo-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--fo-space-md);
    padding: var(--fo-space-md) var(--fo-space-lg);
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.fo-card-title-row {
    display: flex;
    align-items: center;
    gap: var(--fo-space-sm);
    flex-wrap: wrap;
}

.fo-card-title {
    margin: 0;
    font-size: var(--fo-font-lg);
    font-weight: var(--fo-font-weight-bold);
    color: var(--fo-text-primary);
}

.fo-card-body {
    padding: var(--fo-space-md) var(--fo-space-lg);
}

.fo-card-footer {
    display: flex;
    align-items: center;
    gap: var(--fo-space-md);
    padding: var(--fo-space-sm) var(--fo-space-lg) var(--fo-space-md);
    border-top: 1px solid rgba(51, 65, 85, 0.5);
}

.fo-card-action {
    border: none;
    background: transparent;
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-font-weight-semibold);
    cursor: pointer;
    padding: 0;
}

.fo-card-action--primary { color: var(--fo-accent-text); }
.fo-card-action--secondary { color: var(--fo-text-tertiary); }

.fo-card-updated {
    margin-left: auto;
    font-size: var(--fo-font-xs);
    color: var(--fo-text-tertiary);
}

/* ── Workspace panel (Assets & similar) ───────────────────────── */
.fo-panel {
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-lg);
    background: var(--fo-card);
    padding: var(--fo-space-lg);
    color: var(--fo-text-primary);
}

.fo-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--fo-space-md);
    margin-bottom: var(--fo-space-md);
}

.fo-panel-header h2 {
    margin: 0;
    font-size: var(--fo-font-lg, 1.1rem);
    font-weight: var(--fo-font-weight-semibold, 600);
    color: var(--fo-text-primary);
}

.fo-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--fo-space-lg);
}

/* Data rows inside cards */
.fo-data-rows {
    display: flex;
    flex-direction: column;
    gap: var(--fo-space-xs);
}

.fo-data-rows--compact {
    gap: 2px;
}

.fo-data-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--fo-space-md);
    font-size: var(--fo-font-md);
    flex-wrap: wrap;
}

.fo-data-row--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

.fo-data-row--stacked .fo-data-value {
    text-align: left;
}

.fo-data-label {
    color: var(--fo-text-secondary);
}

.fo-data-value {
    font-weight: var(--fo-font-weight-semibold);
    text-align: right;
    white-space: nowrap;
}

.fo-data-hint {
    font-size: var(--fo-font-sm);
    color: var(--fo-text-tertiary);
    font-style: italic;
}

.fo-data-divider {
    margin: var(--fo-space-md) 0;
    border: 0;
    border-top: 1px solid var(--fo-border);
    opacity: 0.35;
}

.fo-data-summary .fo-data-row {
    font-size: 0.9375rem;
}

/* ── Badges / status chips ────────────────────────────────────── */
.fo-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--fo-radius-pill);
    font-size: var(--fo-font-xs);
    font-weight: var(--fo-font-weight-bold);
    line-height: 1.4;
    white-space: nowrap;
}

.fo-badge--ok,
.fo-badge--success {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
}

.fo-badge--warn,
.fo-badge--warning {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.fo-badge--crit,
.fo-badge--danger {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.fo-badge--info {
    background: var(--fo-accent-soft);
    color: var(--fo-accent-text);
}

.fo-badge--muted {
    background: rgba(100, 116, 139, 0.2);
    color: var(--fo-text-secondary);
}

.fo-badge--neutral {
    background: rgba(100, 116, 139, 0.25);
    color: var(--fo-text-secondary);
}

/* Phase 56A — subtle outlined Beta pill (neutral gray, no warning colors) */
.fo-beta-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.1rem 0.45rem;
    margin-left: 0.35rem;
    border: 1px solid #94a3b8;
    border-radius: 999px;
    background: transparent;
    color: #64748b;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.2;
    vertical-align: middle;
    white-space: nowrap;
}

h1 .fo-beta-badge,
.h3 .fo-beta-badge,
.pr-card-name .fo-beta-badge,
.fo-workspace-tab .fo-beta-badge {
    margin-left: 0.4rem;
}

/* ── Empty state ──────────────────────────────────────────────── */
.fo-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--fo-space-xl) var(--fo-space-lg);
    color: var(--fo-text-secondary);
}

.fo-empty-state-icon {
    font-size: 2.5rem;
    color: var(--fo-text-tertiary);
    margin-bottom: var(--fo-space-md);
}

.fo-empty-state-title {
    margin: 0 0 var(--fo-space-sm);
    font-size: var(--fo-font-md);
    font-weight: var(--fo-font-weight-semibold);
    color: var(--fo-text-secondary);
}

.fo-empty-state-text {
    margin: 0;
    font-size: var(--fo-font-sm);
    color: var(--fo-text-tertiary);
    max-width: 28rem;
}

.fo-empty-state--compact {
    padding: var(--fo-space-md) var(--fo-space-sm);
}

/* ── Skeleton loaders ─────────────────────────────────────────── */
.fo-skeleton {
    background: linear-gradient(
        90deg,
        rgba(51, 65, 85, 0.4) 0%,
        rgba(71, 85, 105, 0.6) 50%,
        rgba(51, 65, 85, 0.4) 100%
    );
    background-size: 200% 100%;
    animation: fo-shimmer 1.2s ease-in-out infinite;
    border-radius: var(--fo-radius-sm);
}

.fo-skeleton--text {
    height: 0.875rem;
    width: 100%;
}

.fo-skeleton--title {
    height: 1.25rem;
    width: 60%;
}

.fo-skeleton--kpi {
    height: 2rem;
    width: 40%;
}

.fo-skeleton-block {
    display: flex;
    flex-direction: column;
    gap: var(--fo-space-sm);
    padding: var(--fo-space-lg);
}

/* ── Tables (dark OS style) ───────────────────────────────────── */
.fo-table-wrap {
    overflow-x: auto;
}

.fo-table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.fo-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: var(--fo-font-md);
    color: var(--fo-text-primary);
}

.fo-table thead th {
    padding: var(--fo-space-sm) var(--fo-space-md);
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fo-text-tertiary);
    border-bottom: 1px solid var(--fo-border);
    background: rgba(15, 23, 42, 0.5);
}

.fo-table tbody td {
    padding: var(--fo-space-sm) var(--fo-space-md);
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    vertical-align: middle;
}

.fo-table tbody tr:hover td {
    background: rgba(59, 130, 246, 0.05);
}

.fo-table tbody tr.fo-table-row--muted {
    opacity: 0.75;
}

/* ── Mobile cards ─────────────────────────────────────────────── */
.fo-mobile-card {
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-md);
    padding: var(--fo-space-md);
    background: rgba(30, 41, 59, 0.5);
}

.fo-mobile-card--done {
    opacity: 0.8;
}

.fo-mobile-card-list {
    display: flex;
    flex-direction: column;
    gap: var(--fo-space-md);
}

/* ── Side panel / drawer ──────────────────────────────────────── */
.fo-side-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: calc(var(--fo-z-panel) - 1);
}

.fo-side-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(420px, 100vw);
    background: var(--fo-bg-alt, #172033);
    border-left: 1px solid var(--fo-border);
    z-index: var(--fo-z-panel);
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
}

.fo-side-panel-header {
    padding: var(--fo-space-lg);
    border-bottom: 1px solid var(--fo-border);
}

.fo-side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--fo-space-lg);
}

/* ── Timeline ─────────────────────────────────────────────────── */
.fo-timeline {
    position: relative;
    padding-left: var(--fo-space-xl);
}

.fo-timeline::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--fo-border);
}

.fo-timeline-item {
    position: relative;
    padding-bottom: var(--fo-space-lg);
}

.fo-timeline-item::before {
    content: "";
    position: absolute;
    left: calc(-1 * var(--fo-space-xl) + 3px);
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--fo-accent);
    border: 2px solid var(--fo-bg-alt, #172033);
}

.fo-timeline-title {
    font-size: var(--fo-font-md);
    font-weight: var(--fo-font-weight-semibold);
    margin: 0 0 2px;
}

.fo-timeline-meta {
    font-size: var(--fo-font-sm);
    color: var(--fo-text-tertiary);
}

/* ── Copilot card ─────────────────────────────────────────────── */
.fo-copilot-card {
    border: 1px solid var(--fo-accent-border);
    border-radius: var(--fo-radius-lg);
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.08) 0%, var(--fo-card) 100%);
    padding: var(--fo-space-md) var(--fo-space-lg);
}

.fo-copilot-card-header {
    display: flex;
    align-items: center;
    gap: var(--fo-space-sm);
    margin-bottom: var(--fo-space-sm);
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-font-weight-semibold);
    color: var(--fo-accent-text);
}

.fo-copilot-card-body {
    font-size: var(--fo-font-md);
    color: var(--fo-text-primary);
}

.fo-copilot-card-action {
    margin-top: var(--fo-space-sm);
    font-size: var(--fo-font-sm);
    font-weight: var(--fo-font-weight-semibold);
    color: var(--fo-accent-text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ── Quick actions ────────────────────────────────────────────── */
.fo-quick-action {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: var(--fo-space-xs);
    padding: var(--fo-space-sm);
    border-radius: var(--fo-radius-md);
    border: 1px solid var(--fo-border);
    background: var(--fo-card);
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-xs);
    font-weight: var(--fo-font-weight-semibold);
    cursor: pointer;
    min-width: 64px;
    text-align: center;
}

.fo-quick-action i {
    font-size: 1.1rem;
}

.fo-quick-action:hover:not(:disabled) {
    background: var(--fo-card-hover);
    color: var(--fo-text-primary);
}

.fo-quick-action--primary {
    border-color: var(--fo-accent-border);
    background: var(--fo-accent-soft);
    color: var(--fo-accent-text);
}

/* ── Alerts (inline, not toast) ───────────────────────────────── */
.fo-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 16px;
    border-radius: 12px;
    font-size: var(--fo-font-md, 0.95rem);
    line-height: 1.5;
    border: 1px solid transparent;
}

.fo-alert-icon {
    flex-shrink: 0;
    margin-top: 0.1rem;
    font-size: 1.1rem;
}

.fo-alert-body {
    flex: 1;
    min-width: 0;
}

.fo-alert-body ul,
.fo-alert ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fo-alert-body li + li,
.fo-alert li + li {
    margin-top: 0.35rem;
}

/* Primary naming (auth + new surfaces) */
.fo-alert-danger,
.fo-alert--danger {
    background: #2b1619;
    border-color: #d9534f;
    color: #ffd7d7;
}

.fo-alert-danger .fo-alert-icon,
.fo-alert--danger .fo-alert-icon {
    color: #d9534f;
}

.fo-alert-danger .fo-alert-secondary,
.fo-alert--danger .fo-alert-secondary,
.fo-alert-danger small,
.fo-alert--danger small {
    color: #f5bcbc;
}

.fo-alert-warning,
.fo-alert--warning {
    background: #2d2613;
    border-color: #f0ad4e;
    color: #ffe8b3;
}

.fo-alert-warning .fo-alert-icon,
.fo-alert--warning .fo-alert-icon {
    color: #f0ad4e;
}

.fo-alert-success,
.fo-alert--success {
    background: #14301f;
    border-color: #2ecc71;
    color: #d6ffe5;
}

.fo-alert-success .fo-alert-icon,
.fo-alert--success .fo-alert-icon {
    color: #2ecc71;
}

.fo-alert-info,
.fo-alert--info {
    background: #16263b;
    border-color: #4aa3ff;
    color: #d8ecff;
}

.fo-alert-info .fo-alert-icon,
.fo-alert--info .fo-alert-icon {
    color: #4aa3ff;
}

.fo-alert-danger a,
.fo-alert--danger a,
.fo-alert-warning a,
.fo-alert--warning a,
.fo-alert-success a,
.fo-alert--success a,
.fo-alert-info a,
.fo-alert--info a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.fo-alert-danger a:hover,
.fo-alert--danger a:hover,
.fo-alert-warning a:hover,
.fo-alert--warning a:hover,
.fo-alert-success a:hover,
.fo-alert--success a:hover,
.fo-alert-info a:hover,
.fo-alert--info a:hover {
    opacity: 0.9;
}

/* ── Modal + code (RC Bucket 1) ───────────────────────────────── */
.fo-modal-content {
    background: var(--fo-card);
    color: var(--fo-text-primary);
    border: 1px solid var(--fo-border);
}

.fo-modal-content .modal-header,
.fo-modal-content .modal-footer {
    border-color: var(--fo-border);
}

.fo-code-block {
    background: var(--fo-bg-alt, #172033);
    color: var(--fo-text-primary);
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-sm);
    padding: 0.5rem;
    font-size: 0.875em;
    overflow-x: auto;
}

/* ── Loading center ───────────────────────────────────────────── */
.fo-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--fo-space-md);
    padding: var(--fo-space-xl);
    color: var(--fo-text-secondary);
}

/* ── Animations ───────────────────────────────────────────────── */
@keyframes fo-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fo-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes fo-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
    50%      { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.15); }
}

.fo-animate-in {
    animation: fo-fade-in var(--fo-duration-normal) var(--fo-ease) backwards;
}

/* KPI card status chips reuse fo-badge */
.fo-kpi-card .fo-badge {
    font-size: var(--fo-font-xs);
    padding: 2px 6px;
}
