/* ═══════════════════════════════════════════════════════════════════
   ALEX Widget Mode — Floating panels over ShipApp
   Activated by body.widget-mode class (set via ?mode=widget URL param)
   CSS values ported directly from Element Specification Sheet v2
   ═══════════════════════════════════════════════════════════════════ */

/* ── Hide standard ALEX UI when widget mode active ────────────────── */
body.widget-mode #ambient-container,
body.widget-mode #output-container,
body.widget-mode #input-bar-container,
body.widget-mode #lang-selector,
body.widget-mode #review-banner,
body.widget-mode #hud-response-panel,
body.widget-mode #training-trigger-btn,
body.widget-mode #storyline-fade-overlay,
body.widget-mode #safety-gate-overlay,
body.widget-mode footer {
    display: none !important;
}

body.widget-mode {
    background: #f7f7f7;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ═══════════════════════════════════════════════════════════════════
   SHIPAPP BACKGROUND — Real screenshot behind ALEX widget
   ═══════════════════════════════════════════════════════════════════ */
.shipapp-mockup {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: url('shipapp-bg.png') center top / cover no-repeat;
    pointer-events: none;
}

/* Interactive ShipApp mock (kickout-operator project) */
#shipapp-root {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}
#shipapp-root .wrapper {
    padding-bottom: 36px; /* room for demo bar */
}

/* When ShipApp root is present, restore tile background on body */
body.widget-mode:has(#shipapp-root) {
    background-image: url('shipapp-assets/tile.png') !important;
    background-color: transparent !important;
}

/* ═══════════════════════════════════════════════════════════════════
   WIDGET CIRCLE — 88×88px, 3 states (Dormant, Listening, Thinking)
   Position: absolute, bottom: 20px, right: 20px
   ═══════════════════════════════════════════════════════════════════ */
.widget-circle {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background-color: transparent;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

/* Dormant: static orange ring, subtle glow */
.widget-circle.dormant {
    border: 3px solid #FF9500;
    filter: drop-shadow(0 0 8px rgba(210,110,0,0.45));
    box-shadow: inset 0 0 20px 8px rgba(210,110,0,0.35);
    animation: none;
}

/* Listening: pulse glow, scale 1→1.02, 2.5s infinite */
.widget-circle.listening {
    border: 3px solid #FF9500;
    filter: drop-shadow(0 0 8px rgba(210,110,0,0.45));
    box-shadow: inset 0 0 20px 8px rgba(210,110,0,0.5);
    animation: widgetPulse 2.5s infinite ease-in-out;
}

/* Thinking: spinning half-ring, 1s linear infinite */
.widget-circle.thinking {
    border: 3px solid rgba(255,149,0,0.2);
    border-top: 3px solid #FF9500;
    border-right: 3px solid #FF9500;
    animation: widgetSpin 1s linear infinite;
    box-shadow: 0 0 20px rgba(255,149,0,0.3), inset 0 0 20px 8px rgba(210,110,0,0.35);
    filter: drop-shadow(0 0 8px rgba(210,110,0,0.45));
}

/* Hidden when panels or pills are showing */
.widget-circle.hidden {
    display: none !important;
}

@keyframes widgetPulse {
    0%   { transform: scale(1);    border-color: #FF9500; box-shadow: 0 0 25px rgba(255,149,0,.5), 0 0 50px rgba(255,149,0,.3), 0 0 75px rgba(255,149,0,.15), inset 0 0 20px 8px rgba(210,110,0,0.5); }
    50%  { transform: scale(1.02); border-color: #FFB340; box-shadow: 0 0 40px rgba(255,149,0,.7), 0 0 70px rgba(255,149,0,.4), 0 0 100px rgba(255,149,0,.2), inset 0 0 24px 10px rgba(210,110,0,0.6); }
    100% { transform: scale(1);    border-color: #FF9500; box-shadow: 0 0 25px rgba(255,149,0,.5), 0 0 50px rgba(255,149,0,.3), 0 0 75px rgba(255,149,0,.15), inset 0 0 20px 8px rgba(210,110,0,0.5); }
}

@keyframes widgetSpin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════════
   PANEL AREA — Container for all floating panels
   Width: 25vw, Position: fixed top:20px right:20px
   ═══════════════════════════════════════════════════════════════════ */
.widget-panel-area {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 37.5vw;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 90;
    opacity: 0;
    pointer-events: none;
}

.widget-panel-area.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSE PANEL — Floating text panel
   Max-height: 30vh, opens at final height before typewriter
   ═══════════════════════════════════════════════════════════════════ */
.widget-response-panel {
    max-height: 22vh;
    background: linear-gradient(145deg, #1a1f2e 0%, #232f3e 100%);
    border: 1px solid rgba(255, 107, 0, 0.2);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Panel header: session circle left, controls right */
.widget-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    flex-shrink: 0;
    min-height: 32px;
}

/* Session indicator circle — 24×24px canvas */
.widget-session-canvas {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Panel control icons container */
.widget-panel-controls {
    display: flex;
    gap: 6px;
}

/* Control button base: 28×28px */
.widget-ctrl-btn {
    width: 28px;
    height: 28px;
    background: rgba(26, 31, 46, 0.8);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    opacity: 0.6;
    border: none;
    padding: 0;
    transition: opacity 0.15s ease;
}
.widget-ctrl-btn:hover { opacity: 1; }

/* Hide icon: horizontal line (minimize) */
.widget-ctrl-hide::after {
    content: '';
    position: absolute;
    top: 13px;
    left: 7px;
    right: 7px;
    height: 2px;
    background: #FF9500;
    border-radius: 1px;
}

/* Dismiss icon: X */
.widget-ctrl-close::before,
.widget-ctrl-close::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 13px;
    width: 2px;
    height: 16px;
    background: #FF9500;
    border-radius: 1px;
}
.widget-ctrl-close::before { transform: rotate(45deg); }
.widget-ctrl-close::after { transform: rotate(-45deg); }

/* Scrollable text area — overflow controlled by JS based on content length */
.widget-text-area {
    padding: 0 20px 20px 12px;
    flex: 1;
    overflow: hidden;
    color: #fff;
    font-size: 18px;
    line-height: 1.6;
}
.widget-text-area.scrollable {
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.widget-text-area.scrollable::-webkit-scrollbar { display: none; }

/* Typewriter cursor blink */
.widget-typewriter-cursor {
    display: inline;
    border-right: 2px solid rgba(255,149,0,0.6);
    padding-right: 2px;
    animation: widgetCursorBlink 0.8s step-end infinite;
}

@keyframes widgetCursorBlink {
    0%, 100% { border-color: rgba(255,149,0,0.6); }
    50%      { border-color: transparent; }
}

/* ═══════════════════════════════════════════════════════════════════
   USER TRANSCRIPT BUBBLE — Voice input typewriter display
   Appears above ALEX's response, fades out when response streams in
   ═══════════════════════════════════════════════════════════════════ */
.widget-user-bubble {
    background: rgba(255, 149, 0, 0.12);
    border: 1px solid rgba(255, 149, 0, 0.25);
    border-radius: 12px;
    padding: 10px 16px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    line-height: 1.5;
    text-align: right;
    margin-left: auto;
    max-width: 85%;
    width: fit-content;
    transition: opacity 0.35s ease;
}

.widget-user-bubble.fading {
    opacity: 0;
}

.widget-user-bubble-text {
    display: inline;
}

/* ═══════════════════════════════════════════════════════════════════
   SCROLL INDICATOR — Custom orange thumb, no track
   ═══════════════════════════════════════════════════════════════════ */
.widget-scroll-indicator {
    position: absolute;
    top: 12px;
    right: 6px;
    bottom: 12px;
    width: 4px;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: auto;
    cursor: pointer;
}
.widget-scroll-indicator.visible { opacity: 1; }

.widget-scroll-thumb {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    background: rgba(255, 149, 0, 0.5);
    border-radius: 2px;
    transition: top 0.4s ease, height 0.1s ease;
    cursor: grab;
}
.widget-scroll-thumb:active { cursor: grabbing; }

/* ═══════════════════════════════════════════════════════════════════
   MEDIA PANEL — Floating media container
   ═══════════════════════════════════════════════════════════════════ */
.widget-media-panel {
    background: linear-gradient(145deg, #1a1f2e 0%, #232f3e 100%);
    border: 1px solid rgba(255, 107, 0, 0.2);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    gap: 10px;
    max-height: 40vh;
    overflow: hidden;
}

.widget-media-item {
    flex: 1;
    background: #2a3440;
    border-radius: 8px;
    min-height: 20vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.widget-media-item img,
.widget-media-item video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* Fullscreen expand icon: 28×28px, top-left of each media item */
.widget-expand-icon {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    background: rgba(26, 31, 46, 0.8);
    border-radius: 6px;
    cursor: pointer;
    z-index: 3;
    opacity: 0.6;
    transition: opacity 0.15s ease;
}
.widget-expand-icon:hover { opacity: 1; }

.widget-expand-icon::before {
    content: '';
    position: absolute;
    top: 5px; left: 5px; right: 5px; bottom: 5px;
    background:
        linear-gradient(to right, #FF9500 0%, #FF9500 100%) 0 0/5px 1.5px no-repeat,
        linear-gradient(to bottom, #FF9500 0%, #FF9500 100%) 0 0/1.5px 5px no-repeat,
        linear-gradient(to right, #FF9500 0%, #FF9500 100%) 100% 0/5px 1.5px no-repeat,
        linear-gradient(to bottom, #FF9500 0%, #FF9500 100%) 100% 0/1.5px 5px no-repeat,
        linear-gradient(to right, #FF9500 0%, #FF9500 100%) 0 100%/5px 1.5px no-repeat,
        linear-gradient(to bottom, #FF9500 0%, #FF9500 100%) 0 100%/1.5px 5px no-repeat,
        linear-gradient(to right, #FF9500 0%, #FF9500 100%) 100% 100%/5px 1.5px no-repeat,
        linear-gradient(to bottom, #FF9500 0%, #FF9500 100%) 100% 100%/1.5px 5px no-repeat;
}

/* ═══════════════════════════════════════════════════════════════════
   FULLSCREEN MODE — Media fills entire ShipApp area
   ═══════════════════════════════════════════════════════════════════ */
.widget-fullscreen-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(145deg, #1a1f2e 0%, #232f3e 100%);
    z-index: 200;
    display: none;
    padding: 12px;
    gap: 12px;
}
.widget-fullscreen-overlay.visible {
    display: flex;
}

.widget-fullscreen-overlay .widget-media-item {
    flex: 1;
    min-height: auto;
    height: 100%;
}

.widget-fullscreen-overlay .widget-expand-icon {
    top: 12px;
    left: 12px;
    width: 28px;
    height: 28px;
    border-radius: 7px;
}

/* ═══════════════════════════════════════════════════════════════════
   PILL TABS — Minimized state, replaces widget circle
   Position: fixed, bottom: 20px, right: 20px
   ═══════════════════════════════════════════════════════════════════ */
.widget-pill-row {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: row;
    gap: 8px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.widget-pill-row.visible {
    opacity: 1;
    pointer-events: auto;
}

.widget-pill {
    height: 36px;
    max-width: 160px;
    padding: 6px 14px;
    background: linear-gradient(145deg, #1a1f2e 0%, #232f3e 100%);
    border: 1px solid rgba(255, 107, 0, 0.2);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.15s ease;
}
.widget-pill:hover { transform: scale(1.03); }

.widget-pill-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Pill thumbnail for media pill */
.widget-pill-thumb {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 4px;
    background: #2a3440;
    border: 1px solid rgba(255, 149, 0, 0.3);
    background-size: cover;
    background-position: center;
}

/* ═══════════════════════════════════════════════════════════════════
   INSTRUCTION PILL — Onboarding tutorial
   Inverted colors: white bg, dark text, brighter orange border
   ═══════════════════════════════════════════════════════════════════ */
.widget-instruction-pill {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 149, 0, 0.6);
    border-radius: 12px;
    padding: 10px 14px;
    color: #1a1f2e;
    font-size: 18px;
    line-height: 1.4;
    position: fixed;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    max-width: 320px;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.1s ease, border-color 0.2s ease;
    pointer-events: none;
}
.widget-instruction-pill.visible {
    opacity: 1;
    pointer-events: auto;
}
.widget-instruction-pill.success {
    border-color: rgba(40, 200, 64, 0.6);
}

/* Progress dots */
.widget-tutorial-dots {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}
.widget-tutorial-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 149, 0, 0.3);
}
.widget-tutorial-dot.filled {
    background: #FF9500;
}

/* ═══════════════════════════════════════════════════════════════════
   LANGUAGE SELECTION SCREEN (TL)
   Full-screen ALEX home with breathing logo
   ═══════════════════════════════════════════════════════════════════ */
.widget-lang-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #0a0e13 0%, #0f1419 50%, #131a21 100%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
}

.widget-lang-logo {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: #0f1419;
    border: 3px solid #FF9500;
    box-shadow: 0 0 30px rgba(255,149,0,0.4), 0 0 60px rgba(255,149,0,0.2), 0 0 90px rgba(255,149,0,0.1);
    animation: widgetPulse 2.5s infinite ease-in-out;
}

.widget-lang-title {
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 3px;
}

.widget-lang-subtitle {
    color: rgba(255,255,255,0.5);
    font-size: 14px;
}

.widget-lang-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 500px;
    width: 100%;
    margin-top: 8px;
}

.widget-lang-btn {
    padding: 12px 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,149,0,0.15);
    border-radius: 8px;
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: inherit;
}
.widget-lang-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,149,0,0.4);
}
.widget-lang-btn[data-lang="ar"] {
    direction: rtl;
}

/* ═══════════════════════════════════════════════════════════════════
   DEV TOGGLE — Switch back to standard mode
   ═══════════════════════════════════════════════════════════════════ */
.widget-dev-toggle {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 9999;
    background: rgba(255, 149, 0, 0.15);
    color: #FF9500;
    border: 1px solid rgba(255, 107, 0, 0.2);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    backdrop-filter: blur(4px);
    font-family: inherit;
}
.widget-dev-toggle:hover {
    background: rgba(255, 149, 0, 0.25);
}

/* ═══════════════════════════════════════════════════════════════════
   DEMO MODE — Splash + Scenario screens
   ═══════════════════════════════════════════════════════════════════ */
.widget-demo-start-btn {
    margin-top: 24px;
    padding: 14px 48px;
    background: #FF9500;
    color: #0f1419;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, transform 0.1s ease;
    box-shadow: 0 0 20px rgba(255,149,0,0.4);
}
.widget-demo-start-btn:hover {
    background: #FFB340;
    transform: scale(1.03);
}

.widget-demo-scenario-text {
    max-width: 560px;
    text-align: center;
    color: rgba(255,255,255,0.85);
    font-size: 17px;
    line-height: 1.7;
    padding: 0 16px;
    margin-top: 8px;
}

.widget-demo-scenario-cue {
    margin-top: 28px;
    color: #FF9500;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.5px;
    opacity: 0;
    animation: widgetPulse 2.5s infinite ease-in-out;
}
