/* Skip link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    z-index: 1000;
    padding: 0.65rem 1rem;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    box-shadow: var(--shadow-md);
}

.skip-link:focus {
    top: 1rem;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Focus visible */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Main landmark is focused programmatically after route changes — hide ring on the whole pane */
#appContent:focus {
    outline: none;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .loading-spinner {
        animation: none;
        border-top-color: var(--primary);
        opacity: 0.7;
    }
}

/* Dark theme */
[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-muted: #334155;
    --text: #f1f5f9;
    --text-secondary: #e2e8f0;
    --text-muted: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border: #334155;
    --border-strong: #475569;
    --primary-soft: #1e3a5f;
    --success-soft: #064e3b;
    --warning-soft: #78350f;
    --warning-text: #fde68a;
    --danger-soft: #450a0a;
    --danger-text: #fecaca;
    --danger-border: #f87171;
    --purple-soft: #4c1d95;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .app-sidebar {
    background: #0b1220;
}

[data-theme="dark"] .mobile-header {
    background: #1e293b;
    border-color: var(--border);
}

[data-theme="dark"] .mobile-header-sub,
[data-theme="dark"] .mobile-org-label {
    color: #e2e8f0;
    opacity: 1;
}

[data-theme="dark"] .bottom-nav {
    background: #1e293b;
    border-top-color: #475569;
}

[data-theme="dark"] .bottom-nav-inner {
    background: #1e293b;
}

[data-theme="dark"] .bottom-nav-link {
    color: #cbd5e1;
}

[data-theme="dark"] .bottom-nav-link.active {
    color: #93c5fd;
}

[data-theme="dark"] .bottom-nav-fab-label {
    color: #93c5fd;
}

[data-theme="dark"] .org-list-item {
    color: #e2e8f0;
}

[data-theme="dark"] .org-list-item.active {
    background: #1e3a5f;
    color: #93c5fd;
}

[data-theme="dark"] .org-panel-header,
[data-theme="dark"] .profile-panel-header,
[data-theme="dark"] .more-panel-header {
    color: #f1f5f9;
}

[data-theme="dark"] .more-list-item {
    color: #e2e8f0;
}

[data-theme="dark"] .more-list-item.active {
    background: #1e3a5f;
    color: #93c5fd;
}

[data-theme="dark"] .noolz-chat-input {
    background: #0f172a;
    color: #f8fafc;
    border-color: #64748b;
}

[data-theme="dark"] .noolz-chat-input::placeholder {
    color: #94a3b8;
    opacity: 1;
}

[data-theme="dark"] .alert-banner .alert-action {
    color: #fecaca;
}

[data-theme="dark"] .alert-banner .alert-action:hover {
    color: #fee2e2;
}

/* Error state */
.error-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--text-muted);
}

.error-state i {
    font-size: 2.25rem;
    color: var(--danger);
    margin-bottom: 0.75rem;
    display: block;
}

.error-state p {
    margin-bottom: 1rem;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

/* Session modal */
.session-modal {
    position: fixed;
    inset: 0;
    z-index: 1500;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.session-modal[hidden] {
    display: none;
}

.session-modal-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.session-modal-card h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.session-modal-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.85rem;
}

.session-modal-card .session-modal-countdown {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 1.5rem;
}

.session-modal-card .session-modal-countdown:empty {
    display: none;
}

/* Once the session is gone the dashboard must not stay visible behind the notice */
.session-ended .app-shell,
.session-ended .bottom-nav,
.session-ended .preview-banner,
.session-ended .profile-panel,
.session-ended .profile-backdrop,
.session-ended .org-panel,
.session-ended .org-backdrop,
.session-ended .more-panel,
.session-ended .more-backdrop,
.session-ended .noolz-chat-dock {
    display: none;
}

/* Mobile org sheet */
.mobile-org-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mobile-org-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.55);
}

.org-panel {
    display: none;
    position: fixed;
    z-index: 1250;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
}

.org-panel.show {
    display: block;
}

.org-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.org-panel-list {
    padding: 0.5rem;
}

.org-panel-list .org-list-item {
    width: 100%;
}

.org-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1240;
}

.org-backdrop.show {
    display: block;
}

@media (min-width: 769px) {
    .org-backdrop.show {
        display: none;
    }

    .org-panel {
        display: none !important;
    }
}
