/* sidebar-nav.css – 2025 SaaS left sidebar navigation */

/* ----------------------------------------------------------
   Layout shell
   ---------------------------------------------------------- */

.page-with-sidebar {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: 100vh;
    padding: 0;
}

/* Right-side main area next to sidebar */
.page-with-sidebar .nw-main {
    flex: 1;
    min-width: 0;
    padding: 24px 28px;
    max-width: 100%;
}

/* ----------------------------------------------------------
   Sidebar core
   ---------------------------------------------------------- */

.nw-sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    width: 260px;
    flex-shrink: 0;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.04);
    z-index: 1200;
}

.nw-sidebar__inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 18px 0px 16px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ----------------------------------------------------------
   Brand
   ---------------------------------------------------------- */

.nw-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px 14px;
    margin-bottom: 4px;
    border-bottom: 1px solid #eef0f4;
}

.nw-sidebar__brand-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nw-sidebar__logo-circle {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 25px;
    border: 1px solid rgba(15, 23, 42, .12);
    box-shadow: 0 8px 24px #0f172a14;
}

.nw-sidebar__brand-text {
    display: flex;
    flex-direction: column;
}

.nw-sidebar__brand-name {
    font-size: 24px;
    font-weight: 500;
    color: #111827;
}

.nw-sidebar__brand-sub {
    font-size: 11px;
    color: #9ca3af;
}

.nw-sidebar__household-pill {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 999px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

/* Role colors */
.nw-sidebar__household-pill.is-owner {
    background: #e0edff;
    color: #1d4ed8;
}

.nw-sidebar__household-pill.is-editor {
    background: #e6f7ef;
    color: #047857;
}

.nw-sidebar__household-pill.is-viewer {
    background: #f1f5f9;
    color: #475569;
}
/* Collapse button (top-right of brand row) */
.nw-sidebar__collapse-btn {
    border: none;
    outline: none;
    border-radius: 999px;
    background: #f3f4f6;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    color: #6b7280;
    transition: background 0.12s ease, transform 0.08s ease, color 0.12s ease;
}

.nw-sidebar__collapse-btn:hover {
    background: #e5e7eb;
    color: #111827;
    transform: translateX(1px);
}

/* ----------------------------------------------------------
   Section labels (Overview / Money & spending / etc.)
   ---------------------------------------------------------- */

.nw-sidebar__section-label {
    margin: 14px 10px 4px;
    padding-top: 8px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #9ca3af;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
}

/* First section label (Overview) – no top rule */
.nw-sidebar__nav--primary .nw-sidebar__section-label:first-of-type {
    border-top: none;
    margin-top: 4px;
    padding-top: 0;
}

/* ----------------------------------------------------------
   Nav groups (primary / secondary)
   ---------------------------------------------------------- */

.nw-sidebar__nav {
    margin-top: 10px;
    padding: 4px 2px 4px 0px;
}

.nw-sidebar__nav--primary {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #9ca3af transparent;
}

/* WebKit scrollbar (Chrome/Edge) */
.nw-sidebar__nav--primary::-webkit-scrollbar {
    width: 6px;
}

.nw-sidebar__nav--primary::-webkit-scrollbar-track {
    background: transparent;
}

.nw-sidebar__nav--primary::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 999px;
}

.nw-sidebar__nav--secondary {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
}

/* ----------------------------------------------------------
   Collapsible groups (Accounts & balances, etc.)
   ---------------------------------------------------------- */

.nw-sidebar__group {
    margin-top: 4px;
    margin-bottom: 2px;
}

.nw-sidebar__group-header {
    width: 100%;
    border: none;
    outline: none;
    background: #f9fafb;
    padding: 5px 10px;
    margin: 4px 0px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    text-align: left;
    border-radius: 8px;
    letter-spacing: 0.02em;
    transition: background 0.12s ease, color 0.12s ease;
}

.nw-sidebar__group-header:hover {
    background: #f3f4f6;
    color: #111827;
}

.nw-sidebar__group-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nw-sidebar__group-caret {
    margin-left: 8px;
    height: 11px;
    width: 11px;
    line-height: 1;
    transition: transform 0.12s ease, color 0.12s ease;
}

.nw-sidebar__group-body {
    margin-top: 2px;
    padding-left: 2px;
}

.nw-sidebar__group.is-collapsed .nw-sidebar__group-body {
    display: none;
}

.nw-sidebar__group.is-collapsed .nw-sidebar__group-caret {
    transform: rotate(-90deg);
}

/* ----------------------------------------------------------
   Items
   ---------------------------------------------------------- */

.nw-sidebar__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    margin: 2px 6px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    color: #4b5563;
    text-decoration: none;
    background: transparent;
    transition:
        background 0.12s ease,
        color 0.12s ease,
        box-shadow 0.15s ease;
}

a.nw-sidebar__item {
border-left: 3px solid transparent;
    border-radius: 0px 6px 6px 0px;
    color: #333e4e;
}

.nw-sidebar__item:hover {
    background-color: #f3f4f6;
    color: #111827;
}

.nw-sidebar__item.is-active {
    background: #eff6ff;
        color: #0d44aa;
        border-color: #3487f4;
}

/* Icon + label */
.nw-sidebar__icon {
    width: 22px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

/* Unified thin-stroke icons */
.nw-sidebar__icon svg {
    width: 20px;
    height: 20px;
    display: block;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    /* thinner, unified stroke */
    stroke-linecap: round;
    stroke-linejoin: round;
    color: #9ca3af;
}

/* Hover & active icon tints */
.nw-sidebar__item:hover .nw-sidebar__icon svg {
    color: #6b7280;
}

.nw-sidebar__item.is-active .nw-sidebar__icon svg {
    color: #0052d2;
}

.nw-sidebar__label {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* Nested items slightly tighter */
.nw-sidebar__group-body .nw-sidebar__item {
    padding: 5px 10px;
    margin: 1px 0px;
}

/* ----------------------------------------------------------
   Badge (Recurring count)
   ---------------------------------------------------------- */

.nw-sidebar__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    min-width: 20px;
    height: 18px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    background: #dcfce7;
    color: #065f46;
}

/* ----------------------------------------------------------
   Footer: user block
   ---------------------------------------------------------- */

.nw-sidebar__footer {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

/* Wrapper so we can attach the dropup menu to it */
.nw-sidebar__user-shell {
    position: relative;
}

/* Clickable user pill */
.nw-sidebar__user {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 999px;
    background: #f9fafb;
    border: none;
    outline: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s ease, box-shadow 0.15s ease;
}

.nw-sidebar__user:hover {
    background: #eef2ff;
    box-shadow: 0 4px 14px rgba(148, 163, 184, 0.3);
}

/* Avatar – rounded square style with optional image */
.nw-sidebar__avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: #fee2e2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #b91c1c;
    overflow: hidden;
    flex-shrink: 0;
}

.nw-sidebar__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Text stack */
.nw-sidebar__user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.nw-sidebar__user-name {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nw-sidebar__user-sub {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Small caret on the right */
.nw-sidebar__user-caret {
    margin-left: auto;
    font-size: 11px;
    color: #9ca3af;
    transition: transform 0.12s ease, color 0.12s ease;
}

.nw-sidebar__user-shell.is-open .nw-sidebar__user-caret {
    transform: rotate(180deg);
    color: #4b5563;
}

/* Drop-up menu */
.nw-sidebar__user-menu {
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: 50px;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 8px 8px rgba(15, 23, 42, 0.25);
    padding: 8px 0;
    font-size: 13px;
    display: none;
    z-index: 1400;
}

.nw-sidebar__user-shell.is-open .nw-sidebar__user-menu {
    display: block;
}

/* Menu header: avatar + name + account type */
.nw-sidebar__user-menu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 8px;
}

.nw-sidebar__user-menu-header .nw-sidebar__avatar {
    width: 34px;
    height: 34px;
}

.nw-sidebar__user-menu-name {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.nw-sidebar__user-menu-role {
    font-size: 11px;
    color: #6b7280;
}

.nw-sidebar__user-menu-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 6px 0;
}

/* Menu items */
.nw-sidebar__user-menu-list {
    padding: 2px 0;
}

.nw-sidebar__user-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    text-decoration: none;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.nw-sidebar__user-menu-item:hover {
    background: #f3f4f6;
    color: #111827;
}

.nw-sidebar__user-menu-item-icon {
    width: 18px;
    display: inline-flex;
    justify-content: center;
}

.nw-sidebar__user-menu-item-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.7;
    stroke: currentColor;
    fill: none;
}

/* Logout item at bottom */
.nw-sidebar__user-menu-item--logout {
    color: #b91c1c;
}

.nw-sidebar__user-menu-item--logout:hover {
    background: #fee2e2;
    color: #7f1d1d;
}

/* ----------------------------------------------------------
   Collapsed state
   ---------------------------------------------------------- */

.page-with-sidebar.is-sidebar-collapsed .nw-sidebar {
    width: 72px;
}

/* Hide text when collapsed */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__brand-text,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__label,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__user-text,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__user-caret,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__section-label,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__group-header {
    display: none;
}

.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__user {
    justify-content: center;
}

/* Always show all group items in collapsed mode */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__group-body {
    display: block !important;
}

/* Tighten group spacing */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__group {
    margin-top: 0;
    margin-bottom: 0;
}

/* Icon tiles */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item {
    justify-content: center;
    padding: 6px;
    margin: 4px auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    /* soft square like Linear */
}

/* Active tile */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item.is-active {
    background: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* Ensure active icon is crisp white */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item.is-active .nw-sidebar__icon svg {
    color: #ffffff;
}

/* Rotate collapse icon in collapsed mode */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__collapse-btn {
    transform: rotate(180deg);
}

/* Adjust main padding when collapsed */
.page-with-sidebar.is-sidebar-collapsed .nw-main {
    padding-left: 20px;
}

/* Icons to toggle: default show "open" icon */
.icon-sidebar-collapsed {
    display: none;
}

.page-with-sidebar.is-sidebar-collapsed .icon-sidebar-open {
    display: none;
}

.page-with-sidebar.is-sidebar-collapsed .icon-sidebar-collapsed {
    display: block;
}


/* -----------------------------------------------------------
   Collapsed mode: show text tooltip using aria-label
   ----------------------------------------------------------- */

/* Allow tooltips to overflow without causing horizontal scroll */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar {
    overflow: visible;
}

/* The scroll area should only scroll vertically */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__nav--primary,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__nav--secondary {
    overflow: visible;
    scrollbar-width: none;
}

/* Hide scrollbar in WebKit (Chrome / Edge) */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__nav--primary::-webkit-scrollbar,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__nav--secondary::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* Allow tooltip overflow for entire sidebar in collapsed mode */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__inner {
    overflow: visible !important;
}

/* Each item becomes a positioning context */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item {
    position: relative;
}

/* Tooltip bubble */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item[aria-label]::after {
    content: attr(aria-label);
    position: absolute;
    top: 50%;
    left: calc(100% + 10px);
    /* 10px gap from tile edge */
    transform: translateY(-50%);
    white-space: nowrap;
    padding: 4px 8px;
    font-size: 11px;
    line-height: 1.4;
    border-radius: 6px;
    background: #111827;
    color: #f9fafb;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
    opacity: 0;
    pointer-events: none;
    z-index: 1300;
    transition: opacity .12s ease;
}

/* Show on hover / keyboard focus */
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item[aria-label]:hover::after,
.page-with-sidebar.is-sidebar-collapsed .nw-sidebar__item[aria-label]:focus-visible::after {
    opacity: 1;
}


/* ----------------------------------------------------------
   Mobile: hide sidebar and fallback to old layout
   ---------------------------------------------------------- */

@media (max-width: 768px) {
    .nw-sidebar {
        display: none;
    }

    .page-with-sidebar {
        display: block;
    }

    .page-with-sidebar .nw-main {
        padding: 16px;
    }
}
