/* ==========================================================================
   walkthrough.css — KFCRIS Events walkthrough stage
   See BRIEF.md §5 (stage layout), §10 (stage elements), §13 (quality bars).
   No Tailwind, no frameworks — self-contained.
   ========================================================================== */

/* --------- Reset + base --------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0f172a;      /* slate-900 */
    color: #e2e8f0;            /* slate-200 */
    font-family: 'Segoe UI', Tahoma, 'Tajawal', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    cursor: pointer;
}

/* --------- Z-layers (BRIEF §5) --------- */
:root {
    --z-iframe:    1;
    --z-ribbon:    500;
    --z-bar:       1000;
    --z-overlay:   9999;

    --stage-bg:    #0b1220;
    --stage-panel: #0f172a;
    --stage-edge:  #1e293b;
    --stage-ink:   #e2e8f0;
    --stage-muted: #94a3b8;
    --accent-gold: #d4a24a;
    --accent-navy: #1a365d;

    --actor-color: #d4a24a;      /* overridden per act via JS */

    --top-bar-h:     64px;
    --chrome-h:      38px;
    --ribbon-h:      108px;
    --controls-h:    60px;
    --caption-h:     84px;
}

/* --------- Stage grid --------- */
#wt-stage {
    display: grid;
    grid-template-rows: var(--top-bar-h) 1fr var(--ribbon-h) var(--controls-h);
    width: 100vw;
    height: 100vh;
    background: var(--stage-bg);
    position: relative;
}

/* --------- Top bar (actor chip + titles + scene counter) --------- */
#wt-topbar {
    z-index: var(--z-bar);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: linear-gradient(180deg, #0f172a 0%, #0b1220 100%);
    border-bottom: 1px solid var(--stage-edge);
}

.wt-actor-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--stage-edge);
    border-radius: 999px;
    font-size: 14px;
    max-width: 50%;
    min-height: 36px;
}

.wt-actor-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--actor-color);
    box-shadow: 0 0 12px var(--actor-color);
    flex-shrink: 0;
}

.wt-actor-name {
    font-weight: 600;
    color: var(--stage-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wt-actor-sep {
    width: 1px;
    height: 18px;
    background: var(--stage-edge);
    flex-shrink: 0;
}

.wt-desk-label {
    color: var(--stage-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wt-parallel-tag {
    display: inline-block;
    padding: 2px 8px;
    margin-inline-start: 6px;
    background: rgba(212, 162, 74, 0.15);
    color: var(--accent-gold);
    border-radius: 4px;
    font-size: 12px;
}

.wt-act-title {
    flex: 1;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: var(--stage-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wt-scene-counter {
    color: var(--stage-muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    min-width: 80px;
    text-align: start;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wt-scene-counter[data-degraded="true"]::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #facc15;          /* yellow-400 */
    box-shadow: 0 0 6px #facc15;
}

/* --------- Iframe region --------- */
#wt-iframe-region {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 20px 40px 8px;
    background: var(--stage-bg);
    min-height: 0;
}

.wt-browser-chrome {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--chrome-h);
    padding: 0 14px;
    background: #334155;          /* slate-700 */
    border-radius: 10px 10px 0 0;
    border: 1px solid var(--stage-edge);
    border-bottom: none;
    direction: ltr;                /* chrome dots + URL read LTR */
}

.wt-chrome-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.wt-chrome-dot-red    { background: #ef4444; }
.wt-chrome-dot-yellow { background: #f59e0b; }
.wt-chrome-dot-green  { background: #10b981; }

.wt-chrome-url {
    flex: 1;
    margin-inline-start: 12px;
    padding: 4px 12px;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 999px;
    color: #cbd5e1;
    font-size: 12px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

#wt-iframe-container {
    flex: 1;
    min-height: 0;
    position: relative;
    background: white;
    border-radius: 0 0 10px 10px;
    border: 1px solid var(--stage-edge);
    border-top: none;
    overflow: hidden;
    z-index: var(--z-iframe);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    transition: transform 350ms ease-in-out, opacity 350ms ease-in-out;
}

#wt-iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: white;
}

/* Scene transition slides (BRIEF §10.7) — direction flipped because dir=rtl */
#wt-iframe-container[data-wt-transition="out"] {
    transform: translateX(-30%);
    opacity: 0;
}
#wt-iframe-container[data-wt-transition="in"] {
    transform: translateX(30%);
    opacity: 0;
}

/* --------- Documents ribbon --------- */
#wt-documents-ribbon {
    z-index: var(--z-ribbon);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    background: linear-gradient(180deg, #0b1220 0%, #050a14 100%);
    border-top: 1px solid var(--stage-edge);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

#wt-documents-ribbon:empty::before {
    content: 'لا توجد مستندات محمولة';
    color: var(--stage-muted);
    font-size: 12px;
    opacity: 0.6;
}

.wt-doc-card {
    flex-shrink: 0;
    width: 88px;
    height: 84px;
    padding: 8px;
    background: #1e293b;
    border: 1px solid var(--stage-edge);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 200ms, border-color 200ms;
}
.wt-doc-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-gold);
}
.wt-doc-card .wt-doc-icon {
    font-size: 22px;
    line-height: 1;
}
.wt-doc-card .wt-doc-title {
    font-size: 11px;
    color: var(--stage-ink);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* Materializing animation for new documents (BRIEF §10.4) */
@keyframes wt-doc-appear {
    0%   { transform: scale(0);   opacity: 0; }
    60%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1);   opacity: 1; }
}
.wt-doc-card[data-wt-new="true"] {
    animation: wt-doc-appear 400ms ease-out;
}

/* --------- Control bar --------- */
#wt-controls {
    z-index: var(--z-bar);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 24px;
    background: linear-gradient(0deg, #0f172a 0%, #0b1220 100%);
    border-top: 1px solid var(--stage-edge);
    transition: opacity 300ms, transform 300ms;
}

#wt-controls[data-wt-hidden="true"] {
    opacity: 0;
    transform: translateY(100%);
    pointer-events: none;
}

.wt-ctl-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    color: var(--stage-ink);
    font-size: 14px;
    transition: background 150ms;
}
.wt-ctl-btn:hover { background: rgba(255, 255, 255, 0.12); }
.wt-ctl-btn[data-wt-active="true"] { background: var(--accent-gold); color: #0b1220; }

.wt-ctl-sep {
    width: 1px;
    height: 22px;
    background: var(--stage-edge);
    margin: 0 4px;
}

.wt-ctl-meta {
    color: var(--stage-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    padding: 0 8px;
}

.wt-ctl-progress {
    flex: 0 0 200px;
    height: 4px;
    background: var(--stage-edge);
    border-radius: 2px;
    overflow: hidden;
}
.wt-ctl-progress-fill {
    height: 100%;
    background: var(--accent-gold);
    width: 0%;
    transition: width 200ms linear;
}

/* --------- Caption bar (lower-third, BRIEF §10.6) --------- */
/* Sits in the thin gutter between iframe and control bar so it never
 * covers iframe content. Semi-transparent so the audience still sees
 * the page behind it. */
#wt-caption-bar {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--controls-h) + 8px);
    max-width: 70%;
    padding: 10px 20px;
    background: rgba(11, 18, 32, 0.78);
    backdrop-filter: blur(8px);
    border: 1px solid var(--stage-edge);
    border-radius: 999px;
    z-index: var(--z-bar);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 250ms ease-in-out;
    pointer-events: none;
}

#wt-caption-bar[data-wt-visible="true"] {
    opacity: 1;
}

#wt-caption-bar[hidden] { display: none; }

.wt-caption-actor-bar {
    width: 4px;
    align-self: stretch;
    background: var(--actor-color);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--actor-color);
}

.wt-caption-text {
    flex: 1;
    font-size: 18px;
    line-height: 1.6;
    color: var(--stage-ink);
    text-align: start;              /* RTL: renders right-aligned */
    font-weight: 500;
}

/* --------- Inbox tray (bottom ribbon area) --------- */
/* Lives in the documents-ribbon row as a horizontal strip across the
 * bottom, so envelopes never cover iframe content. Desk mode overrides
 * below to enlarge + center for envelope-focused scenes. */
#wt-inbox-tray {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(var(--controls-h) + var(--ribbon-h) - 28px);
    height: 60px;
    z-index: var(--z-bar);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    pointer-events: auto;
    opacity: 0.88;
    transition: transform 550ms cubic-bezier(.4,0,.2,1),
                height 550ms cubic-bezier(.4,0,.2,1),
                opacity 400ms ease,
                bottom 550ms cubic-bezier(.4,0,.2,1);
}
#wt-inbox-tray:hover { opacity: 1; }
#wt-inbox-tray .wt-inbox-item {
    flex: 0 0 auto;
    font-size: 11px;
    padding: 6px 10px;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Desk mode: iframe fades back, inbox tray rises to prominence. */
#wt-stage[data-wt-mode="desk"] #wt-iframe-container {
    opacity: 0.22;
    filter: grayscale(0.4);
    transition: opacity 550ms, filter 550ms;
    pointer-events: none;
}
#wt-stage[data-wt-mode="desk"] #wt-inbox-tray {
    flex-direction: column;
    bottom: auto;
    top: calc(var(--top-bar-h) + 40px);
    left: 50%;
    right: auto;
    width: 440px;
    height: auto;
    max-height: 70vh;
    transform: translateX(-50%);
}
#wt-stage[data-wt-mode="desk"] #wt-inbox-tray .wt-inbox-item {
    max-width: none;
    white-space: normal;
    padding: 10px 14px;
    font-size: 12px;
}
#wt-stage[data-wt-mode="desk"] #wt-documents-ribbon {
    opacity: 0.45;
    transition: opacity 550ms;
}

#wt-inbox-tray:empty { display: none; }

.wt-inbox-item {
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--stage-edge);
    border-radius: 6px;
    font-size: 12px;
    color: var(--stage-ink);
    cursor: pointer;
    transition: border-color 150ms, transform 150ms;
}
.wt-inbox-item:hover {
    border-color: var(--accent-gold);
    transform: translateX(-2px);    /* RTL: nudges toward the stage centre */
}
.wt-inbox-item[data-wt-unread="true"] {
    border-color: var(--accent-gold);
}

@keyframes wt-inbox-bounce {
    0%, 100% { transform: translateY(0); }
    30%      { transform: translateY(-4px); }
    60%      { transform: translateY(-2px); }
}
.wt-inbox-item[data-wt-bounce="true"] {
    animation: wt-inbox-bounce 400ms ease-out;
}

/* --------- Overlay (cursor, envelopes, ripples) --------- */
#wt-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    pointer-events: none;
}

/* Synthetic cursor (drawn on parent, not in iframe) */
.wt-cursor {
    position: absolute;
    width: 22px;
    height: 22px;
    transform: translate(-50%, -50%);
    transition: left 600ms cubic-bezier(.4, .0, .2, 1),
                top  600ms cubic-bezier(.4, .0, .2, 1),
                opacity 250ms;
    pointer-events: none;
}
.wt-cursor svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}
.wt-cursor[data-wt-hidden="true"] { opacity: 0; }

/* Ripple on click */
@keyframes wt-ripple {
    from { transform: translate(-50%, -50%) scale(0.4); opacity: 0.7; }
    to   { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}
.wt-ripple {
    position: absolute;
    width: 42px;
    height: 42px;
    border: 2px solid var(--accent-gold);
    border-radius: 50%;
    animation: wt-ripple 600ms ease-out forwards;
    pointer-events: none;
}

/* Glow for read-gesture target */
.wt-glow {
    position: absolute;
    border-radius: 6px;
    box-shadow: 0 0 0 3px rgba(212, 162, 74, 0.6),
                0 0 18px rgba(212, 162, 74, 0.55);
    pointer-events: none;
    transition: opacity 250ms;
}

/* --------- Envelope (flight + inbox) --------- */
.wt-envelope {
    position: absolute;
    width: 260px;
    height: 108px;
    padding: 10px 14px;
    background: #fefce8;           /* yellow-50 — looks like paper */
    color: #1f2937;
    border: 1px solid #d4a24a;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    font-size: 12px;
    line-height: 1.4;
    transform: translate(-50%, -50%);
    transition: left 1200ms cubic-bezier(.55, .085, .68, .53),
                top  1200ms cubic-bezier(.55, .085, .68, .53),
                transform 200ms, opacity 300ms;
}
.wt-envelope .wt-env-route {
    font-size: 11px;
    color: #78716c;
    margin-bottom: 4px;
}
.wt-envelope .wt-env-subject {
    font-weight: 700;
    margin-bottom: 4px;
}
.wt-envelope .wt-env-preview {
    color: #4b5563;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* --------- Email lightbox (opened envelope, BRIEF §6, §8.2 open_envelope) --------- */
.wt-email-lightbox {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-overlay) + 1);
    background: rgba(0, 0, 0, 0.68);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 250ms;
    pointer-events: none;
}
.wt-email-lightbox[data-wt-visible="true"] {
    opacity: 1;
    pointer-events: auto;
}
.wt-email-lightbox .wt-email-card {
    width: min(720px, 100%);
    max-height: 90vh;
    background: white;
    color: #111827;
    border-radius: 12px;
    overflow: auto;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.5);
    padding: 24px 28px;
}

/* --------- Document lightbox --------- */
.wt-doc-lightbox {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-overlay) + 1);
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 250ms;
    pointer-events: none;
}
.wt-doc-lightbox[data-wt-visible="true"] {
    opacity: 1;
    pointer-events: auto;
}
.wt-doc-lightbox iframe {
    width: min(900px, 100%);
    height: 90vh;
    border: 0;
    background: white;
    border-radius: 6px;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.5);
}

/* --------- Jump-act modal (BRIEF §11.3) --------- */
.wt-jump-modal {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-overlay) + 1);
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    opacity: 0;
    transition: opacity 200ms;
    pointer-events: none;
}
.wt-jump-modal[data-wt-visible="true"] {
    opacity: 1;
    pointer-events: auto;
}
.wt-jump-modal-card {
    width: min(640px, 100%);
    max-height: 80vh;
    background: #0f172a;
    border: 1px solid var(--stage-edge);
    border-radius: 12px;
    overflow: auto;
    padding: 24px;
}
.wt-jump-modal-card h2 {
    color: var(--stage-ink);
    margin-bottom: 16px;
    font-size: 18px;
}
.wt-jump-phase-header {
    margin-top: 16px;
    padding-bottom: 6px;
    color: var(--accent-gold);
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid var(--stage-edge);
}
.wt-jump-act-btn {
    display: block;
    width: 100%;
    text-align: start;
    padding: 10px 14px;
    margin-top: 6px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    color: var(--stage-ink);
    transition: background 150ms;
}
.wt-jump-act-btn:hover { background: rgba(255, 255, 255, 0.08); }

/* --------- Attach / file pseudo-upload indicator --------- */
.wt-attach-ghost {
    position: absolute;
    padding: 6px 10px;
    background: rgba(212, 162, 74, 0.92);
    color: #0b1220;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: wt-doc-appear 400ms ease-out;
}

/* --------- Responsive fallback (not the primary target — demo runs on a big screen) --------- */
@media (max-width: 960px) {
    #wt-iframe-region { padding: 12px 20px 6px; }
    .wt-actor-chip { max-width: 60%; }
    #wt-caption-bar { left: 4%; right: 4%; width: 92%; }
}
