/* ============================================================================
   an-viz-ui Design System
   CSS custom property-based styling for DOM components.
   Override --avui-* variables to theme.
   ============================================================================ */

/* === Defaults (Cyber Nebula — operator-companion default) ===
 *
 * Mirrors the `cyber_nebula` preset in
 * `core/an-hitlr/docs/design/tokens.toml` and
 * `core/an-hitlr/app-ios/App/Theme/AnTheme.swift`. Token names align
 * across iOS Swift (camelCase) and CSS (kebab-case) — same names mean
 * the same thing on every platform.
 *
 * Override `--avui-*` to re-skin. Themes shipped in
 * `crates/an-viz-ui/src/theme/mod.rs` (`Theme::cyber_nebula()`,
 * `Theme::cyber_nebula_violet()`, `Theme::cyber_punk_patriot()`,
 * `Theme::minimal_dark()`, `Theme::light()`).
 */
:root {
    --avui-bg: #08071A;
    --avui-bg-panel: rgba(17, 16, 43, 0.88);
    --avui-bg-card: #11102B;
    --avui-text: rgba(245, 245, 255, 0.94);
    --avui-text-muted: rgba(245, 245, 255, 0.55);
    --avui-accent: #3CEFEE;
    --avui-accent-hover: #5EFAEA;
    --avui-accent-secondary: #A765FF;
    --avui-danger: #FF5C7A;
    --avui-success: #4ADE80;
    --avui-warning: #F9C74F;
    --avui-border: rgba(167, 101, 255, 0.16);
    --avui-border-focus: rgba(60, 239, 238, 0.55);
    --avui-glow-accent: rgba(60, 239, 238, 0.42);
    --avui-glow-accent-secondary: rgba(167, 101, 255, 0.40);
    --avui-glass-fill: rgba(17, 16, 43, 0.72);
    --avui-glass-border: rgba(60, 239, 238, 0.22);
    --avui-scope-marketplace: #C9B48A;
    --avui-radius: 8px;
    --avui-radius-lg: 14px;
    --avui-font: system-ui, 'SF Pro Text', sans-serif;
    --avui-font-mono: 'JetBrains Mono', 'SF Mono', 'IBM Plex Mono', monospace;
    --avui-font-size: 15px;
    --avui-transition: 0.22s cubic-bezier(0.32, 0.72, 0.0, 1.0);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; }

/* === Buttons === */
.avui-btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border-radius: var(--avui-radius);
    font-family: var(--avui-font); font-size: var(--avui-font-size);
    cursor: pointer; transition: all var(--avui-transition);
    border: 1px solid var(--avui-border); color: var(--avui-text);
    text-decoration: none; gap: 6px; white-space: nowrap;
}
.avui-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.avui-btn-primary {
    background: var(--avui-accent); border-color: var(--avui-accent); color: #fff;
}
.avui-btn-primary:hover:not(:disabled) { background: var(--avui-accent-hover); }
.avui-btn-secondary {
    background: transparent; border-color: var(--avui-accent); color: var(--avui-accent);
}
.avui-btn-secondary:hover:not(:disabled) { background: rgba(59, 130, 246, 0.1); }
.avui-btn-icon {
    width: 36px; height: 36px; padding: 0;
    background: transparent; border-color: transparent; font-size: 16px;
}
.avui-btn-icon:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }
.avui-btn-group { display: flex; gap: 8px; align-items: center; }

/* === Card === */
.avui-card {
    background: var(--avui-bg-card); border: 1px solid var(--avui-border);
    border-radius: var(--avui-radius-lg); overflow: hidden;
}
.avui-card-header {
    padding: 12px 16px; border-bottom: 1px solid var(--avui-border);
    background: rgba(255, 255, 255, 0.02);
}
.avui-card-title {
    margin: 0; font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--avui-accent);
}
.avui-card-body { padding: 16px; }

/* === Modal === */
.avui-modal-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
}
.avui-modal {
    background: var(--avui-bg-card); border: 1px solid var(--avui-border);
    border-radius: var(--avui-radius-lg); min-width: 400px; max-width: 90vw;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.avui-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--avui-border);
}
.avui-modal-title { margin: 0; font-size: 16px; color: var(--avui-text); }
.avui-modal-close {
    background: none; border: none; color: var(--avui-text-muted);
    font-size: 18px; cursor: pointer; padding: 4px;
}
.avui-modal-close:hover { color: var(--avui-text); }
.avui-modal-body { padding: 20px; color: var(--avui-text); }
.avui-modal-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 16px 20px; border-top: 1px solid var(--avui-border);
}

/* === Tabs === */
.avui-tabs-header {
    display: flex; gap: 2px; border-bottom: 1px solid var(--avui-border);
    padding: 0 8px;
}
.avui-tab-btn {
    padding: 8px 16px; border: none; background: transparent;
    color: var(--avui-text-muted); font-family: var(--avui-font);
    font-size: var(--avui-font-size); cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--avui-transition);
}
.avui-tab-btn:hover { color: var(--avui-text); }
.avui-tab-btn.active {
    color: var(--avui-accent); border-bottom-color: var(--avui-accent);
}
.avui-tab-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
    border-radius: 9px; font-size: 10px; font-weight: 600;
    background: var(--avui-accent); color: #fff;
}
.avui-tabs-content { padding: 16px; }

/* === Loading / Error / Empty === */
.avui-loading-spinner {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 40px; gap: 16px;
    color: var(--avui-text-muted);
}
.avui-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--avui-border);
    border-top-color: var(--avui-accent);
    border-radius: 50%;
    animation: avui-spin 0.8s linear infinite;
}
@keyframes avui-spin { to { transform: rotate(360deg); } }
.avui-loading-skeleton { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.avui-skeleton-line {
    height: 14px; border-radius: 4px;
    background: linear-gradient(90deg, var(--avui-border) 25%, rgba(255,255,255,0.06) 50%, var(--avui-border) 75%);
    background-size: 200% 100%;
    animation: avui-shimmer 1.5s ease-in-out infinite;
}
@keyframes avui-shimmer { to { background-position: -200% 0; } }
.avui-error-state, .avui-empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 40px; gap: 12px; text-align: center;
}
.avui-error-icon, .avui-empty-icon { font-size: 2rem; }
.avui-error-message { color: var(--avui-danger); }
.avui-empty-message { color: var(--avui-text-muted); }
.avui-empty-title { color: var(--avui-text); margin: 0; }

/* === Grid === */
.avui-grid-item {
    background: var(--avui-bg-card); border: 1px solid var(--avui-border);
    border-radius: var(--avui-radius); overflow: hidden;
    transition: border-color var(--avui-transition);
}
.avui-grid-item:hover { border-color: var(--avui-accent); }

/* === Carousel === */
.avui-carousel { position: relative; }
.avui-carousel-track::-webkit-scrollbar { display: none; }
.avui-carousel-track { scrollbar-width: none; }
.avui-carousel-arrow {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--avui-bg-panel); border: 1px solid var(--avui-border);
    color: var(--avui-text); font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 10; backdrop-filter: blur(8px);
}
.avui-carousel-arrow:hover { border-color: var(--avui-accent); }
.avui-carousel-arrow-left { left: 8px; }
.avui-carousel-arrow-right { right: 8px; }

/* === Forms === */
.avui-input-wrapper { display: flex; flex-direction: column; gap: 6px; }
.avui-input-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--avui-text-muted);
}
.avui-input, .avui-textarea, .avui-select {
    padding: 8px 12px; border-radius: var(--avui-radius);
    border: 1px solid var(--avui-border); background: rgba(255,255,255,0.04);
    color: var(--avui-text); font-family: var(--avui-font);
    font-size: var(--avui-font-size);
    transition: border-color var(--avui-transition);
}
.avui-input:focus, .avui-textarea:focus, .avui-select:focus {
    outline: none; border-color: var(--avui-border-focus);
}
.avui-input:disabled, .avui-textarea:disabled, .avui-select:disabled {
    opacity: 0.4; cursor: not-allowed;
}
.avui-checkbox {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    color: var(--avui-text); font-size: var(--avui-font-size);
}
.avui-form-field { display: flex; flex-direction: column; gap: 6px; }
.avui-form-label { font-size: 12px; color: var(--avui-text-muted); font-weight: 500; }
.avui-form-error { font-size: 11px; color: var(--avui-danger); margin: 0; }
.avui-required { color: var(--avui-danger); margin-left: 2px; }
.avui-form-group {
    border: 1px solid var(--avui-border); border-radius: var(--avui-radius);
    padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.avui-form-legend {
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--avui-accent); padding: 0 8px;
}

/* === Layout === */
.avui-page {
    display: flex; flex-direction: column; min-height: 100vh;
    background: var(--avui-bg); color: var(--avui-text);
    font-family: var(--avui-font); font-size: var(--avui-font-size);
}
.avui-page-header {
    flex-shrink: 0; border-bottom: 1px solid var(--avui-border);
    background: var(--avui-bg-panel);
}
.avui-page-main { flex: 1; overflow-y: auto; }
.avui-page-footer {
    flex-shrink: 0; border-top: 1px solid var(--avui-border);
    background: var(--avui-bg-panel);
}
.avui-sidebar {
    flex-shrink: 0; border-right: 1px solid var(--avui-border);
    background: var(--avui-bg-panel); transition: width var(--avui-transition);
    overflow: hidden;
}
.avui-sidebar-right { border-right: none; border-left: 1px solid var(--avui-border); }
.avui-sidebar-content { padding: 16px; min-width: 280px; }
.avui-panel { background: var(--avui-bg-card); }
.avui-panel-bordered { border: 1px solid var(--avui-border); border-radius: var(--avui-radius-lg); }
.avui-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--avui-border);
}
.avui-panel-title {
    margin: 0; font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--avui-accent);
}
.avui-panel-actions { display: flex; gap: 4px; }
.avui-panel-body { padding: 16px; }

/* === Links === */
.avui-link { color: var(--avui-accent); text-decoration: none; }
.avui-link:hover { color: var(--avui-accent-hover); text-decoration: underline; }

/* === Section notebook cell === */
.avui-section-cell { position: relative; }
.avui-section-cell-content { margin-bottom: 0.75rem; }
.avui-section-cell-interaction {
    border: 1px solid var(--avui-border);
    border-radius: var(--avui-radius-lg);
    background: color-mix(in srgb, var(--avui-bg-panel) 88%, transparent);
    padding: 0.75rem 0.85rem 0.9rem;
}
.avui-section-cell-toolbar {
    display: flex; gap: 0.5rem; justify-content: flex-end; margin-bottom: 0.4rem;
}
.avui-section-cell-clear,
.avui-section-cell-unbind {
    background: transparent; border: none; color: var(--avui-text-muted);
    font-family: var(--avui-font-mono); font-size: 10px; letter-spacing: 0.06em;
    text-transform: uppercase; cursor: pointer; padding: 0;
}
.avui-section-cell-clear:hover,
.avui-section-cell-unbind:hover { color: var(--avui-accent); }

/* === Section focus indicator (pulse + sparkline) === */
.avui-section-focus {
    position: relative;
    border-radius: var(--avui-radius-lg);
    transition: box-shadow var(--avui-transition);
    --avui-progress: 0%;
}
.avui-section-focus--focused {
    box-shadow:
        0 0 0 1px var(--avui-border-focus),
        0 0 32px -8px var(--avui-glow-accent);
    animation: avui-focus-pulse 3.2s ease-in-out infinite alternate;
}
.avui-section-focus--multi.avui-section-focus--phase-b {
    animation-delay: -1.6s;
}
.avui-section-focus--processing {
    animation: none;
    box-shadow: 0 0 0 1px var(--avui-border-focus);
}
.avui-section-focus--error {
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--avui-warning) 55%, transparent);
}
.avui-section-focus-sparkline {
    position: absolute; left: 0; right: 0; top: 0; height: 2px;
    pointer-events: none; opacity: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--avui-accent) var(--avui-progress),
        transparent calc(var(--avui-progress) + 8%)
    );
    transition: opacity 0.25s ease;
}
.avui-section-focus--processing .avui-section-focus-sparkline { opacity: 0.85; }
.avui-section-focus--error .avui-section-focus-sparkline {
    opacity: 0.7;
    background: linear-gradient(90deg, transparent, var(--avui-warning), transparent);
}
@keyframes avui-focus-pulse {
    from {
        box-shadow:
            0 0 0 1px var(--avui-border-focus),
            0 0 24px -10px color-mix(in srgb, var(--avui-glow-accent) 55%, transparent);
    }
    to {
        box-shadow:
            0 0 0 1px var(--avui-border-focus),
            0 0 40px -6px var(--avui-glow-accent);
    }
}
@media (prefers-reduced-motion: reduce) {
    .avui-section-focus--focused { animation: none; }
}

/* === Interaction bar === */
.avui-interaction-bar { display: flex; flex-direction: column; gap: 0.55rem; }
.avui-interaction-modes { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.avui-interaction-mode {
    font-family: var(--avui-font-mono); font-size: 11px; letter-spacing: 0.04em;
    padding: 0.25rem 0.55rem; border-radius: 999px; border: 1px solid var(--avui-border);
    background: transparent; color: var(--avui-text-muted); cursor: pointer;
}
.avui-interaction-mode:hover:not(:disabled) {
    color: var(--avui-text); border-color: var(--avui-border-focus);
}
.avui-interaction-mode-active {
    color: var(--avui-bg); background: var(--avui-accent); border-color: var(--avui-accent);
}
.avui-interaction-mode-soon { opacity: 0.55; cursor: not-allowed; }
.avui-interaction-mode-soon-tag {
    margin-left: 0.3rem; font-size: 9px; text-transform: uppercase; opacity: 0.8;
}
.avui-interaction-input-row { display: flex; gap: 0.4rem; }
.avui-interaction-input {
    flex: 1; min-width: 0; padding: 0.55rem 0.7rem;
    border-radius: var(--avui-radius); border: 1px solid var(--avui-border);
    background: color-mix(in srgb, var(--avui-bg) 70%, transparent);
    color: var(--avui-text); font-family: var(--avui-font); font-size: 13px;
}
.avui-interaction-input:focus {
    outline: none; border-color: var(--avui-border-focus);
}
.avui-interaction-input::placeholder { color: var(--avui-text-muted); }
.avui-interaction-input:disabled { opacity: 0.55; }
.avui-interaction-submit {
    padding: 0.55rem 0.85rem; border-radius: var(--avui-radius);
    border: 1px solid var(--avui-accent); background: var(--avui-accent);
    color: var(--avui-bg); cursor: pointer; font-weight: 600;
}
.avui-interaction-submit:hover:not(:disabled) { background: var(--avui-accent-hover); }
.avui-interaction-submit:disabled { opacity: 0.45; cursor: not-allowed; }

/* === Atmosphere layers === */
.avui-atmosphere {
    position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
    --avui-px: 0; --avui-py: 0;
}
.avui-atmosphere-void {
    position: absolute; inset: 0; background: var(--avui-bg);
}
.avui-atmosphere-nebula {
    position: absolute; width: 70%; height: 55%; border-radius: 50%;
    filter: blur(90px); opacity: 0.55;
    transform: translate(
        calc(var(--avui-px) * 12px),
        calc(var(--avui-py) * 8px)
    );
}
.avui-atmosphere-nebula-a {
    left: 10%; top: 8%;
    background: radial-gradient(circle, var(--avui-glow-accent) 0%, transparent 70%);
    animation: avui-nebula-a 72s ease-in-out infinite alternate;
}
.avui-atmosphere-nebula-b {
    right: 5%; top: 30%;
    background: radial-gradient(circle, var(--avui-glow-accent-secondary) 0%, transparent 70%);
    animation: avui-nebula-b 88s ease-in-out infinite alternate;
}
.avui-atmosphere-nebula-c {
    left: 30%; bottom: 5%;
    background: radial-gradient(circle, color-mix(in srgb, var(--avui-scope-marketplace) 40%, transparent) 0%, transparent 70%);
    animation: avui-nebula-c 96s ease-in-out infinite alternate;
}
@keyframes avui-nebula-a { from { transform: translate(-2%, 0); } to { transform: translate(3%, 2%); } }
@keyframes avui-nebula-b { from { transform: translate(2%, -1%); } to { transform: translate(-3%, 2%); } }
@keyframes avui-nebula-c { from { transform: translate(0, 2%); } to { transform: translate(2%, -2%); } }
.avui-atmosphere-grain {
    position: absolute; inset: 0; opacity: 0.045;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.avui-atmosphere-horizon-grid {
    position: absolute; left: -20%; right: -20%; bottom: 12%; height: 50%;
    transform-origin: 50% 100%;
    transform: perspective(420px) rotateX(58deg)
        translateX(calc(var(--avui-px) * 6px))
        translateY(calc(var(--avui-py) * 4px));
    background-image:
        linear-gradient(color-mix(in srgb, var(--avui-accent) 22%, transparent) 1px, transparent 1px),
        linear-gradient(90deg, color-mix(in srgb, var(--avui-accent) 16%, transparent) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(to top, black 0%, transparent 88%);
    -webkit-mask-image: linear-gradient(to top, black 0%, transparent 88%);
}
.avui-atmosphere-horizon-line {
    position: absolute; left: 8%; right: 8%; top: 48%; height: 1px;
    background: linear-gradient(
        90deg, transparent,
        color-mix(in srgb, var(--avui-accent) 45%, transparent) 20%,
        color-mix(in srgb, var(--avui-scope-marketplace) 35%, transparent) 50%,
        color-mix(in srgb, var(--avui-accent) 45%, transparent) 80%,
        transparent
    );
}
.avui-atmosphere-particles {
    position: absolute; inset: 0; width: 100%; height: 100%;
    transform: translate(
        calc(var(--avui-px) * 18px),
        calc(var(--avui-py) * 12px)
    );
}
.avui-atmosphere-vignette {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.4) 100%);
}
.avui-atmosphere-head-glow {
    position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
    border-radius: 50%; pointer-events: none;
    background: radial-gradient(circle, var(--avui-glow-accent) 0%, transparent 70%);
    opacity: 0.12; transition: left 0.05s linear, top 0.05s linear, opacity 0.2s ease;
}
@media (prefers-reduced-motion: reduce) {
    .avui-atmosphere-nebula-a,
    .avui-atmosphere-nebula-b,
    .avui-atmosphere-nebula-c { animation: none; }
}

/* === Scope tether === */
.avui-scope-tether {
    position: fixed; inset: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 40;
    overflow: visible;
}
.avui-scope-tether--hidden { display: none; }
.avui-scope-tether-path {
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* Soft under-bloom — same path as spark (no parallel double-rail). */
.avui-scope-tether-path--glow {
    stroke: color-mix(in srgb, var(--avui-accent) 50%, transparent);
    stroke-width: 5;
    opacity: 0.4;
}
/* Sparkline stroke: dashed energy traveling orb → cell. */
.avui-scope-tether-path--spark {
    stroke: color-mix(in srgb, var(--avui-accent-hover) 82%, #fff 18%);
    stroke-width: 2.25;
    stroke-dasharray: 7 11;
    opacity: 0.95;
    animation: avui-tether-spark 0.85s linear infinite;
    filter: drop-shadow(0 0 4px var(--avui-glow-accent));
}
.avui-scope-tether-packet {
    fill: #fff;
    stroke: var(--avui-accent-hover);
    stroke-width: 1.5;
    filter: drop-shadow(0 0 6px var(--avui-glow-accent));
}
.avui-scope-tether-node {
    fill: var(--avui-accent-hover);
    stroke: color-mix(in srgb, var(--avui-accent-hover) 40%, #fff 60%);
    stroke-width: 1.25;
}
.avui-scope-tether-node--head { opacity: 0.9; }
.avui-scope-tether-node--cell {
    opacity: 1;
    transform-box: fill-box;
    transform-origin: center;
    animation: avui-tether-node-pulse 1.8s ease-in-out infinite;
}
.avui-scope-tether--dragging .avui-scope-tether-path--glow { opacity: 0.65; }
.avui-scope-tether--dragging .avui-scope-tether-path--spark {
    opacity: 1;
    animation-duration: 0.55s;
}
/* Off-screen target: relationship stays drawn (path exits the viewport), quieter. */
.avui-scope-tether-link--offscreen .avui-scope-tether-path--glow { opacity: 0.22; }
.avui-scope-tether-link--offscreen .avui-scope-tether-path--spark {
    opacity: 0.5;
    stroke-width: 1.75;
}
.avui-scope-tether-link--offscreen .avui-scope-tether-packet { opacity: 0.55; }
@keyframes avui-tether-spark {
    to { stroke-dashoffset: -36; }
}
@keyframes avui-tether-node-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.85;
        filter: drop-shadow(0 0 2px var(--avui-glow-accent));
    }
    50% {
        transform: scale(1.3);
        opacity: 1;
        filter: drop-shadow(0 0 7px var(--avui-glow-accent));
    }
}
@media (prefers-reduced-motion: reduce) {
    .avui-scope-tether-path--spark,
    .avui-scope-tether-node--cell {
        animation: none;
    }
    .avui-scope-tether-packet { display: none; }
    .avui-scope-tether-path--spark { stroke-dasharray: 5 8; opacity: 0.95; }
}

/* === Cmd head (notebook remote) === */
.avui-cmd-head {
    position: fixed; z-index: 50; width: 55px; height: 55px;
    touch-action: none; user-select: none;
    /* Stacked glass: info sheet above, chat controller below. */
    --avui-cmd-head-controller-h: 3.5rem;
    --avui-cmd-head-stack-gap: 0.5rem;
}
.avui-cmd-head--dragging,
.avui-cmd-head--coasting {
    /* No layout transitions while dragging / coasting — avoids perceived "reset". */
    transition: none;
}
.avui-cmd-head--dragging .avui-cmd-head-sheet {
    /* Hide without unmounting (keeps pointer capture stable). */
    visibility: hidden; pointer-events: none;
}
.avui-cmd-head-orb {
    width: 55px; height: 55px; border-radius: 50%;
    position: relative; cursor: grab;
    isolation: isolate;
    transition: box-shadow 180ms ease, transform 180ms ease;
    transform-origin: 50% 50%;
}
.avui-cmd-head:hover .avui-cmd-head-orb {
    transform: scale(1.04);
}
.avui-cmd-head--dragging .avui-cmd-head-orb {
    cursor: grabbing;
    transform: scale(1.08);
    transition: none;
}
.avui-cmd-head--coasting .avui-cmd-head-orb {
    cursor: grabbing;
    transform: scale(1.05);
    transition: none;
}
.avui-cmd-head-orb-halo {
    position: absolute; inset: -10px; border-radius: 50%;
    background: radial-gradient(
        circle at 50% 50%,
        color-mix(in srgb, var(--avui-accent) 45%, transparent),
        transparent 70%
    );
    opacity: 0.55;
    animation: avui-orb-breathe 3.6s ease-in-out infinite;
    z-index: 0;
}
.avui-cmd-head-orb-glass {
    position: absolute; inset: 0; border-radius: 50%;
    background: var(--avui-glass-fill);
    border: 1px solid var(--avui-glass-border);
    backdrop-filter: blur(10px) saturate(1.35);
    -webkit-backdrop-filter: blur(10px) saturate(1.35);
    box-shadow:
        0 6px 18px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
    z-index: 1;
}
.avui-cmd-head-orb-core {
    position: absolute; inset: 9px; border-radius: 50%;
    background:
        radial-gradient(circle at 32% 28%, color-mix(in srgb, var(--avui-accent-hover) 90%, #fff), transparent 42%),
        radial-gradient(circle at 60% 70%, color-mix(in srgb, var(--avui-accent) 55%, #000), var(--avui-accent));
    box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.35);
    z-index: 2;
}
.avui-cmd-head-orb-shine {
    position: absolute; inset: 11px 14px auto 11px; height: 38%;
    border-radius: 50%;
    background: linear-gradient(
        165deg,
        rgba(255, 255, 255, 0.45),
        rgba(255, 255, 255, 0.05) 55%,
        transparent
    );
    z-index: 3;
    pointer-events: none;
}
.avui-cmd-head-orb-iris {
    position: absolute; left: 50%; top: 52%;
    width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.85), transparent 45%),
        radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--avui-bg) 35%, #000), #0a0c0d);
    box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--avui-accent-hover) 70%, transparent);
    z-index: 4;
    pointer-events: none;
}
.avui-cmd-head-orb-ring {
    position: absolute; inset: 2px; border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--avui-glass-border) 80%, transparent);
    border-top-color: color-mix(in srgb, var(--avui-accent-hover) 65%, transparent);
    opacity: 0.85;
    z-index: 5;
    pointer-events: none;
}
.avui-cmd-head--processing .avui-cmd-head-orb-ring {
    animation: avui-orb-spin 1.2s linear infinite;
    border-top-color: var(--avui-accent-hover);
}
.avui-cmd-head--processing .avui-cmd-head-orb-halo {
    opacity: 0.85;
    animation: avui-orb-breathe 1.4s ease-in-out infinite;
}
.avui-cmd-head--error .avui-cmd-head-orb-core {
    background:
        radial-gradient(circle at 32% 28%, color-mix(in srgb, var(--avui-warning) 80%, #fff), transparent 42%),
        radial-gradient(circle at 60% 70%, color-mix(in srgb, var(--avui-warning) 55%, #000), var(--avui-warning));
}
.avui-cmd-head--marketplace .avui-cmd-head-orb-core {
    background:
        radial-gradient(circle at 32% 28%, color-mix(in srgb, var(--avui-scope-marketplace) 85%, #fff), transparent 42%),
        radial-gradient(circle at 60% 70%, color-mix(in srgb, var(--avui-scope-marketplace) 50%, #000), var(--avui-scope-marketplace));
}
.avui-cmd-head--scoped .avui-cmd-head-orb-iris {
    box-shadow: 0 0 0 2px var(--avui-accent);
}

/* Idle beckon — noticeability for first-time visitors (paused on hover / use). */
.avui-cmd-head--beckon .avui-cmd-head-orb {
    animation: avui-orb-beckon 2.8s ease-in-out infinite;
}
.avui-cmd-head--beckon .avui-cmd-head-orb-ring {
    animation: avui-orb-spin 6.5s linear infinite;
    border-top-color: color-mix(in srgb, var(--avui-accent-hover) 85%, transparent);
    opacity: 1;
}
.avui-cmd-head--beckon .avui-cmd-head-orb-halo {
    animation: avui-orb-beckon-halo 2.4s ease-in-out infinite;
}
.avui-cmd-head--beckon:hover .avui-cmd-head-orb,
.avui-cmd-head--beckon:focus-visible .avui-cmd-head-orb {
    animation: none;
    transform: scale(1.04);
}
.avui-cmd-head--beckon:hover .avui-cmd-head-orb-ring,
.avui-cmd-head--beckon:focus-visible .avui-cmd-head-orb-ring {
    animation: none;
}
.avui-cmd-head--beckon:hover .avui-cmd-head-orb-halo,
.avui-cmd-head--beckon:focus-visible .avui-cmd-head-orb-halo {
    animation: avui-orb-breathe 3.6s ease-in-out infinite;
}

@keyframes avui-orb-spin { to { transform: rotate(360deg); } }
@keyframes avui-orb-breathe {
    0%, 100% { transform: scale(0.92); opacity: 0.4; }
    50% { transform: scale(1.08); opacity: 0.7; }
}
@keyframes avui-orb-beckon {
    0%, 100% { transform: rotate(-5deg) scale(1); }
    40% { transform: rotate(6deg) scale(1.07); }
    70% { transform: rotate(-3deg) scale(1.03); }
}
@keyframes avui-orb-beckon-halo {
    0%, 100% { transform: scale(0.88); opacity: 0.35; }
    50% { transform: scale(1.22); opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
    .avui-cmd-head--beckon .avui-cmd-head-orb,
    .avui-cmd-head--beckon .avui-cmd-head-orb-ring,
    .avui-cmd-head--beckon .avui-cmd-head-orb-halo {
        animation: none;
    }
}

.avui-cmd-head-sheet {
    position: absolute; right: 0; left: auto;
    bottom: calc(64px + var(--avui-cmd-head-controller-h) + var(--avui-cmd-head-stack-gap));
    display: flex; flex-direction: column; gap: 0.75rem;
    min-width: 280px; min-height: 220px;
    /* Never let a tall/resized sheet run off the top of the viewport and
       mangle background content. Reserves the controller stack + orb + a
       top breathing margin. Mobile overrides to none (fullscreen sheet). */
    max-height: calc(100dvh - var(--avui-cmd-head-controller-h) - var(--avui-cmd-head-stack-gap) - 140px);
    padding: 1rem 1.05rem 1.15rem;
    border-radius: var(--avui-radius-lg);
    background:
        linear-gradient(
            145deg,
            color-mix(in srgb, #e8f0ff 14%, transparent) 0%,
            transparent 42%,
            color-mix(in srgb, #9eb6d4 8%, transparent) 70%,
            transparent 100%
        ),
        var(--avui-glass-fill);
    border: 1px solid var(--avui-glass-border);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    box-shadow:
        0 16px 40px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        inset 0 -1px 0 rgba(0, 0, 0, 0.18);
    color: var(--avui-text);
    overflow: hidden;
    transform-origin: 100% 100%;
    /* Transform/opacity only — filter + backdrop-filter blanks children in WebKit/Chromium. */
    animation: avui-sheet-liquid-open 0.58s cubic-bezier(0.2, 1.05, 0.32, 1) both;
}
.avui-cmd-head-sheet::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        108deg,
        transparent 30%,
        rgba(255, 255, 255, 0.06) 44%,
        rgba(230, 240, 255, 0.38) 50%,
        rgba(160, 190, 220, 0.14) 56%,
        transparent 70%
    );
    background-size: 220% 100%;
    background-position: 120% 0;
    animation: avui-sheet-liquid-sheen 0.75s ease-out 0.04s both;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
}
.avui-cmd-head-sheet > * {
    position: relative;
    z-index: 1;
}
/* Floating chat controller — its own glass bar below the info sheet.
   Using the controller generates the sheet above (cmd-head spec). */
.avui-cmd-head-controller {
    position: absolute; right: 0; bottom: 64px;
    display: flex; flex-direction: column;
    min-width: 280px;
    padding: 0.5rem 0.6rem;
    border-radius: var(--avui-radius-lg);
    background:
        linear-gradient(
            145deg,
            color-mix(in srgb, #e8f0ff 14%, transparent) 0%,
            transparent 42%,
            color-mix(in srgb, #9eb6d4 8%, transparent) 70%,
            transparent 100%
        ),
        var(--avui-glass-fill);
    border: 1px solid var(--avui-glass-border);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        inset 0 -1px 0 rgba(0, 0, 0, 0.18);
    color: var(--avui-text);
    box-sizing: border-box;
    transform-origin: 100% 100%;
    animation: avui-sheet-liquid-open 0.5s cubic-bezier(0.2, 1.05, 0.32, 1) both;
}
.avui-cmd-head-controller .avui-cmd-head-input-row {
    margin: 0;
}
.avui-cmd-head--dragging .avui-cmd-head-controller {
    /* Hide without unmounting (keeps pointer capture stable). */
    visibility: hidden; pointer-events: none;
}
.avui-cmd-head-sheet--resizing {
    user-select: none;
    transition: none;
    animation: none;
}
.avui-cmd-head-sheet--resizing::before {
    animation: none;
    opacity: 0;
}
@keyframes avui-sheet-liquid-open {
    0% {
        opacity: 0;
        transform: scale(0.22, 0.16) translate(8px, 14px);
    }
    58% {
        opacity: 1;
        transform: scale(1.012, 1.018) translate(0, 0);
    }
    100% {
        opacity: 1;
        transform: scale(1) translate(0, 0);
    }
}
@keyframes avui-sheet-liquid-sheen {
    0% { opacity: 0; background-position: 120% 0; }
    35% { opacity: 0.85; }
    100% { opacity: 0; background-position: -40% 0; }
}
.avui-cmd-head-sheet-close {
    display: none;
}
.avui-cmd-head-resize-host {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.avui-cmd-head-resize-host > * {
    pointer-events: auto;
}
.avui-cmd-head-scope {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}
.avui-cmd-head-scope-label {
    display: block; font-family: var(--avui-font-mono); font-size: 10px;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--avui-text-muted);
    margin: 0;
}
.avui-cmd-head-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.avui-cmd-head-chip {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-family: var(--avui-font-mono); font-size: 10px;
    padding: 0.2rem 0.45rem; border-radius: 999px;
    border: 1px solid var(--avui-border); background: transparent;
    color: var(--avui-text); cursor: pointer;
}
.avui-cmd-head-chip-x { opacity: 0.6; }
.avui-cmd-head-clear {
    background: transparent; border: none; color: var(--avui-text-muted);
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; cursor: pointer;
    padding: 0.2rem 0.25rem;
}
.avui-cmd-head-scope-hint {
    margin: 0; font-size: 11px; line-height: 1.4;
    color: var(--avui-text-muted);
}
.avui-cmd-head-input-row {
    display: flex; align-items: stretch; gap: 0.5rem; flex: 0 0 auto;
}
/*
 * Canonical field pattern: chrome + padding on a wrapper; naked <input> inside.
 * Safari/WebKit does not honor vertical padding on text inputs reliably —
 * padding on a block/flex container always works.
 */
.avui-cmd-head-field {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    min-height: 2.5rem;
    padding: 0.55rem 0.85rem;
    border-radius: var(--avui-radius);
    border: 1px solid var(--avui-border);
    background: color-mix(in srgb, var(--avui-bg) 55%, transparent);
    cursor: text;
}
.avui-cmd-head-field:focus-within {
    border-color: var(--avui-border-focus);
}
.avui-cmd-head-input {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--avui-text);
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}
.avui-cmd-head-input:disabled {
    opacity: 0.55;
}
.avui-cmd-head-send {
    flex: 0 0 auto;
    min-height: 2.5rem; min-width: 3.25rem;
    padding: 0 0.9rem; border-radius: var(--avui-radius);
    border: 1px solid var(--avui-accent); background: var(--avui-accent);
    color: var(--avui-bg); font-size: 12px; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    box-sizing: border-box;
}
.avui-cmd-head-body {
    flex: 1 1 auto; min-height: 0; overflow: auto;
    margin-top: 0.1rem;
    padding: 0.65rem 0.1rem 0.15rem 0;
}
.avui-cmd-head-body .avui-answer-stream { margin: 0; }
.avui-cmd-head-body .avui-answer-placeholder {
    font-size: 12px; line-height: 1.45; color: var(--avui-text-muted);
}
.avui-cmd-head-body .avui-timing-profile { margin-top: 0.35rem; }
/* Corpus scope footer — ALL scope data (label + chips + hint) anchors the
   bottom of the info panel, just above the controller. The top of the pane
   is the answer body alone, so nothing crowds the top edge. */
.avui-cmd-head-sheet-footer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    margin-top: 0.1rem;
    padding: 0.6rem 0.1rem 0;
    border-top: 1px solid color-mix(in srgb, var(--avui-border) 65%, transparent);
}
.avui-cmd-head-sheet-footer .avui-cmd-head-scope-hint {
    margin: 0;
}
.avui-cmd-head-resize {
    position: absolute; z-index: 2; touch-action: none;
    background: transparent;
}
.avui-cmd-head-resize--left {
    top: 16px; bottom: 8px; left: 0; width: 12px;
    cursor: ew-resize;
}
.avui-cmd-head-resize--top {
    top: 0; left: 16px; right: 8px; height: 12px;
    cursor: ns-resize;
}
.avui-cmd-head-resize--corner {
    top: 0; left: 0; width: 22px; height: 22px;
    cursor: nwse-resize;
    border-top-left-radius: var(--avui-radius-lg);
    background:
        linear-gradient(135deg,
            color-mix(in srgb, var(--avui-accent) 70%, transparent) 0 2px,
            transparent 2px 5px,
            color-mix(in srgb, var(--avui-accent) 45%, transparent) 5px 7px,
            transparent 7px);
    opacity: 0.7;
}
.avui-cmd-head-resize--left:hover,
.avui-cmd-head-sheet--resizing .avui-cmd-head-resize--left {
    background: linear-gradient(
        90deg,
        color-mix(in srgb, var(--avui-accent) 35%, transparent),
        transparent
    );
}
.avui-cmd-head-resize--top:hover,
.avui-cmd-head-sheet--resizing .avui-cmd-head-resize--top {
    background: linear-gradient(
        180deg,
        color-mix(in srgb, var(--avui-accent) 35%, transparent),
        transparent
    );
}
.avui-cmd-head-resize--corner:hover,
.avui-cmd-head-sheet--resizing .avui-cmd-head-resize--corner { opacity: 1; }
body.avui-cmd-head-gesture {
    cursor: grabbing !important;
    user-select: none !important;
}
body.avui-cmd-head-gesture * {
    cursor: inherit !important;
}

/* Mobile: bottom-row dock + fullscreen sheet that collapses to the orb */
.avui-cmd-head--mobile {
    height: 55px; width: auto; min-width: 55px;
    --avui-cmd-head-controller-h: 4rem;
    --avui-cmd-head-stack-gap: 0.4rem;
}
.avui-cmd-head--mobile.avui-cmd-head--expanded {
    z-index: 80;
}
.avui-cmd-head--mobile.avui-cmd-head--expanded .avui-cmd-head-orb {
    position: relative;
    z-index: 3;
}
.avui-cmd-head--mobile .avui-cmd-head-sheet {
    position: fixed;
    inset: 0;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    z-index: 2;
    border-radius: 0;
    /* Denser fill so landing nav doesn’t read through the sheet chrome. */
    background:
        linear-gradient(
            145deg,
            color-mix(in srgb, #e8f0ff 10%, transparent) 0%,
            transparent 42%,
            color-mix(in srgb, #9eb6d4 6%, transparent) 70%,
            transparent 100%
        ),
        rgba(11, 13, 14, 0.94);
    padding:
        max(1.1rem, env(safe-area-inset-top, 0px))
        max(1.1rem, env(safe-area-inset-right, 0px))
        calc(var(--avui-cmd-head-controller-h) + var(--avui-cmd-head-stack-gap) + env(safe-area-inset-bottom, 0px))
        max(1.1rem, env(safe-area-inset-left, 0px));
    transform-origin: 50% 100%;
    animation: avui-sheet-mobile-open 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.avui-cmd-head--mobile .avui-cmd-head-sheet--closing {
    animation: avui-sheet-mobile-close 0.34s cubic-bezier(0.4, 0, 0.2, 1) both;
    pointer-events: none;
}
.avui-cmd-head--mobile .avui-cmd-head-sheet-footer {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}
.avui-cmd-head--mobile .avui-cmd-head-scope {
    flex: 1 1 auto;
}
.avui-cmd-head--mobile .avui-cmd-head-sheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 2.5rem;
    padding: 0 0.85rem;
    border-radius: var(--avui-radius);
    border: 1px solid var(--avui-border);
    background: color-mix(in srgb, var(--avui-bg) 55%, transparent);
    color: var(--avui-text);
    font-family: var(--avui-font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}
.avui-cmd-head--mobile .avui-cmd-head-field {
    min-height: 3rem;
    padding: 0.85rem 1.15rem;
}
.avui-cmd-head--mobile .avui-cmd-head-input {
    font-size: 16px; /* avoid iOS focus zoom */
    line-height: 1.35;
}
.avui-cmd-head--mobile .avui-cmd-head-input::placeholder {
    opacity: 0.72;
}
.avui-cmd-head--mobile .avui-cmd-head-send {
    min-height: 3rem;
    padding: 0 1.1rem;
}
.avui-cmd-head--mobile .avui-cmd-head-input-row {
    gap: 0.65rem;
    margin-top: 0.15rem;
}
/* Mobile: controller docks at the bottom of the fullscreen sheet. */
.avui-cmd-head--mobile .avui-cmd-head-controller {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    min-width: 0;
    border-radius: 0;
    z-index: 4;
    padding:
        0.5rem max(1.1rem, env(safe-area-inset-right, 0px))
        calc(0.55rem + env(safe-area-inset-bottom, 0px))
        max(1.1rem, env(safe-area-inset-left, 0px));
    transform-origin: 50% 100%;
    animation: avui-sheet-mobile-open 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.avui-cmd-head--mobile .avui-cmd-head-body {
    flex: 1 1 auto;
    min-height: 0;
}
body.avui-cmd-head-sheet-open,
body.avui-cmd-head-sheet-open .landing-shell {
    overflow: hidden !important;
    overscroll-behavior: none;
}
@keyframes avui-sheet-mobile-open {
    0% {
        opacity: 0.75;
        transform: translateY(18%) scale(0.2, 0.14);
        border-radius: 28px;
    }
    62% {
        opacity: 1;
        transform: translateY(0) scale(1.01, 1.015);
        border-radius: 8px;
    }
    100% {
        opacity: 1;
        transform: none;
        border-radius: 0;
    }
}
@keyframes avui-sheet-mobile-close {
    0% {
        opacity: 1;
        transform: none;
        border-radius: 0;
    }
    100% {
        opacity: 0.55;
        transform: translateY(22%) scale(0.18, 0.12);
        border-radius: 28px;
    }
}
@media (prefers-reduced-motion: reduce) {
    .avui-cmd-head--processing .avui-cmd-head-orb-ring,
    .avui-cmd-head-orb-halo { animation: none; }
    .avui-cmd-head-sheet,
    .avui-cmd-head-sheet::before {
        animation: none !important;
    }
    .avui-cmd-head--mobile .avui-cmd-head-sheet,
    .avui-cmd-head--mobile .avui-cmd-head-sheet--closing {
        transform: none;
        border-radius: 0;
    }
}
