/* ==========================================================================
   The Office — Animated Workspace View
   ========================================================================== */

.office-view {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
}

.office-floor {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    padding-right: 310px;
    position: relative;
    align-items: start;
}

/* ==========================================================================
   Office Desk Card
   ========================================================================== */

.office-desk {
    background: var(--surface);
    border: 1px solid var(--rule);
    overflow: hidden;
    transition: border-color 0.4s, box-shadow 0.4s, opacity 1.5s, max-height 1.5s;
    position: relative;
    opacity: 1;
    max-height: 500px;
}

.office-desk.desk-departing {
    animation: deskDepart 1.5s ease-in forwards;
    pointer-events: none;
}

@keyframes deskDepart {
    0%   { opacity: 1; transform: scaleY(1); max-height: 300px; }
    60%  { opacity: 0; transform: scaleY(0.8); max-height: 200px; }
    100% { opacity: 0; transform: scaleY(0); max-height: 0; margin: 0; padding: 0; }
}

.office-desk.active {
    border-color: var(--agent-color, var(--rule-dark));
    box-shadow: 0 3px 16px rgba(0,0,0,0.1);
}

/* ==========================================================================
   Scene — The animated area
   ========================================================================== */

.office-scene {
    height: 140px;
    background: var(--surface-warm);
    border-bottom: 2px solid var(--agent-color, var(--rule));
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

/* Desk furniture — always visible */
.scene-furniture {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.2rem;
    line-height: 1;
    z-index: 1;
    filter: grayscale(0.3);
}

/* Character — the agent (emoji fallback) */
.scene-character-emoji {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.8rem;
    z-index: 2;
    transition: transform 0.5s ease, opacity 0.3s;
    line-height: 1;
}

/* Character — avatar image */
img.scene-character {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    height: 110px;
    width: auto;
    z-index: 2;
    transition: transform 0.5s ease, opacity 0.3s;
    image-rendering: auto;
    pointer-events: none;
}

/* Object — what they're working with (appears/disappears) */
.scene-object {
    position: absolute;
    font-size: 1.6rem;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.4s, transform 0.4s;
    line-height: 1;
}

.scene-object.visible {
    opacity: 1;
}

/* Object positions */
.scene-object.left {
    bottom: 60px;
    left: 18%;
    transform: rotate(-10deg);
}

.scene-object.right {
    bottom: 60px;
    right: 18%;
    transform: rotate(10deg);
}

.scene-object.above {
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
}

/* Image inside a scene object (e.g. thought-cogs.png) */
.scene-object-img {
    height: 42px;
    width: auto;
    display: block;
    pointer-events: none;
}

/* Thought bubble — sits below the scene, not overlapping it */
.scene-thought {
    display: none;
    font-family: 'Libre Baskerville', Georgia, serif;
    font-style: italic;
    font-size: 0.68rem;
    color: var(--ink-light);
    background: var(--surface-warm);
    border-top: 1px solid var(--rule);
    border-left: 3px solid var(--agent-color, var(--rule));
    padding: 0 10px;
    line-height: 1.4;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.6s ease, padding 0.6s ease, background 0.6s ease;
}

.scene-thought.visible {
    display: block;
}

/* Expanded state — shows full text briefly */
.scene-thought.expanded {
    max-height: 200px;
    padding: 10px 12px;
    background: white;
}

/* Status label — floats above the scene */
.scene-status {
    position: absolute;
    bottom: 6px;
    left: 8px;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--ink-light);
    background: rgba(255,255,255,0.85);
    padding: 2px 7px;
    border-radius: 3px;
    z-index: 5;
    transition: opacity 0.3s;
}

.scene-status .status-icon {
    margin-right: 3px;
}

/* Tool badge in scene */
.scene-tool-badge {
    position: absolute;
    bottom: 6px;
    right: 8px;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.6rem;
    font-weight: 500;
    background: var(--agent-color, var(--ink-light));
    color: white;
    padding: 2px 7px;
    border-radius: 3px;
    z-index: 5;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.3s, transform 0.3s, background 0.3s;
}

.scene-tool-badge.visible {
    opacity: 1;
    transform: translateY(0);
}

.scene-tool-badge.done {
    background: var(--state-active);
}

.scene-tool-badge.fail {
    background: var(--accent);
}

/* Delegation badge — shows who they're communicating with */
.scene-delegation-badge {
    position: absolute;
    top: 6px;
    right: 8px;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.58rem;
    font-weight: 600;
    background: rgba(0, 122, 255, 0.85);
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    z-index: 5;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.3s, transform 0.3s, background 0.3s;
    white-space: nowrap;
}

.scene-delegation-badge.visible {
    opacity: 1;
    transform: translateY(0);
}

.scene-delegation-badge.returning {
    background: rgba(52, 199, 89, 0.85);
}

/* ==========================================================================
   Character Animations
   ========================================================================== */

/* Idle — gentle breathing/rocking */
.office-desk.state-idle .scene-character {
    animation: idleBreathe 3s ease-in-out infinite;
}

@keyframes idleBreathe {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-3px); }
}

/* Idle slow — deeper breathing, settling in */
.office-desk.state-idle-slow .scene-character {
    animation: idleBreatheSlow 5s ease-in-out infinite;
}

@keyframes idleBreatheSlow {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-2px); }
}

/* Dormant — no animation, greyed out */
.office-desk.desk-dormant {
    opacity: 0.45;
    filter: grayscale(0.7);
    transition: opacity 3s, filter 3s;
}

.office-desk.state-dormant .scene-character {
    animation: none;
    opacity: 0.5;
}

.office-desk.state-dormant .scene-object {
    display: none;
}

/* Typing — slight side-to-side */
.office-desk.state-typing .scene-character {
    animation: typingBob 0.6s ease-in-out infinite;
}

@keyframes typingBob {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(0deg); }
    25% { transform: translateX(-50%) translateY(-2px) rotate(-2deg); }
    75% { transform: translateX(-50%) translateY(-2px) rotate(2deg); }
}

/* Reading — lean forward slightly */
.office-desk.state-reading .scene-character {
    animation: readingLean 2s ease-in-out infinite;
}

@keyframes readingLean {
    0%, 100% { transform: translateX(-50%) rotate(0deg) translateY(0); }
    50% { transform: translateX(-50%) rotate(3deg) translateY(2px); }
}

/* Thinking — look up */
.office-desk.state-thinking .scene-character {
    animation: thinkingLook 2.5s ease-in-out infinite;
}

@keyframes thinkingLook {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    40% { transform: translateX(-50%) translateY(-8px); }
    60% { transform: translateX(-50%) translateY(-8px); }
}

/* Writing — focused bob */
.office-desk.state-writing .scene-character {
    animation: writingFocus 1s ease-in-out infinite;
}

@keyframes writingFocus {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(0); }
    50% { transform: translateX(-50%) translateY(2px) rotate(3deg); }
}

/* Sending — reach out */
.office-desk.state-sending .scene-character {
    animation: sendingReach 1.2s ease-in-out 1;
}

@keyframes sendingReach {
    0% { transform: translateX(-50%) translateY(0); }
    40% { transform: translateX(-40%) translateY(-4px); }
    100% { transform: translateX(-50%) translateY(0); }
}

/* Sleeping — gentle sway */
.office-desk.state-sleeping .scene-character {
    animation: sleepingSway 4s ease-in-out infinite;
}

@keyframes sleepingSway {
    0%, 100% { transform: translateX(-50%) rotate(-4deg); }
    50% { transform: translateX(-50%) rotate(4deg); }
}

/* Error — shake */
.office-desk.state-error .scene-character {
    animation: errorShake 0.4s ease-in-out 3;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(-50%); }
    25% { transform: translateX(calc(-50% - 6px)); }
    75% { transform: translateX(calc(-50% + 6px)); }
}

/* Success flash on the whole scene */
/* Success flash removed — tick emoji is sufficient */

/* Desk border pulse removed — too distracting */

/* ==========================================================================
   Object Animations
   ========================================================================== */

/* Paper appears from below */
.scene-object.anim-paper-in {
    animation: paperIn 0.5s ease-out forwards;
}

@keyframes paperIn {
    from { opacity: 0; transform: rotate(-10deg) translateY(20px); }
    to { opacity: 1; transform: rotate(-10deg) translateY(0); }
}

/* Screen glow */
.scene-object.anim-screen-glow {
    animation: screenGlow 1.5s ease-in-out infinite;
}

@keyframes screenGlow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}

/* Typing dots in scene */
.scene-typing-dots {
    position: absolute;
    bottom: 45px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 4px;
    z-index: 3;
}

.office-desk.state-typing .scene-typing-dots,
.office-desk.state-writing .scene-typing-dots {
    display: flex;
}

.scene-typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--agent-color, var(--ink-light));
    animation: sceneDotBounce 1.2s infinite;
}

.scene-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.scene-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sceneDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ZZZ for sleeping */
.scene-zzz {
    position: absolute;
    top: 15px;
    right: 25%;
    font-size: 1.1rem;
    opacity: 0;
    z-index: 4;
    display: none;
}

/* ZZZ no longer shown — progressive idle uses drink PNGs instead */

@keyframes zzzFloat {
    0% { opacity: 0; transform: translateY(10px) scale(0.7); }
    30% { opacity: 0.8; }
    70% { opacity: 0.6; }
    100% { opacity: 0; transform: translateY(-15px) scale(1.1); }
}

/* Searching magnifier animation — small circular sweep */
.scene-object.searching img {
    animation: searchSweep 1.2s ease-in-out infinite;
    transform-origin: center center;
}

@keyframes searchSweep {
    0%   { transform: translate(0, 0) rotate(0deg); }
    25%  { transform: translate(6px, -4px) rotate(8deg); }
    50%  { transform: translate(-2px, -6px) rotate(-5deg); }
    75%  { transform: translate(-6px, 2px) rotate(-8deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* ==========================================================================
   Office Nameplate (below scene)
   ========================================================================== */

.office-nameplate {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
}

.office-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--agent-color, var(--rule));
    flex-shrink: 0;
}

.office-lamp {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--state-idle);
    transition: background 0.4s, box-shadow 0.4s;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    z-index: 5;
}

.office-desk.active .office-lamp {
    background: var(--state-active);
    box-shadow: 0 0 6px rgba(61, 107, 74, 0.5);
}

.office-name-group {
    flex: 1;
    min-width: 0;
}

.office-name {
    font-family: 'Inter', -apple-system, sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--ink);
}

.office-instance {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.62rem;
    color: var(--ink-light);
    font-style: italic;
}

/* ==========================================================================
   Office Mini Log
   ========================================================================== */

.office-log {
    border-top: 1px solid var(--rule);
    padding: 0 12px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.office-desk.log-open .office-log {
    padding: 6px 12px;
    max-height: 80px;
    overflow-y: auto;
}

.office-log::-webkit-scrollbar {
    width: 3px;
}

.office-log::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 2px;
}

.office-log .log-entry {
    display: flex;
    align-items: baseline;
    gap: 5px;
    padding: 1px 0;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.62rem;
    color: var(--ink-light);
    line-height: 1.3;
}

.office-log .log-time {
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    opacity: 0.5;
    min-width: 44px;
}

.office-log .log-icon {
    flex-shrink: 0;
    width: 12px;
    text-align: center;
    font-size: 0.62rem;
}

.office-log .log-msg {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.office-log .log-entry.new {
    animation: logFlash 1.5s ease-out;
}

/* ==========================================================================
   Timeline Bar — integrated replay controls
   ========================================================================== */

.timeline-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
    padding: 6px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.timeline-top-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.timeline-info {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.68rem;
    color: var(--ink-light);
    flex: 1;
}

.timeline-speed {
    display: flex;
    gap: 2px;
}

.speed-btn {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.65rem;
    font-weight: 500;
    padding: 3px 8px;
    border: 1px solid var(--rule);
    background: var(--surface-warm);
    color: var(--ink-light);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.speed-btn:first-child { border-radius: 3px 0 0 3px; }
.speed-btn:last-child { border-radius: 0 3px 3px 0; }

.speed-btn.active {
    background: var(--ink);
    color: white;
    border-color: var(--ink);
}

.speed-btn:hover:not(.active) {
    background: var(--rule);
    color: var(--ink);
}

.timeline-bottom-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.replay-btn {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border: 1px solid var(--rule-dark);
    background: var(--surface-warm);
    color: var(--ink);
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.replay-btn:hover:not(:disabled) {
    background: var(--ink);
    color: white;
}

.replay-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.replay-btn.live-btn {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 4px 10px;
    background: var(--surface-warm);
    color: var(--ink-light);
    border-color: var(--rule);
}

.replay-btn.live-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.replay-timeline {
    flex: 1;
    height: 20px;
    position: relative;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    background: var(--rule);
}

.replay-heatmap {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 4px;
}

.replay-thumb {
    position: absolute;
    top: 50%;
    left: 100%;
    width: 3px;
    height: 24px;
    background: var(--ink);
    transform: translate(-50%, -50%);
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    pointer-events: none;
    transition: left 0.05s linear;
}

.replay-live-marker {
    position: absolute;
    top: 0;
    right: 0;
    width: 3px;
    height: 100%;
    background: var(--state-active);
    opacity: 0.6;
    border-radius: 0 4px 4px 0;
}

.replay-timeline.disabled {
    opacity: 0.4;
    cursor: default;
}

.replay-time {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-light);
    min-width: 55px;
    text-align: right;
}

/* Replay mode indicator on masthead */
.edition-label.replay-mode {
    color: var(--accent);
    animation: replayPulse 2s ease-in-out infinite;
}

@keyframes replayPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==========================================================================
   Delegation Paper Plane Flight
   ========================================================================== */

.paper-plane {
    position: absolute;
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translate(-50%, -50%);
    opacity: 0;
}

.paper-plane .plane-icon {
    height: 36px;
    width: auto;
    transform: rotate(var(--plane-angle, 0deg));
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    transition: none;
    pointer-events: none;
}

.paper-plane .plane-label {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.58rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
    margin-top: 2px;
}

.paper-plane.sending .plane-label {
    background: rgba(0, 122, 255, 0.85);
}

.paper-plane.returning .plane-label {
    background: rgba(52, 199, 89, 0.85);
}

/* Flight animation */
.paper-plane.flying {
    opacity: 1;
    animation: planefly 1.2s ease-in-out forwards;
}

@keyframes planefly {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(
            calc(-50% + var(--flight-dx) * 0.5),
            calc(-50% + var(--flight-dy) * 0.5 - 40px)
        ) scale(1.1);
        opacity: 1;
    }
    85% {
        opacity: 1;
    }
    100% {
        transform: translate(
            calc(-50% + var(--flight-dx)),
            calc(-50% + var(--flight-dy))
        ) scale(0.6);
        opacity: 0;
    }
}

/* Receiving desk — subtle glow pulse when a plane is incoming */
.office-desk.desk-receiving {
    animation: receivePulse 1.2s ease-out 1;
}

@keyframes receivePulse {
    0% { box-shadow: 0 3px 16px rgba(0,0,0,0.1); }
    50% { box-shadow: 0 0 20px rgba(0, 122, 255, 0.3), 0 0 40px rgba(0, 122, 255, 0.1); }
    100% { box-shadow: 0 3px 16px rgba(0,0,0,0.1); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    .office-floor {
        grid-template-columns: 1fr;
    }

    .office-scene {
        height: 120px;
    }
}

/* ==========================================================================
   Narrative Phone
   ========================================================================== */

.narrative-phone {
    position: fixed;
    right: 24px;
    top: 180px;
    width: 280px;
    height: 520px;
    background: #1a1a1a;
    border-radius: 32px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.25), inset 0 0 0 2px #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 50;
    font-family: 'Inter', -apple-system, sans-serif;
}

.phone-notch {
    width: 100px;
    height: 6px;
    background: #333;
    border-radius: 3px;
    margin: 10px auto 0;
    flex-shrink: 0;
}

.phone-header {
    padding: 8px 16px 10px;
    text-align: center;
    flex-shrink: 0;
    border-bottom: 1px solid #2a2a2a;
}

.phone-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.phone-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.phone-messages::-webkit-scrollbar {
    width: 3px;
}

.phone-messages::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}

/* Individual message bubble */
.phone-msg {
    max-width: 92%;
    padding: 8px 11px;
    border-radius: 14px;
    font-size: 0.68rem;
    line-height: 1.45;
    color: #f0f0f0;
    position: relative;
    animation: msgSlideIn 0.3s ease-out;
    word-wrap: break-word;
}

.phone-msg-name {
    font-size: 0.58rem;
    font-weight: 700;
    margin-bottom: 3px;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.phone-msg-time {
    font-size: 0.52rem;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}

.phone-msg-text {
    font-family: 'Libre Baskerville', Georgia, serif;
    font-style: italic;
}

/* Time separator between messages */
.phone-time-sep {
    text-align: center;
    font-size: 0.55rem;
    color: #555;
    padding: 4px 0;
    flex-shrink: 0;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
