/* ==========================================================================
   Layout - Jabbr Dashboard v2
   CSS Grid shell: sidebar + header + main + status bar
   ========================================================================== */

/* ── App Shell ──────────────────────────────────────────────────────────── */
body {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-deepest);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    transition: width var(--transition-normal);
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-lg);
    height: var(--header-height);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    overflow: hidden;
}

.brand-text {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    white-space: nowrap;
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .brand-text {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
    position: absolute;
}

/* Bot Avatar */
.bot-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-teal-dim), var(--accent-purple-dim));
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.bot-face {
    width: 22px;
    height: 18px;
    position: relative;
}

.bot-eye {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent-teal);
    top: 2px;
    animation: botBlink 4s infinite;
}

.bot-eye.left  { left: 3px; }
.bot-eye.right { right: 3px; }

.bot-mouth {
    position: absolute;
    bottom: 1px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--accent-teal);
    opacity: 0.6;
}

/* Bot states */
.bot-avatar.trading .bot-eye {
    animation: botPulse 1.5s infinite;
    background: var(--color-success);
}

.bot-avatar.trading {
    box-shadow: var(--shadow-glow-teal);
}

.bot-avatar.idle .bot-eye {
    height: 2px;
    top: 4px;
    animation: none;
}

.bot-avatar.error .bot-eye {
    background: var(--color-danger);
    animation: botPulse 0.8s infinite;
}

.bot-avatar.error {
    box-shadow: var(--shadow-glow-rose);
}

@keyframes botBlink {
    0%, 45%, 55%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.1); }
}

@keyframes botPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-sm);
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    min-height: 42px;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--text-primary);
    background: var(--bg-active);
}

.nav-item.active .nav-icon {
    background: var(--icon-color, var(--accent-teal-dim));
    color: var(--icon-color, var(--accent-teal));
}

.nav-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: var(--text-md);
    transition: all var(--transition-fast);
    color: var(--text-muted);
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
    color: var(--icon-color, var(--accent-teal));
    background: color-mix(in srgb, var(--icon-color, var(--accent-teal)) 15%, transparent);
}

.nav-label {
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
    position: absolute;
}

/* Collapsed tooltip */
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: var(--space-sm);
    gap: 0;
}

.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-md);
    z-index: var(--z-tooltip);
}

.sidebar.collapsed .nav-item:hover::after {
    opacity: 1;
}

/* Sidebar footer */
.sidebar-footer {
    padding: var(--space-sm);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* Sidebar logout button */
.sidebar-logout {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--text-base);
    font-family: inherit;
    transition: all var(--transition-fast);
    min-height: 42px;
}

.sidebar-logout:hover {
    color: var(--accent-rose);
    background: var(--accent-rose-dim);
}

.sidebar-logout i {
    width: 34px;
    min-width: 34px;
    text-align: center;
    font-size: var(--text-md);
}

.sidebar.collapsed .sidebar-logout {
    justify-content: center;
    padding: var(--space-sm);
}

.sidebar.collapsed .sidebar-logout .nav-label {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
    position: absolute;
}

.sidebar.collapsed .sidebar-logout {
    justify-content: center;
    padding: var(--space-sm);
    gap: 0;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: var(--space-lg) var(--space-sm);
    gap: 0;
}

.sidebar-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.sidebar-toggle i {
    transition: transform var(--transition-normal);
}

.sidebar.collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

/* ── Main Wrapper ───────────────────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    min-width: 0;
    transition: margin-left var(--transition-normal);
    height: 100vh;
    height: 100dvh;
}

body.sidebar-collapsed .main-wrapper {
    margin-left: var(--sidebar-collapsed);
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
    height: var(--header-height);
    background: var(--bg-deepest);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-xl);
    flex-shrink: 0;
    z-index: var(--z-header);
    gap: var(--space-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 0;
}

.page-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    white-space: nowrap;
}

.mobile-menu-btn {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--text-lg);
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Header center - session stats */
.header-center {
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.session-stats {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

.stat-chip i {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Header right */
.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-shrink: 0;
}

/* ── Environment Toggle ─────────────────────────────────────────────────── */
.env-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 3px var(--space-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    user-select: none;
    transition: border-color var(--transition-normal);
}

.env-toggle.is-demo {
    border-color: var(--accent-amber);
    box-shadow: 0 0 8px rgba(var(--accent-amber-rgb, 245,166,35), 0.15);
}

.env-label {
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-fast), text-shadow var(--transition-fast);
    padding: 2px 2px;
    line-height: 1;
}

.env-label.active {
    color: var(--text-primary);
}

.env-label.mainnet.active {
    color: var(--color-success);
    text-shadow: 0 0 6px var(--color-success);
}

.env-label.demo.active {
    color: var(--accent-amber);
    text-shadow: 0 0 6px var(--accent-amber);
}

/* Mini toggle switch */
.env-switch {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
    flex-shrink: 0;
}

.env-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.env-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--color-success);
    border-radius: 16px;
    transition: background var(--transition-normal);
}

.env-slider::before {
    content: '';
    position: absolute;
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-normal);
}

.env-switch input:checked + .env-slider {
    background: var(--accent-amber);
}

.env-switch input:checked + .env-slider::before {
    transform: translateX(12px);
}

.env-toggle.switching {
    opacity: 0.6;
    pointer-events: none;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
}

.conn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-warning);
    transition: background var(--transition-normal);
}

.connection-badge.connected .conn-dot {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
}

.connection-badge.disconnected .conn-dot {
    background: var(--color-danger);
}

.conn-text {
    color: var(--text-secondary);
}

.wallet-badge {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.wallet-badge i {
    color: var(--accent-amber);
    font-size: var(--text-xs);
}

/* ── User Greeting & Notification Dropdown ──────────────────────────────── */
.user-greeting {
    position: relative;
    display: flex;
    align-items: center;
}

.user-greeting-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    user-select: none;
}

.user-greeting-trigger:hover {
    border-color: var(--accent-teal);
    background: rgba(0,212,170,0.05);
}

.user-greeting-trigger > i:first-child {
    color: var(--accent-teal);
    font-size: 1rem;
}

.greeting-arrow {
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    margin-left: 2px;
}

.user-greeting.open .greeting-arrow {
    transform: rotate(180deg);
}

.msg-badge {
    background: var(--color-danger, #ff4757);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 10px;
    padding: 0 4px;
    animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    max-height: 420px;
    background: var(--bg-secondary, #111827);
    border: 1px solid var(--border-color, #2d3548);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.user-greeting.open .notification-dropdown {
    display: flex;
}

.notif-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle, #1e2538);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #e0e0e0);
}

.notif-header .btn-link {
    background: none;
    border: none;
    color: var(--accent-teal, #00d4aa);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
}

.notif-header .btn-link:hover {
    text-decoration: underline;
}

.notif-list {
    flex: 1;
    overflow-y: auto;
    max-height: 320px;
}

.notif-item {
    display: flex;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-subtle, #1e2538);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.82rem;
}

.notif-item:hover {
    background: rgba(0,212,170,0.04);
}

.notif-item.unread {
    background: rgba(0,212,170,0.06);
    border-left: 3px solid var(--accent-teal, #00d4aa);
}

.notif-item .notif-emoji {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.notif-item .notif-body {
    flex: 1;
    min-width: 0;
}

.notif-item .notif-title {
    font-weight: 600;
    color: var(--text-primary, #e0e0e0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-item .notif-text {
    color: var(--text-secondary, #94a3b8);
    font-size: 0.78rem;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-item .notif-time {
    color: var(--text-muted, #64748b);
    font-size: 0.7rem;
    margin-top: 3px;
}

.notif-item .notif-mark-btn {
    flex-shrink: 0;
    align-self: center;
    background: none;
    border: 1px solid var(--border-subtle, #1e2538);
    border-radius: 4px;
    color: var(--text-muted, #64748b);
    font-size: 0.7rem;
    padding: 2px 6px;
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.notif-item .notif-mark-btn:hover {
    color: var(--accent-teal, #00d4aa);
    border-color: var(--accent-teal, #00d4aa);
}

.notif-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
}

.notif-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-subtle, #1e2538);
    text-align: center;
}

.notif-footer a {
    color: var(--accent-teal, #00d4aa);
    font-size: 0.8rem;
    text-decoration: none;
}

.notif-footer a:hover {
    text-decoration: underline;
}

/* Notification header actions (clear + mark all) */
.notif-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.notif-header-actions .btn-link i {
    font-size: 0.72rem;
}

/* Notification actions footer (profile + logout) */
.notif-actions-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--border-subtle, #1e2538);
    background: rgba(0,0,0,0.15);
}

.notif-action-link {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.notif-action-link:hover {
    color: var(--text-primary, #e0e0e0);
    background: var(--bg-hover, rgba(255,255,255,0.04));
}

.notif-logout-btn:hover {
    color: var(--accent-rose, #f43f5e) !important;
    background: var(--accent-rose-dim, rgba(244,63,94,0.15)) !important;
}

/* ── Page Content ───────────────────────────────────────────────────────── */
.page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-xl);
    background: var(--bg-base);
}

.page-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: var(--space-lg);
    color: var(--text-muted);
}

.loader-ring {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-default);
    border-top-color: var(--accent-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Status Bar ─────────────────────────────────────────────────────────── */
.status-bar {
    height: var(--status-bar-height);
    background: var(--bg-deepest);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    flex-shrink: 0;
    font-size: var(--text-xs);
    color: var(--text-muted);
    gap: var(--space-lg);
}

.status-left,
.status-center,
.status-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    white-space: nowrap;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-dot.idle    { background: var(--text-muted); }
.status-dot.active  { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.status-dot.error   { background: var(--color-danger); }

.status-version {
    padding: 1px 6px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
}

/* ── Mobile Bottom Nav ──────────────────────────────────────────────────── */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--bg-deepest);
    border-top: 1px solid var(--border-subtle);
    z-index: var(--z-header);
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-xs) var(--space-sm);
    color: var(--text-muted);
    font-size: 10px;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
    min-width: 52px;
}

.mobile-nav-item i {
    font-size: 18px;
}

.mobile-nav-item.active {
    color: var(--accent-teal);
}

.mobile-nav-item:active {
    transform: scale(0.95);
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-xl);
    backdrop-filter: blur(4px);
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
