/* Anansi Main Styles */
/* Utilities */
.hidden {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    overflow: hidden;
}

/* Shell Layout */
.app-shell {
    display: grid;
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    grid-template-rows: 48px 1fr;
    grid-template-columns: 200px 1fr 300px;
    grid-template-areas:
        "topbar topbar topbar"
        "nav    main   lens";
    transition: grid-template-columns 0.2s ease;
}

.app-shell.lens-collapsed {
    grid-template-columns: 200px 1fr 0px;
}

.app-shell.lens-collapsed .web-lens {
    display: none;
}

/* Collapsed States */
/* Note: JavaScript will toggle classes or grid definition */

/* Top Bar */
.topbar {
    grid-area: topbar;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    z-index: 10;
}

.topbar-left,
.topbar-center,
.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.topbar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.app-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    font-family: var(--font-serif);
    font-size: var(--text-lg);
}

.app-logo-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

/* Theme Switching for Logo */
[data-theme="light"] .app-logo-img {
    content: url('../assets/logo_light.png');
}

.project-name {
    font-weight: 500;
    font-size: var(--text-sm);
}

.environment-badge {
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background-color: var(--accent-muted);
    color: var(--accent-primary);
    text-transform: uppercase;
}

/* Navigation */
.web-navigator {
    grid-area: nav;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.nav-sections {
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, color 0.1s;
}

.nav-item:hover {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-weight: 500;
}

.nav-item-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Weaving Table (Main) */
.weaving-table {
    grid-area: main;
    background-color: var(--bg-app);
    overflow: hidden;
    /* Prevent outer scroll, let panel-content handle it */
    position: relative;
    display: flex;
    flex-direction: column;
}

.panel-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    /* Constrain reading width slightly */
    margin: 0 auto;
    width: 100%;
    padding: var(--space-6);
    box-sizing: border-box;
    min-height: 0;
    /* Critical: Allow flex children to shrink below content size */
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-6);
}

.panel-title {
    margin: 0;
    font-size: 24px;
    font-weight: 400;
    font-family: var(--font-serif);
}

.panel-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.panel-actions {
    display: flex;
    gap: var(--space-2);
}

/* Web Lens */
.web-lens {
    grid-area: lens;
    background-color: var(--bg-panel);
    border-left: 1px solid var(--border-subtle);
    overflow-y: auto;
}

.lens-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 500;
    font-size: var(--text-sm);
}

.lens-content {
    padding: var(--space-4);
}

/* Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background-color: var(--bg-surface);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-elevated);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.btn-icon {
    padding: 6px;
    width: 32px;
    height: 32px;
}

.card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-4);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card-header {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 500;
    font-size: var(--text-sm);
    display: flex;
    justify-content: space-between;
}

.card-body {
    padding: var(--space-4);
}

/* Forms */
.form-group {
    margin-bottom: var(--space-4);
}

.label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    box-sizing: border-box;
}

.input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ======================== */
/* UX Elevation Additions   */
/* ======================== */

/* === Empty State Component === */
.empty-state-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-6);
    background: var(--bg-surface);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-lg);
    min-height: 200px;
    animation: fadeIn 0.3s ease-out;
}

.empty-state-card .empty-icon {
    width: 48px;
    height: 48px;
    color: var(--accent-primary);
    opacity: 0.7;
    margin-bottom: var(--space-4);
}

.empty-state-card .empty-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-card .empty-description {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    max-width: 300px;
    margin-bottom: var(--space-4);
}

.empty-state-card .btn {
    margin-top: var(--space-2);
}

/* === Panel Transitions === */
.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Critical: Allow flex children to shrink below content size */
    overflow-y: auto;
    /* Let individual panel grids/cards handle scrolling */
    animation: panelFadeIn 0.2s ease-out;
}

@keyframes panelFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* === Tooltips === */
.nav-item {
    position: relative;
}

.nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    background: var(--ink-900);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 100;
    box-shadow: var(--shadow-soft);
}

.nav-item:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(4px);
}

.nav-item:not([data-tooltip])::after {
    display: none;
}

/* === Micro-animations for Buttons === */
.btn {
    transition: all 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 108, 255, 0.3);
}

/* Button Success State */
.btn.btn-success-flash {
    background-color: var(--status-success) !important;
    border-color: var(--status-success) !important;
    animation: successPulse 0.5s ease-out;
}

@keyframes successPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(95, 212, 156, 0.5);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(95, 212, 156, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(95, 212, 156, 0);
    }
}

/* === Card Hover Effects === */
.card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* === Toast Enhancements === */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    min-width: 280px;
    max-width: 400px;
    box-shadow: var(--shadow-soft);
    animation: toastSlideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.toast.toast-success {
    border-left: 4px solid var(--status-success);
}

.toast.toast-error {
    border-left: 4px solid var(--status-error);
}

.toast.toast-warning {
    border-left: 4px solid var(--status-warning);
}

.toast .toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.toast-success .toast-icon {
    color: var(--status-success);
}

.toast.toast-error .toast-icon {
    color: var(--status-error);
}

.toast.toast-warning .toast-icon {
    color: var(--status-warning);
}

.toast .toast-message {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* === Navigation Category Tooltips === */
.nav-header {
    cursor: default;
    position: relative;
}

.nav-header[data-hint]::after {
    content: attr(data-hint);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--ink-800);
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
}

.nav-header:hover[data-hint]::after {
    opacity: 1;
}

/* === Collapsible Details for Settings === */
details.settings-group {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
    overflow: hidden;
}

details.settings-group summary {
    padding: var(--space-3);
    background: var(--bg-surface);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    user-select: none;
    transition: background 0.1s ease;
}

details.settings-group summary:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

details.settings-group summary::before {
    content: '▸';
    font-size: 10px;
    transition: transform 0.2s ease;
}

details.settings-group[open] summary::before {
    transform: rotate(90deg);
}

details.settings-group .settings-content {
    padding: var(--space-3);
}

/* === Token Badge === */
.token-badge {
    display: inline-block;
    font-size: 9px;
    color: var(--text-muted);
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-weight: 500;
    margin-left: 4px;
    border: 1px solid var(--border-subtle);
}

.token-badge.warning {
    color: var(--status-warning);
    border-color: var(--status-warning);
}

.token-badge.error {
    color: var(--status-error);
    border-color: var(--status-error);
}

/* === Keyboard Shortcut Badges === */
kbd {
    background: var(--bg-surface);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    border: 1px solid var(--border-default);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* === Unsaved Changes Indicator === */
.btn-unsaved {
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(218, 165, 32, 0.7);
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(218, 165, 32, 0.7);
    }

    50% {
        box-shadow: 0 0 0 6px rgba(218, 165, 32, 0);
    }
}


/* =========================== */
/* Spindle Chat Components     */
/* =========================== */

/* Chat Container */
.chat-log {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Wrapper */
.chat-message {
    display: flex;
    position: relative;
    animation: chatSlideIn 0.2s ease-out;
}

.chat-message-user {
    justify-content: flex-end;
}

.chat-message-model,
.chat-message-system {
    justify-content: flex-start;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Bubble */
.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble-user {
    background: var(--accent-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble-model {
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 4px;
}

.chat-bubble-system {
    background: transparent;
    color: var(--text-muted);
    border-left: 2px solid var(--status-warning);
    font-style: italic;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 0;
}

/* Role Label */
.chat-role {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    margin-bottom: 4px;
}

/* Edited Indicator */
.chat-edited {
    font-size: 9px;
    opacity: 0.5;
    margin-left: 8px;
    font-style: italic;
}

/* Timestamp on hover */
.chat-timestamp {
    font-size: 9px;
    opacity: 0;
    margin-left: 8px;
    transition: opacity 0.15s ease;
}

.chat-bubble:hover .chat-timestamp {
    opacity: 0.5;
}

/* === Rich Text Formatting === */
.chat-bubble strong {
    font-weight: 700;
}

.chat-bubble em {
    font-style: italic;
}

.chat-bubble del {
    text-decoration: line-through;
    opacity: 0.7;
}

.chat-bubble .chat-code-inline {
    background: rgba(0, 0, 0, 0.15);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.chat-bubble-user .chat-code-inline {
    background: rgba(255, 255, 255, 0.2);
}

.chat-bubble .chat-code-block {
    background: var(--ink-900);
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-primary);
}

.chat-bubble-user .chat-code-block {
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
}

/* === Message Actions === */
.chat-actions {
    display: flex;
    gap: 4px;
    position: absolute;
    top: -24px;
    right: 8px;
    opacity: 0;
    transition: opacity 0.15s ease;
    background: var(--bg-panel);
    border-radius: 6px;
    padding: 2px 4px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-subtle);
}

.chat-message:hover .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    transition: all 0.1s ease;
}

.chat-action-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.chat-action-btn.danger:hover {
    color: var(--status-error);
}

/* === Edit Mode === */
.chat-edit-textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    padding: 8px;
    border: 1px solid var(--accent-primary);
    border-radius: 8px;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
}

.chat-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

/* Mobile Compatibility: Always show actions on touch/small screens */
@media (max-width: 768px),
(hover: none) {
    .chat-actions {
        opacity: 1 !important;
        background: transparent;
    }

    /* Mobile: Increase touch targets */
    .btn,
    .nav-item {
        min-height: 44px;
        /* Apple Human Interface Guidelines */
    }

    .btn-icon {
        width: 44px;
        height: 44px;
        padding: 10px;
        /* Center the icon */
    }
}

/* ================================ */
/* Mobile Layout: Stacked + Drawer  */
/* ================================ */
@media (max-width: 768px) {

    /* Stack the layout */
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }

    /* Topbar adjustments */
    .topbar {
        height: 56px;
        padding: 0 var(--space-2);
    }

    .topbar-left {
        gap: 4px;
    }

    /* Make logo smaller on mobile */
    .app-logo-img {
        height: 24px !important;
    }

    .app-logo span {
        font-size: 14px;
    }

    /* Hide version number on mobile */
    .app-logo span span {
        display: none;
    }

    /* Truncate project name - remove absolute positioning on mobile */
    .topbar-center {
        position: static;
        transform: none;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        justify-content: center;
    }

    .project-name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        display: block;
        font-size: 13px;
    }

    /* Ensure topbar-right stays on top */
    .topbar-right {
        flex-shrink: 0;
        z-index: 5;
    }

    /* Hide text buttons on mobile, keep icon buttons */
    .topbar-right .btn-sm {
        display: none;
    }

    /* Project name becomes clickable */
    #project-header {
        cursor: pointer;
    }

    /* Off-canvas Navigation Drawer */
    .web-navigator {
        position: fixed;
        left: -280px;
        top: 56px;
        bottom: 0;
        width: 280px;
        z-index: 200;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .app-shell.nav-open .web-navigator {
        left: 0;
    }

    /* Overlay when nav is open */
    .app-shell.nav-open::before {
        content: '';
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

    /* Web Lens as slide-out drawer from right */
    .web-lens {
        position: fixed;
        right: -280px;
        top: 56px;
        bottom: 0;
        width: 280px;
        z-index: 200;
        transition: right 0.3s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .app-shell.lens-open .web-lens {
        right: 0;
    }

    /* Overlay when lens is open */
    .app-shell.lens-open::after {
        content: '';
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

    /* Panel container - full bleed on mobile */
    .panel-container {
        padding: var(--space-3);
    }

    .panel-header {
        flex-direction: column;
        gap: var(--space-2);
        margin-bottom: var(--space-4);
    }

    .panel-title {
        font-size: 18px;
    }

    .panel-subtitle {
        font-size: 11px;
    }

    /* Cards full-width and compact */
    .card {
        margin-bottom: var(--space-3);
    }

    .card-body {
        padding: var(--space-3);
    }

    .card-header {
        padding: var(--space-2) var(--space-3);
    }

    /* ================================ */
    /* Force inline grids to stack!     */
    /* ================================ */

    /* Stats grid: force 2-column on mobile */
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    /* Two-column layouts: force single column */
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Flexible grids in forms */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Max-width containers - full width */
    [style*="max-width: 1400px"] {
        max-width: 100% !important;
        padding: 0 !important;
    }

    /* Header layouts - stack vertically */
    [style*="justify-content: space-between"][style*="align-items: flex-start"] {
        flex-direction: column !important;
        gap: 16px !important;
    }

    /* Token/stat cards - compact sizing */
    .card[style*="padding: 16px"] {
        padding: 12px !important;
    }

    .card[style*="padding: 16px"] [style*="font-size: 24px"] {
        font-size: 20px !important;
    }

    /* Form inputs - full width */
    .form-group {
        margin-bottom: var(--space-3);
    }

    .input,
    .input[style] {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Buttons - larger touch targets */
    .btn {
        min-height: 44px;
        padding: var(--space-2) var(--space-3);
    }

    .btn-icon {
        width: 44px;
        height: 44px;
    }

    /* Badge spacing */
    .badge {
        font-size: 10px;
        padding: 4px 8px;
    }

    /* Flexbox wrapping for badges */
    [style*="display: flex"][style*="gap: 12px"][style*="flex-wrap: wrap"] {
        gap: 8px !important;
    }

    /* Cover image - smaller on mobile */
    #project-cover-preview {
        width: 80px !important;
        height: 80px !important;
    }

    /* Toast positioning for mobile */
    #toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }
}

/* Orientation Lock Overlay */
.orientation-lock {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    flex-direction: column;
}

/* Only show overlay on portrait mobile devices */
@media screen and (max-width: 768px) and (orientation: portrait) {
    .orientation-lock {
        display: flex;
    }

    /* Prevent scrolling of main app when locked */
    .app-shell {
        overflow: hidden;
        height: 100vh;
        filter: blur(5px);
    }
}

/* ======================== */
/* Gallery Lightbox         */
/* ======================== */
.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lightboxFadeIn 0.2s ease-out;
    backdrop-filter: blur(8px);
}

@keyframes lightboxFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.gallery-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: lightboxZoomIn 0.25s ease-out;
}

@keyframes lightboxZoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.gallery-lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.gallery-lightbox-close {
    position: absolute;
    top: -40px;
    right: -10px;
    width: 36px;
    height: 36px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 10;
}

.gallery-lightbox-close:hover {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.1);
}

.gallery-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 10;
}

.gallery-lightbox-nav:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

.gallery-lightbox-nav.prev {
    left: -60px;
}

.gallery-lightbox-nav.next {
    right: -60px;
}

.gallery-lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.gallery-lightbox-nav:disabled:hover {
    background: var(--bg-panel);
    color: var(--text-primary);
    transform: translateY(-50%);
}

.gallery-lightbox-counter {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-secondary);
    font-size: 12px;
    background: var(--bg-panel);
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
}

.gallery-lightbox-caption {
    position: absolute;
    bottom: -70px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-muted);
    font-size: 11px;
    max-width: 400px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Lightbox thumbnail click hint */
.gallery-thumb {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gallery-thumb:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Primary image hover hint */
#gallery-primary img {
    cursor: pointer;
    transition: transform 0.15s ease;
}

#gallery-primary img:hover {
    transform: scale(1.02);
}

/* Mobile lightbox adjustments */
@media screen and (max-width: 768px) {
    .gallery-lightbox-nav.prev {
        left: 10px;
    }

    .gallery-lightbox-nav.next {
        right: 10px;
    }

    .gallery-lightbox-close {
        top: 10px;
        right: 10px;
    }

    .gallery-lightbox-content {
        max-width: 95vw;
    }
}

/* ======================== */
/* Procedural Avatar FX     */
/* ======================== */

/* Base Avatar Container */
.chat-avatar-frame {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid transparent;
    box-sizing: border-box;
    /* Ensure no layout shift when border color changes */
}

/* Joy: Bounce + Gold Glow */
.avatar-pulse-joy {
    animation: avatarBounce 0.6s infinite alternate;
    border-color: #FFD700;
    /* Gold */
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

@keyframes avatarBounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-4px);
    }
}

/* Anger: Shake + Red Glow */
.avatar-pulse-anger {
    animation: avatarShake 0.1s infinite;
    border-color: #FF4444;
    /* Red */
    box-shadow: 0 0 8px rgba(255, 68, 68, 0.6);
}

@keyframes avatarShake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

/* Sadness: Desaturate + Blue Tint + Droop */
.avatar-pulse-sad {
    filter: grayscale(0.6) sepia(0.2) hue-rotate(180deg) saturate(1.5);
    border-color: #4488FF;
    /* Blue */
    opacity: 0.8;
    transform: scale(0.95) translateY(2px);
}

/* Fear: Shiver + Purple Glow */
.avatar-pulse-fear {
    animation: avatarShiver 0.2s infinite;
    border-color: #9944FF;
    /* Purple */
    box-shadow: 0 0 12px rgba(153, 68, 255, 0.4);
}

@keyframes avatarShiver {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-2px);
    }

    75% {
        transform: translateX(2px);
    }

    100% {
        transform: translateX(0);
    }
}

/* Surprise: Scale Up + Orange Glow */
.avatar-pulse-surprise {
    border-color: #FF8800;
    /* Orange */
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 136, 0, 0.5);
}

/* Love/Eros: Heartbeat + Pink Glow */
.avatar-pulse-love {
    animation: avatarHeartbeat 1.2s infinite;
    border-color: #FF66AA;
    /* Pink */
    box-shadow: 0 0 10px rgba(255, 102, 170, 0.5);
}

@keyframes avatarHeartbeat {
    0% {
        transform: scale(1);
    }

    14% {
        transform: scale(1.1);
    }

    28% {
        transform: scale(1);
    }

    42% {
        transform: scale(1.2);
    }

    70% {
        transform: scale(1);
    }
}

/* Relaxed/Chill: Slight Float + Green Glow */
.avatar-pulse-relaxed {
    animation: avatarFloat 3s ease-in-out infinite;
    border-color: #44CC88;
    /* Green */
}

@keyframes avatarFloat {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }

    100% {
        transform: translateY(0);
    }
}

/* ======================== */
/* Director's Console       */
/* ======================== */
.director-toolbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 8px 12px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 11px;
    margin-bottom: 8px;
    /* Spacing from chat area */
    border-radius: var(--radius-md);
    margin: 8px;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.director-label {
    font-weight: bold;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 9px;
    margin-right: 4px;
}

.director-group {
    display: flex;
    align-items: center;
    gap: 4px;
    border-right: 1px solid var(--border-subtle);
    padding-right: 12px;
}

.director-group:last-child {
    border-right: none;
    flex: 1;
    /* Expand last group (prompt input) */
}

.director-select {
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
}

.director-select:hover {
    border-color: var(--accent-primary);
}

/* Fix dropdown option visibility */
.director-select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.director-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.1s;
}

.director-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent-primary);
}

.director-input {
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    width: 100%;
}

.director-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Collapsed state */
.director-toolbar.collapsed .director-group {
    display: none;
}

.director-toolbar.collapsed {
    width: auto;
    display: inline-flex;
    padding: 4px 8px;
    border: none;
    background: transparent;
    box-shadow: none;
}

/* === Drag-and-Drop Image Upload === */
.drag-over {
    outline: 2px dashed var(--accent-primary) !important;
    outline-offset: -2px;
    background: rgba(218, 165, 32, 0.08) !important;
    transition: outline 0.15s ease, background 0.15s ease;
}

/* Fixed Toast Container */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 250px;
    pointer-events: auto;
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.success {
    border-left: 4px solid var(--accent-success);
}

.toast.error {
    border-left: 4px solid var(--accent-danger);
}

.toast.info {
    border-left: 4px solid var(--accent-primary);
}

.toast.warning {
    border-left: 4px solid var(--accent-warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden !important;
    position: relative;
    width: 100%;
}