/* ============================================================
   Layout — Sidebar, Header, Bottom Nav, Page View
   Premium responsive layout: 320px → 2560px+
   ============================================================ */

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { text-decoration: underline; color: var(--primary-dark); }
img { max-width: 100%; display: block; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* === APP WRAPPER (Grid) === */
#app-wrapper {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
  min-height: 100dvh;
}

/* === SIDEBAR === */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-sticky);
  transition: transform var(--transition-slow), width var(--transition-slow);
  will-change: transform;
  /* Sticky: stays visible while browser window scrolls */
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.sidebar-brand {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  gap: 12px;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  flex-shrink: 0;
  box-shadow: var(--shadow-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

/* ── Collapsible Nav Sections ── */
.nav-section {
  margin-bottom: 2px;
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  -webkit-user-select: none;
}
.nav-section-header:hover {
  color: var(--text-secondary);
  background: var(--bg-secondary);
}
.nav-section-header .nav-section-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-section-header .nav-section-icon svg {
  width: 14px;
  height: 14px;
}
.nav-section-header .nav-section-label-text {
  flex: 1;
}
.nav-section-header .nav-section-chevron {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition);
  opacity: 0.5;
}
.nav-section-header .nav-section-chevron svg {
  width: 13px;
  height: 13px;
}
.nav-section-header.expanded .nav-section-chevron {
  transform: rotate(0deg);
}
.nav-section-header:not(.expanded) .nav-section-chevron {
  transform: rotate(-90deg);
}

.nav-section-content {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  opacity: 0;
  padding-left: 4px;
}
.nav-section-content.expanded {
  max-height: 500px;
  opacity: 1;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 20px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  position: relative;
}
.nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary);
  text-decoration: none;
  transform: translateX(2px);
}
.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
  line-height: 1.3;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
}
.sidebar-user .user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-bg), var(--primary-light));
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.sidebar-user .user-info {
  flex: 1;
  min-width: 0;
}
.sidebar-user .user-name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.sidebar-user .user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* === HEADER === */
#top-header {
  grid-area: header;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  z-index: var(--z-dropdown);
  position: sticky;
  top: 0;
}

.header-menu-btn {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  color: var(--text);
  font-size: 1.3rem;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.header-menu-btn:hover { background: var(--bg); }

.header-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-spacer { flex: 1; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Shop Selector ── */
.shop-selector {
  margin-right: 4px;
}
.shop-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 7px 28px 7px 10px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 120px;
  max-width: 200px;
  transition: border-color var(--transition);
}
.shop-select:hover { border-color: var(--primary); }
.shop-select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }

.header-icon-btn {
  position: relative;
  background: none;
  border: none;
  padding: 10px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 1.15rem;
  transition: all var(--transition);
}
.header-icon-btn:hover {
  background: var(--bg);
  color: var(--primary);
}
.header-icon-btn .notif-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  background: var(--danger);
  color: white;
  font-size: 0.58rem;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
  line-height: 1;
}

/* ── Notification Dropdown ── */
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-overlay);
  display: none;
}
.notif-dropdown.show { display: block; }
.notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.92rem;
}
.notif-dropdown-header a { font-size: 0.78rem; font-weight: 500; }
.notif-dropdown-list {
  max-height: 340px;
  overflow-y: auto;
}
.notif-dropdown-item {
  display: flex;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition);
}
.notif-dropdown-item:hover { background: var(--bg); }
.notif-dropdown-item.unread { background: var(--primary-bg); }
.notif-dropdown-item .notif-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}
.notif-dropdown-item .notif-text { flex: 1; min-width: 0; }
.notif-dropdown-item .notif-title { font-weight: 600; font-size: 0.82rem; }
.notif-dropdown-item .notif-msg {
  font-size: 0.76rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-dropdown-item .notif-time { font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; }
.notif-dropdown-footer {
  padding: 12px 18px;
  text-align: center;
  font-size: 0.82rem;
  border-top: 1px solid var(--border-light);
}

/* === PAGE VIEW === */
#page-view {
  grid-area: main;
  padding: 28px;
  min-width: 0;           /* allow grid child to shrink below content width */
  overflow-x: hidden;     /* prevent wide tables from blowing out the layout */
  /* No fixed height — browser window scrolls naturally */
  scroll-behavior: smooth;
}

/* POS mode — lock the entire viewport height chain, no scroll, no overflow */
html:has(.pos-root),
body:has(.pos-root) {
  overflow: hidden;
  height: 100%;
}
#app-wrapper:has(.pos-root) {
  height: 100dvh;
  min-height: unset;
  overflow: hidden;
}
#page-view:has(.pos-root) {
  padding: 0 !important;
  overflow: hidden !important;
  height: 100% !important;
}

/* === BOTTOM NAV (Mobile) === */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: var(--z-sticky);
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.bottom-nav-items {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 100%;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item:hover { text-decoration: none; }
.bottom-nav-item .bnav-icon { font-size: 1.15rem; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
}

/* === SIDEBAR OVERLAY (Mobile) === */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: calc(var(--z-sticky) - 1);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   320 → 480 → 640 → 768 → 1024 → 1280 → 1536 → 1920 → 2560+
   ============================================================ */

/* ---------- Large desktop: ≥ 1536px ---------- */
@media (min-width: 1536px) {
  :root { --sidebar-width: 280px; }
  html { font-size: 15px; }
  #page-view { padding: 32px 40px; }
}

/* ---------- Extra large / TV: ≥ 1920px ---------- */
@media (min-width: 1920px) {
  :root { --sidebar-width: 300px; }
  html { font-size: 16px; }
  #page-view { padding: 40px 48px; }
}

/* ---------- Ultra wide / 4K TV: ≥ 2560px ---------- */
@media (min-width: 2560px) {
  :root { --sidebar-width: 320px; }
  html { font-size: 18px; }
  #page-view { padding: 48px 64px; }
  .sidebar-brand { font-size: 1.3rem; }
  .nav-item { font-size: 1rem; padding: 12px 16px; }
}

/* ---------- Medium desktop: ≤ 1280px ---------- */
@media (max-width: 1280px) {
  :root { --sidebar-width: 240px; }
  #page-view { padding: 24px; }
}

/* ---------- Tablet: ≤ 1024px ---------- */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  #page-view { padding: 20px; }
}

/* ---------- Mobile: ≤ 768px ---------- */
@media (max-width: 768px) {
  #app-wrapper {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "header"
      "main";
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    z-index: calc(var(--z-sticky) + 10);
    box-shadow: var(--shadow-xl);
  }
  #sidebar.open { transform: translateX(0); }

  .header-menu-btn { display: flex; }
  #top-header { padding: 0 16px; }

  #bottom-nav { display: block; }

  #page-view {
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-height) + 16px);
  }
}

/* ---------- Small phone: ≤ 480px ---------- */
@media (max-width: 480px) {
  :root { --header-height: 56px; --bottom-nav-height: 60px; }
  html { font-size: 13px; }
  #page-view { padding: 12px; }
  #top-header { padding: 0 12px; gap: 8px; }
  .header-title { font-size: 0.95rem; }
  .notif-dropdown { width: calc(100vw - 24px); right: -60px; }
  .sidebar-brand { padding: 0 16px; font-size: 1.05rem; }
}

/* ---------- Extra small: ≤ 360px ---------- */
@media (max-width: 360px) {
  html { font-size: 12px; }
  #page-view { padding: 8px; }
  .notif-dropdown { width: calc(100vw - 16px); right: -50px; }
}

/* === SCROLLBAR STYLING === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
@supports (scrollbar-width: thin) {
  * { scrollbar-width: thin; scrollbar-color: var(--border-dark) transparent; }
}
