/* ===== App shell ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem 0 1rem;
    z-index: 200;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 1.75rem;
    text-decoration: none;
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.sidebar-brand-name {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #f9fafb;
    line-height: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.125rem;
    width: 100%;
    flex: 1;
}

.sidebar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0 0.75rem;
    text-decoration: none;
    color: #9ca3af;
    transition: color var(--transition);
}

.sidebar-item:hover {
    color: #e5e7eb;
}

.sidebar-item:hover .sidebar-icon-wrap {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-icon-wrap {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}

.sidebar-icon-wrap i {
    font-size: 1.35rem;
    line-height: 1;
}

.sidebar-label {
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1;
    letter-spacing: 0.01em;
    color: #9ca3af;
    transition: color var(--transition);
}

.sidebar-item.active .sidebar-icon-wrap {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-item.active .sidebar-label {
    color: #60a5fa;
    font-weight: 600;
}

.sidebar-item.active {
    color: #fff;
}

.sidebar-item .nav-dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f97316;
    border: 1.5px solid var(--sidebar-bg);
}

.sidebar-theme-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    margin-top: 0.75rem;
    transition: background var(--transition), color var(--transition);
}

.sidebar-theme-btn i {
    font-size: 1.2rem;
}

.sidebar-theme-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-spacer {
    flex: 1;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-header-rail {
    position: sticky;
    top: 0;
    z-index: 150;
    background: var(--topbar-bg);
}

.app-topbar {
    background: transparent;
    color: var(--topbar-text);
    min-height: var(--topbar-height);
    height: var(--topbar-height);
    display: flex;
    align-items: stretch;
    padding: 0 1.5rem;
    gap: 1rem;
}

.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
    transition: background var(--transition);
}

.topbar-icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.topbar-spacer {
    flex: 1;
    min-width: 0.5rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.app-subnav {
    background: transparent;
    border-top: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    align-items: stretch;
    padding: 0;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 0 1 auto;
    min-width: 0;
}

.app-subnav.is-hidden {
    display: none;
}

.app-subnav::-webkit-scrollbar {
    display: none;
}

.subnav-link {
    color: rgba(255, 255, 255, 0.75);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
}

.subnav-link:hover {
    color: #fff;
}

.subnav-link.active {
    color: #fff;
    border-bottom-color: #fff;
    font-weight: 600;
}

.app-content {
    flex: 1;
    padding: 1.5rem;
    max-width: calc(var(--content-max) + 3rem);
    width: 100%;
    margin: 0 auto;
}

.app-content.has-bottom-nav {
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1.5rem);
}

/* ===== Mobile header (replaces sidebar on small screens) ===== */
.mobile-header {
    display: none;
    background: var(--topbar-bg);
    color: #fff;
    padding: 0.75rem 1rem;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 150;
}

.mobile-header-title {
    flex: 1;
    font-weight: 700;
    font-size: 1rem;
}

.mobile-header-sub {
    font-size: 0.75rem;
    opacity: 0.85;
    font-weight: 400;
}

.mobile-org-label {
    font-size: 0.7rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.1rem;
}

.mobile-theme-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;
    font-size: 1.05rem;
}

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

/* ===== Bottom navigation (mobile) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-inner {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0.2rem 0.15rem 0.35rem;
}

.bottom-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem;
    color: var(--text-secondary);
    font-size: 0.62rem;
    font-weight: 600;
    padding: 0.15rem 0.1rem 0;
    min-width: 0;
    width: 100%;
    background: transparent;
    border: 0;
    text-align: center;
    line-height: 1.1;
}

.bottom-nav-link span {
    display: block;
    width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bottom-nav-link i {
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1.35rem;
}

.bottom-nav-link.active {
    color: var(--primary);
}

.bottom-nav-fab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem;
    min-width: 0;
    text-align: center;
}

.bottom-nav-fab-btn {
    width: 46px;
    height: 46px;
    margin-top: -18px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    box-shadow: var(--shadow-lg);
    flex-shrink: 0;
    transition: transform var(--transition), background var(--transition);
}

.bottom-nav-fab-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.bottom-nav-fab-btn.active {
    box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-lg);
}

.bottom-nav-fab-label {
    display: block;
    width: 100%;
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--primary);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Org switcher ===== */
.org-switcher {
    position: relative;
}

.org-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
}

.org-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    overflow: hidden;
}

.org-switcher.open .org-dropdown {
    display: block;
}

.org-dropdown-header {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.org-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: background var(--transition);
}

.org-list-item:hover {
    background: var(--surface-muted);
}

.org-list-item.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

/* ===== Profile ===== */
.profile-menu {
    position: relative;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.profile-panel {
    display: none;
    position: fixed;
    z-index: 401;
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text);
}

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

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

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

.profile-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 999px;
    margin: 0.75rem auto 0;
}

.profile-user-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.profile-member-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

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

.profile-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.profile-close-btn:hover {
    background: var(--surface-muted);
}

.profile-user {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    align-items: center;
    text-align: center;
}

.profile-name {
    font-weight: 600;
}

.profile-email {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.profile-role-switch {
    margin: 0 1rem 1rem;
    width: calc(100% - 2rem);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--primary);
}

.profile-role-switch:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.profile-theme-switch {
    margin: 0 1rem 0.75rem;
    width: calc(100% - 2rem);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text);
}

.profile-theme-switch:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

.profile-action-btn {
    margin: 0 1rem 1rem;
    width: calc(100% - 2rem);
    padding: 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-weight: 600;
    font-size: 0.875rem;
}

.profile-action-btn:hover {
    background: var(--danger);
    color: #fff;
}

/* ===== Page header ===== */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.page-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
