/**
 * BakeryERP Pro — layout shell (sidebar, topbar, main wrap, responsive).
 * Ported from medikcare's app.css layout section; component styles live in
 * components.css, tokens in variables.css (loaded before this file).
 */

/* ── Dark mode: sidebar/topbar-specific ────────────────────────────────── */
html.dark .sidebar { background: #1e293b; border-color: #334155; }
html.dark .sidebar-logo { border-color: #334155; }
html.dark .sidebar-logo .name { color: #93c5fd; }
html.dark .sidebar-nav::-webkit-scrollbar-thumb { background: #475569; }
html.dark .sidebar-footer { border-color: #334155; }
html.dark .nav-item { color: #94a3b8; }
html.dark .nav-item:hover { background: #334155; color: #93c5fd; }
html.dark .nav-item.active { background: #1e3a5f; color: #93c5fd; }
html.dark .nav-section-label { color: #64748b; }
html.dark .topbar { background: #1e293b; border-color: #334155; }
#darkToggle { transition: background .15s, color .15s; }
html.dark #darkToggle { color: #fbbf24; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar { width: 240px; height: 100vh; background: var(--sidebar-bg, #fff); border-right: 1px solid #e2e8f0; position: fixed; top: 0; left: 0; z-index: 50; display: flex; flex-direction: column; transition: width .25s, transform .25s; overflow: hidden; }
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-logo { padding: 18px 0; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-logo > div:last-child { display: none; }
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 9px 0; margin: 1px 4px; gap: 0; font-size: 0; white-space: nowrap; overflow: hidden; }
.sidebar.collapsed .nav-item i { width: auto; font-size: .875rem; }
.sidebar.collapsed .nav-section-label { display: none; }

.sidebar-logo { padding: 18px 20px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sidebar-logo .name { font-weight: 800; font-size: .875rem; color: var(--pr); line-height: 1.2; }
.sidebar-logo .sub { font-size: .7rem; color: #94a3b8; }

.sidebar-nav { padding: 8px 0 16px; flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #e2e8f0 transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* width:100% (not just the flex-stretch every <a> item already gets for free) is needed here because
   .nav-parent items are real <button> elements — buttons size to their own content by default and don't
   stretch to fill a flex column the way anchors do, so without this a collapsed group button shrinks to
   just its icon's width and sits flush-left instead of centered like every other collapsed icon. */
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px 9px 20px; font-size: .8125rem; font-weight: 500; color: #64748b; text-decoration: none; transition: all .12s; margin: 1px 8px; border-radius: 8px; width: 100%; box-sizing: border-box; border: none; border-left: 3px solid transparent; background: none; text-align: left; cursor: pointer; font-family: inherit; }
.nav-item:hover { background: #f1f5f9; color: var(--pr); }
.nav-item.active { background: #eff6ff; color: var(--pr); border-left-color: var(--or); font-weight: 700; }
.nav-item i { width: 16px; text-align: center; font-size: .875rem; flex-shrink: 0; }

.nav-section-label { padding: 14px 20px 6px; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #94a3b8; }
.nav-section-label:first-child { padding-top: 6px; }

/* ── Sidebar accordion groups (parent section -> child links) ────────────── */
.nav-parent { width: calc(100% - 16px); background: none; border: none; font: inherit; cursor: pointer; }
.nav-parent-label { flex: 1; text-align: left; }
.nav-chevron { margin-left: auto; font-size: .65rem; color: #cbd5e1; transition: transform .18s; flex-shrink: 0; }
.nav-group.open > .nav-parent .nav-chevron { transform: rotate(90deg); }
.nav-group.open > .nav-parent { color: var(--pr); }
.nav-submenu { max-height: 0; overflow: hidden; transition: max-height .2s ease; }
.nav-group.open .nav-submenu { max-height: 600px; }
.nav-subitem { padding-left: 44px; font-size: .78rem; }
.nav-subitem.active { border-left-color: var(--or); }

.sidebar.collapsed .nav-chevron { display: none; }
/* The label's flex:1 (see .nav-parent-label above) makes it grow and claim all free space in the row
   regardless of font-size:0 hiding its text — that leftover-space grab is exactly what was pushing the
   collapsed group icon to the left edge instead of letting justify-content:center actually center it.
   Removing the label from flex layout entirely (not just hiding its text) is what fixes that. */
.sidebar.collapsed .nav-parent-label { display: none; }
/* .nav-parent's own width: calc(100% - 16px) (needed in expanded mode, where .nav-item's margin:1px 8px
   already reserves that space) would otherwise still make a collapsed group button 16px narrower than its
   sibling <a> items — same icon-off-by-half-that-gap misalignment, just smaller. Matching .nav-item's own
   width here keeps every collapsed icon's box (and therefore its centered icon) exactly the same size. */
.sidebar.collapsed .nav-parent { width: 100%; }

/* Collapsed (icon-rail) mode: submenus become a flyout to the right of the icon
   instead of an inline accordion — there's no room to show child labels inline.
   Both hover (mouse) and a .flyout-open class (click, for touch/keyboard) reveal it.
   .sidebar/.sidebar-nav switch to overflow:visible while collapsed so the flyout
   isn't clipped by the rail's own scroll container. */
.sidebar.collapsed { overflow: visible; }
.sidebar.collapsed .sidebar-nav { overflow: visible; }
.sidebar.collapsed .nav-group { position: relative; }
.sidebar.collapsed .nav-submenu {
  display: none; position: absolute; left: 64px; top: 0; min-width: 210px;
  background: var(--sidebar-bg, #fff); border: 1px solid #e2e8f0; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15,23,42,.15); padding: 6px; z-index: 60;
  max-height: none; overflow: visible;
}
.sidebar.collapsed .nav-group:hover .nav-submenu,
.sidebar.collapsed .nav-group.flyout-open .nav-submenu { display: block; }
.sidebar.collapsed .nav-subitem { justify-content: flex-start; padding: 8px 10px; margin: 1px 0; gap: 8px; font-size: .8125rem; white-space: nowrap; overflow: visible; }
.nav-flyout-title { display: none; padding: 4px 10px 8px; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #94a3b8; border-bottom: 1px solid #f1f5f9; margin-bottom: 4px; white-space: nowrap; }
.sidebar.collapsed .nav-flyout-title { display: block; }

html.dark .nav-chevron { color: #475569; }
html.dark .nav-group.open > .nav-parent { color: #93c5fd; }
html.dark .sidebar.collapsed .nav-submenu { background: #1e293b; border-color: #334155; }
html.dark .nav-flyout-title { border-color: #334155; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid #f1f5f9; }

/* ── Main / topbar ──────────────────────────────────────────────────────── */
.main-wrap { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; transition: margin .25s; }
.main-wrap.full { margin-left: 60px; }
.topbar { background: var(--navbar-bg, #fff); border-bottom: 1px solid #e2e8f0; padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40; }

/* ── Mobile sidebar overlay ─────────────────────────────────────────────── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 49; }
.sidebar-overlay.show { display: block; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-240px); }
  .sidebar.open { transform: none; }
  .main-wrap { margin-left: 0; }
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-overlay.show { opacity: 1; pointer-events: all; }
  .topbar { padding: 0 10px; gap: 8px; }
  .notif-dropdown { width: calc(100vw - 24px); right: -8px; border-radius: 12px; }
}
