/* App Layout Grid */
.app-layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* ==========================================================================
   M3 Navigation Drawer (Sidebar)
   ========================================================================== */
.sidebar {
    width: 280px; /* Slightly wider for elegant drawer proportions */
    height: 100%;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: var(--transition-m3);
    z-index: 100;
    /* Flat square drawer shape on desktop */
    border-radius: 0;
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    font-size: 1.4rem;
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.brand h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    display: none; /* Desktop hidden */
}

.sidebar-close-btn:hover {
    color: var(--text-primary);
}

.sidebar-actions {
    padding: 20px;
}

/* M3 Extended FAB Button styling */
.sidebar-btn {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 14px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--border-radius-m); /* Squircle style */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition-m3);
    font-family: inherit;
}

.sidebar-btn.btn-neon {
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-tertiary) 100%);
    border: none;
    color: var(--accent-text);
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.25);
    border-radius: 20px; /* Playful squircle M3 Extended FAB */
}

.sidebar-btn.btn-neon:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent-tertiary) 100%);
    box-shadow: 0 8px 20px rgba(56, 189, 248, 0.4);
    transform: scale(1.03) translateY(-1px);
    color: var(--accent-text);
}

.sidebar-btn.btn-neon:active {
    transform: scale(0.97) translateY(0);
}

.sidebar-icon {
    width: 18px;
    height: 18px;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-section-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 10px 12px 6px;
    letter-spacing: 0.8px;
}

/* M3 Navigation Pill sidebar items */
.sidebar-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 12px 18px;
    font-size: 0.92rem;
    font-weight: 500;
    border-radius: var(--border-radius-pill); /* Pill shapes */
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    transition: var(--transition-m3);
    width: 100%;
    font-family: inherit;
    position: relative;
}

.sidebar-item:hover {
    background-color: var(--accent-dim);
    color: var(--accent-color);
}

.sidebar-item:hover .sidebar-icon {
    color: var(--accent-color);
}

/* Sidebar status dot */
.sidebar-item .status-dot {
    position: relative;
    margin-left: auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-danger); /* Crimson warning dot */
    animation: statusPulseRose 2s infinite;
    flex-shrink: 0;
}

.sidebar-item .status-dot.active {
    background-color: #5ce69c; /* Soft M3 green */
    animation: statusPulseGreen 2s infinite;
}

/* Chat History List styling */
.chats-list-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    margin-top: 4px;
}

.chat-list-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 14px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    transition: var(--transition-m3);
    width: 100%;
    font-family: inherit;
    position: relative;
    user-select: none;
    align-items: flex-start;
    padding-right: 56px;
}

.chat-list-item:hover {
    background-color: var(--accent-dim);
    color: var(--text-primary);
}

.chat-list-item.active {
    background-color: var(--accent-dim);
    color: var(--accent-color);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.15);
}

.chat-item-icon {
    width: 16px;
    height: 16px;
    color: inherit;
    opacity: 0.7;
    flex-shrink: 0;
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    white-space: normal;
    text-overflow: ellipsis;
    line-height: 1.25;
    pointer-events: none; /* Let clicks pass through to parent button */
    min-width: 0;
    padding-top: 1px;
}

.chat-item-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 4px;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.chat-item-rename-input {
    flex: 1;
    min-width: 0;
    background-color: #0f172a; /* Slightly darker container backdrop for input readability */
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px; /* Organic Squircle rounding */
    padding: 4px 8px;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: var(--transition-m3);
}

.chat-item-rename-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow), inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.chat-delete-btn {
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-m3);
    flex-shrink: 0;
}

.chat-list-item:hover .chat-delete-btn {
    opacity: 0.7;
}

.chat-list-item:hover .chat-delete-btn:hover {
    opacity: 1;
    color: var(--accent-danger);
    background-color: var(--accent-danger-dim);
}

.chat-rename-btn {
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-m3);
    flex-shrink: 0;
    margin-right: 2px;
}

.chat-list-item:hover .chat-rename-btn {
    opacity: 0.7;
}

.chat-list-item:hover .chat-rename-btn:hover {
    opacity: 1;
    color: var(--accent-color);
    background-color: var(--accent-dim);
}

.sidebar-settings {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.status-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator-dot.online {
    background-color: var(--accent-color);
    box-shadow: 0 0 8px var(--accent-color);
}

/* ==========================================================================
   Main Content Workspace Styling
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Top bar header */
.chat-header {
    height: 64px;
    background-color: transparent; /* Seamless top header */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    z-index: 50;
}

.header-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: none; /* Desktop hidden */
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 50%;
    transition: var(--transition-m3);
}

.header-btn:hover {
    background-color: var(--accent-dim);
    color: var(--accent-color);
}

.header-icon {
    width: 22px;
    height: 22px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .header-title {
        margin: 0;
    }
}

/* Expressive gradient text for LoomScribe */
.header-title h3 {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 32px;
    justify-content: flex-end;
}

.header-btn.visible {
    display: flex !important;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 15px 0 40px rgba(0, 0, 0, 0.6);
    }
    
    .sidebar-close-btn {
        display: block; /* Show dismiss cross-out button */
    }

    .header-btn {
        display: flex; /* Show menu toggle bars */
    }
}

/* ==========================================================================
   Toast Notifications Styling
   ========================================================================== */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    max-width: 400px;
    padding: 14px 20px;
    background: rgba(26, 27, 38, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: #fff;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.toast-success {
    border-left: 4px solid #10b981;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-warning {
    border-left: 4px solid #f59e0b;
}

.toast-info {
    border-left: 4px solid #3b82f6;
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-message {
    line-height: 1.4;
    word-break: break-word;
}

/* Background Streaming Indicator in Sidebar */
@keyframes neonPulseGreen {
    0% { opacity: 0.3; transform: scale(0.9); text-shadow: 0 0 2px rgba(92, 230, 156, 0.4); }
    50% { opacity: 1; transform: scale(1.15); text-shadow: 0 0 8px rgba(92, 230, 156, 0.9), 0 0 12px rgba(92, 230, 156, 0.6); }
    100% { opacity: 0.3; transform: scale(0.9); text-shadow: 0 0 2px rgba(92, 230, 156, 0.4); }
}

.streaming-indicator-dot {
    display: inline-block;
    color: #5ce69c;
    font-weight: bold;
    font-size: 0.95rem;
    line-height: 1;
    margin-left: 8px;
    animation: neonPulseGreen 1.5s infinite ease-in-out;
    vertical-align: middle;
}
