/* ==========================================================================
   SETU – Base Layout
   Icon-only collapsible sidebar (64px), popup flyout menus, main content.
   All colours reference tokens.css custom properties.
   ========================================================================== */

/* ---- Layout shell ---- */
body {
    display: flex;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidebar {
    width: var(--s-sidebar-width);
    background: var(--s-sidebar-bg);
    color: var(--s-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: var(--s-z-sidebar);
}

/* ---- Zone 1: logo ---- */
.sidebar-zone-top {
    padding: var(--s-space-3) 0 var(--s-space-2);
    display: flex;
    justify-content: center;
}
.logo-link {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    text-decoration: none;
    transition: transform var(--s-transition-normal);
}
.logo-link:hover { transform: scale(1.1); }
/* Placeholder wordmark: rounded square + "S". Swap for a real logo asset later. */
.logo-mark {
    width: 32px;
    height: 32px;
    border-radius: var(--s-radius-md);
    background: var(--s-color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--s-font-weight-bold);
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}

/* ---- Zone separators ---- */
.sidebar-sep {
    height: 1px;
    background: var(--s-sidebar-border);
    margin: var(--s-space-1) var(--s-space-3);
    flex-shrink: 0;
}

/* ---- Zone 2: feature nav ----
   Two groups (Nikhil 2026-08-18 UX pass): the Workflows entry is its own
   group pinned to the top of the nav zone; the remaining icons form a
   second group vertically centered in the leftover space. */
.nav-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.sidebar-nav {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.nav-group-top {
    flex-shrink: 0;
}
.nav-group-center {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.nav-item { position: relative; }

.nav-link {
    color: var(--s-sidebar-text);
    padding: 0.85rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--s-transition-fast);
    position: relative;
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
}
.nav-link:hover,
.nav-link.active {
    color: var(--s-sidebar-text-hover);
}
/* Active page marker: slim accent bar on the left edge */
.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: 0 2px 2px 0;
    background: var(--s-color-accent);
}
.nav-link svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

/* ---- Popup flyout menus (desktop: beside sidebar) ---- */
.popup-menu {
    position: absolute;
    left: 100%;
    top: 0;
    background-color: var(--s-color-surface);
    border: 1px solid var(--s-color-border);
    border-radius: var(--s-radius-lg);
    box-shadow: var(--s-shadow-xl);
    padding: var(--s-space-2);
    min-width: 200px;
    display: none;
    z-index: var(--s-z-popover);
}
.nav-item.active > .popup-menu {
    display: block;
    animation: sidebarFadeIn 0.15s ease-out;
}
@keyframes sidebarFadeIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.popup-menu .menu-label {
    font-size: var(--s-font-size-xs);
    font-weight: var(--s-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--s-color-text-tertiary);
    padding: var(--s-space-1) var(--s-space-3);
}

.popup-menu .dropdown-item {
    padding: var(--s-space-2) var(--s-space-3);
    display: flex;
    align-items: center;
    gap: var(--s-space-3);
    color: var(--s-color-text);
    text-decoration: none;
    border-radius: var(--s-radius-md);
    transition: all var(--s-transition-fast);
    margin: 1px 0;
    font-size: var(--s-font-size-base);
    white-space: nowrap;
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    text-align: left;
}
.popup-menu .dropdown-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--s-color-text-secondary);
}
.popup-menu .dropdown-item:hover {
    background-color: var(--s-color-accent-light);
    color: var(--s-color-accent-text);
}
.popup-menu .dropdown-item:hover svg {
    color: var(--s-color-accent-text);
}
.popup-menu .dropdown-item.active {
    background-color: var(--s-color-accent);
    color: #fff;
}
.popup-menu .dropdown-item.active svg {
    color: #fff;
}

/* ---- Zone 3: bottom — theme toggle + user ---- */
.sidebar-zone-bottom {
    flex-shrink: 0;
    padding-bottom: var(--s-space-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-space-2);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--s-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--s-sidebar-text);
    cursor: pointer;
    transition: all var(--s-transition-fast);
    padding: 0;
}
.theme-toggle:hover {
    background: var(--s-sidebar-active-bg);
    color: var(--s-sidebar-text-hover);
}
.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.user-initials {
    width: 34px;
    height: 34px;
    background: var(--s-sidebar-active-bg);
    border-radius: var(--s-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--s-font-size-sm);
    font-weight: var(--s-font-weight-medium);
    color: var(--s-sidebar-text);
    cursor: pointer;
    transition: all var(--s-transition-fast);
    border: 1px solid var(--s-sidebar-border);
}
.user-initials:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--s-sidebar-text-hover);
}

/* User popup opens upward, anchored to the sidebar edge */
.sidebar-zone-bottom .nav-item > .popup-menu {
    top: auto;
    bottom: 0;
}

.popup-menu .menu-meta {
    padding: var(--s-space-2) var(--s-space-3);
    font-size: var(--s-font-size-sm);
    color: var(--s-color-text-secondary);
    border-bottom: 1px solid var(--s-color-border);
    margin-bottom: var(--s-space-1);
    white-space: nowrap;
}
.popup-menu .menu-meta strong {
    display: block;
    color: var(--s-color-text);
    font-weight: var(--s-font-weight-medium);
}

/* ==========================================================================
   MAIN CONTENT
   ========================================================================== */
.main-content {
    flex: 1;
    margin-left: var(--s-sidebar-width);
    width: calc(100% - var(--s-sidebar-width));
    padding: var(--s-space-6) var(--s-space-6) var(--s-space-8);
}
.main-content > .page-inner {
    max-width: var(--s-content-max-width);
    margin: 0 auto;
}

/* Page header pattern: h1 + muted subtitle */
.page-header {
    margin-bottom: var(--s-space-5);
}
.page-header h1 {
    margin-bottom: var(--s-space-1);
}

/* ==========================================================================
   MOBILE (≤ 768px) — sidebar becomes a bottom icon bar, flyouts open upward
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 56px;
        flex-direction: row;
        align-items: center;
        padding: 0 var(--s-space-2);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .sidebar-zone-top { padding: 0 var(--s-space-2); }
    .sidebar-sep { display: none; }
    .nav-wrapper {
        flex-direction: row;
        justify-content: center;
    }
    .sidebar-nav {
        flex-direction: row;
        justify-content: center;
    }
    .nav-group-top,
    .nav-group-center {
        flex-direction: row;
        justify-content: center;
        flex-grow: 0;
    }
    .nav-link { padding: 0 var(--s-space-4); height: 56px; }
    .nav-link.active::before {
        left: 50%;
        top: 0;
        transform: translateX(-50%);
        width: 22px;
        height: 3px;
        border-radius: 0 0 2px 2px;
    }
    .sidebar-zone-bottom {
        flex-direction: row;
        padding-bottom: 0;
        margin-left: auto;
    }
    .popup-menu,
    .sidebar-zone-bottom .nav-item > .popup-menu {
        position: absolute;
        left: 50%;
        top: auto;
        bottom: calc(100% + 8px);
        transform: translateX(-50%);
    }
    .sidebar-zone-bottom .nav-item > .popup-menu {
        left: auto;
        right: 0;
        transform: none;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: var(--s-space-4) var(--s-space-3) calc(56px + var(--s-space-6));
    }
}
