/* ================================================================
   AFFILIATEBOT — LAYOUT  layout.css
   App Shell · Sidebar · Topbar · Bottom Nav · Drawer
   ================================================================ */

/* ── APP SHELL ──────────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
  background: var(--c-bg);
}

/* ── SIDEBAR ────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform var(--dur-base) var(--ease-spring),
              width var(--dur-base) var(--ease-spring);
}

/* Sidebar section label */
.nav-section-label {
  margin-top: 4px;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  text-decoration: none;
}

.logo-mark {
  width: 28px; height: 28px;
  background: var(--grad-primary);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--sh-glow);
}

.logo-mark svg { color: #fff; }
.sidebar-logo .logo-mark svg { width: 15px; height: 15px; }

.logo-wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  overflow: hidden;
}

.logo-wordmark .name {
  font-size: 14px;
  font-weight: var(--fw-bold);
  color: var(--c-text);
  white-space: nowrap;
}

.logo-wordmark .tagline {
  font-size: 10.5px;
  color: var(--c-text-3);
  font-weight: var(--fw-medium);
}

/* Nav scroll area */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: 11px;
  font-weight: var(--fw-semi);
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--c-text-2);
  font-size: 13px;
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast),
              transform var(--dur-fast);
  min-height: auto;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.nav-item:active { transform: scale(.98); }

.nav-item.active {
  background: transparent;
  color: var(--c-text);
  font-weight: var(--fw-semi);
  box-shadow: none;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c-primary), transparent 85%);
  opacity: .12;
  pointer-events: none;
}

.nav-item.active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: var(--r-pill);
  background: var(--c-primary);
}

.nav-item.active .nav-icon { color: inherit; }

/* Dark mode active nav */
[data-theme="dark"] .nav-item.active {
  background: transparent;
  color: var(--c-text);
  box-shadow: none;
}
[data-theme="dark"] .nav-item.active .nav-icon { color: inherit; }
[data-theme="dark"] .nav-item:hover {
  background: rgba(255,255,255,.05);
  color: var(--c-text);
}

.nav-item .nav-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  transition: color var(--dur-fast);
}

.nav-item .nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  margin-left: auto;
  background: var(--c-danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  border-radius: var(--r-pill);
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
  animation: badge-pop .3s var(--ease-spring);
}

@keyframes badge-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* Sidebar footer / user */
.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-shrink: 0;
  cursor: default;
  transition: background var(--dur-fast);
  border-radius: 0 0 0 0;
}

.sidebar-footer:hover { background: transparent; }

[data-theme="dark"] .sidebar-footer:hover { background: transparent; }

.sidebar-health {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--c-text-2);
  font-size: 12px;
  font-weight: var(--fw-semi);
}

.sidebar-health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-success);
  box-shadow: 0 0 0 3px rgba(47, 211, 111, .12);
}

.sidebar-avatar,
.user-avatar {
  width: 30px; height: 30px;
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-2);
  color: var(--c-text);
  font-size: 12px;
  font-weight: var(--fw-bold);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-info { flex: 1; overflow: hidden; }

.user-name {
  font-size: 13px;
  font-weight: var(--fw-semi);
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 11.5px;
  color: var(--c-text-3);
}

/* ── PAGE WRAPPER ───────────────────────────────────────────────── */
#page-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  transition: margin-left var(--dur-base) var(--ease-spring);
}

/* ── TOPBAR ─────────────────────────────────────────────────────── */
#topbar {
  position: sticky;
  top: 0; z-index: 30;
  height: var(--topbar-h);
  background: var(--c-bg);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-6);
  flex-shrink: 0;
}

.topbar-mobile-logo {
  display: none;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
}

.topbar-mobile-logo .logo-mark { width: 30px; height: 30px; }
.topbar-mobile-logo .name { font-size: 13px; font-weight: var(--fw-bold); color: var(--c-text); }

.topbar-page-title {
  font-size: 16px;
  font-weight: var(--fw-bold);
  color: var(--c-text);
  white-space: nowrap;
  line-height: 1.2;
}

.topbar-breadcrumb {
  display: block;
  margin-top: 2px;
  color: var(--c-text-3);
  font-size: 11px;
  font-weight: var(--fw-medium);
  line-height: 1.2;
  white-space: nowrap;
}

/* Search */
.topbar-search {
  flex: 1;
  max-width: 300px;
  position: relative;
  display: flex;
  align-items: center;
}

.topbar-search input {
  width: 100%;
  height: 36px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  padding: 0 68px 0 34px;
  font-size: 13px;
  color: var(--c-text-2);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast),
              background var(--dur-fast);
  cursor: pointer;
}
.topbar-search input:hover {
  background: var(--c-surface);
  border-color: var(--c-border-2);
}

.topbar-search input::placeholder { color: var(--c-text-3); }
.topbar-search input:focus {
  border-color: var(--c-primary);
  box-shadow: var(--sh-focus);
  outline: none;
}

.topbar-search .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-3);
  pointer-events: none;
  width: 15px; height: 15px;
}

.search-kbd {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 10.5px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--c-text-3);
  font-family: ui-monospace, monospace;
  pointer-events: none;
  white-space: nowrap;
}

/* Topbar right actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.topbar-icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--r-control);
  display: flex; align-items: center; justify-content: center;
  color: var(--c-text-2);
  position: relative;
  transition: background var(--dur-fast), color var(--dur-fast);
  cursor: pointer;
}

.topbar-icon-btn:hover { background: var(--c-surface); color: var(--c-text); }

.topbar-budget-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  color: var(--c-money);
  text-decoration: none;
  font-size: 13px;
  font-weight: var(--fw-bold);
  line-height: 1.5;
}

.topbar-budget-pill[hidden] {
  display: none !important;
}

.topbar-notif-badge,
.topbar-notif-dot {
  position: absolute;
  top: 7px; right: 6px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  background: var(--c-danger);
  border-radius: var(--r-pill);
  border: 2px solid var(--c-bg);
  color: #fff;
  font-size: 9px;
  font-weight: var(--fw-bold);
  line-height: 11px;
  text-align: center;
}

@keyframes pulse-dot {
  0%,100%{ box-shadow: 0 0 0 0 rgba(220,38,38,.4) }
  50%    { box-shadow: 0 0 0 4px rgba(220,38,38,0) }
}

.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-pill);
  background: var(--grad-primary);
  color: #fff;
  font-size: 12px;
  font-weight: var(--fw-semi);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: box-shadow var(--dur-fast), transform var(--dur-fast);
}

.topbar-avatar:hover { box-shadow: var(--sh-raised); transform: scale(1.05); }

/* ── MAIN CONTENT ───────────────────────────────────────────────── */
#main-content {
  flex: 1;
  width: 100%;
  padding: var(--sp-6);
  overflow-y: auto;
  max-width: 1320px;
  margin: 0 auto;
}

/* Page header pattern */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.page-header-left { flex: 1; min-width: 0; }

.page-title {
  font-size: 22px;
  font-weight: var(--fw-bold);
  color: var(--c-text);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13.5px;
  color: var(--c-text-2);
  margin-top: 3px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* Section header inside page */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  gap: var(--sp-4);
}

.section-title {
  font-size: 15px;
  font-weight: var(--fw-semi);
  color: var(--c-text);
}

/* ── BOTTOM NAV (mobile) ────────────────────────────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border-2);
  z-index: 40;
  padding: 0 var(--sp-1);
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -4px 16px rgba(15,23,42,.07);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  min-height: 52px;
  color: var(--c-text-3);
  font-size: 10.5px;
  font-weight: var(--fw-medium);
  cursor: pointer;
  padding: var(--sp-1);
  position: relative;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast);
  text-decoration: none;
}

.bnav-item.active { color: var(--c-text); }

/* Active indicator bar on bottom nav */
.bnav-item.active::before {
  display: none;
}

.bnav-item .bnav-icon {
  width: 22px; height: 22px;
  transition: transform var(--dur-base) var(--ease-spring);
}

.bnav-item.active .bnav-icon { transform: none; }

.bnav-indicator {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 6px; height: 6px;
  background: var(--c-danger);
  border-radius: 50%;
  border: 1.5px solid var(--c-surface);
  opacity: 0;
  transition: opacity var(--dur-fast);
}
.bnav-item[data-badge="true"] .bnav-indicator { opacity: 1; }

/* ── MOBILE DRAWER ──────────────────────────────────────────────── */
#drawer-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base);
}

#drawer-overlay.visible { opacity: 1; pointer-events: auto; }

#mobile-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--c-surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  z-index: 50;
  transform: translateY(100%);
  transition: transform var(--dur-base) var(--ease-spring);
  padding-bottom: max(var(--sp-8), env(safe-area-inset-bottom, 8px));
  max-height: 80vh;
  overflow-y: auto;
}

#mobile-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 36px; height: 4px;
  background: var(--c-border-2);
  border-radius: var(--r-pill);
  margin: var(--sp-3) auto var(--sp-4);
}

.drawer-section-label {
  font-size: 11px;
  font-weight: var(--fw-semi);
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: var(--sp-2) var(--sp-5) var(--sp-1);
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 14px var(--sp-5);
  color: var(--c-text-2);
  font-size: 14px;
  font-weight: var(--fw-medium);
  transition: background var(--dur-fast), color var(--dur-fast);
  cursor: pointer;
  text-decoration: none;
  min-height: 52px;
}

.drawer-item:hover   { background: var(--c-surface-2); color: var(--c-text); }
.drawer-item.active  { color: var(--c-primary); }

.drawer-item .nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ── OFFLINE BANNER ─────────────────────────────────────────────── */
#offline-banner {
  position: fixed;
  bottom: var(--bottom-nav-h); left: 0; right: 0;
  z-index: 60;
  background: var(--c-warning);
  color: #fff;
  padding: var(--sp-2) var(--sp-5);
  font-size: 13px;
  font-weight: var(--fw-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transform: translateY(100%);
  transition: transform var(--dur-base) var(--ease-spring);
  box-shadow: 0 -2px 12px rgba(217,119,6,.2);
}

#offline-banner.show { transform: translateY(0); }

/* ── SIDEBAR OVERLAY (mobile) ───────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.4);
  z-index: 39;
  opacity: 0;
  transition: opacity var(--dur-base);
}
#sidebar-overlay.visible { opacity: 1; }

/* ── RESPONSIVE ─────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  #sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    z-index: 50;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--sh-modal);
  }
  #page-wrapper { margin-left: 0 !important; }
  #bottom-nav { display: flex; }
  #main-content {
    padding: var(--sp-4);
    padding-bottom: calc(var(--bottom-nav-h) + var(--sp-6));
  }
  #drawer-overlay { display: block; }
  .topbar-mobile-logo { display: flex; }
  .topbar-titlewrap { display: none !important; }
  .topbar-page-title { display: none; }
  .topbar-search { display: none; }
  #offline-banner { bottom: var(--bottom-nav-h); }
}

@media (min-width: 1024px) {
  #mobile-drawer, #drawer-overlay { display: none !important; }
  #bottom-nav { display: none !important; }
  #sidebar-overlay { display: none !important; }
  .topbar-mobile-logo { display: none; }
  .topbar-page-title { display: block; }
  #offline-banner { bottom: 0; top: auto; }
}

@media (max-width: 767px) {
  #topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .topbar-mobile-logo { min-height: 44px; }
  .topbar-actions .btn-sm { height: 44px; }
  .topbar-icon-btn { height: 44px; width: 44px; }
  .topbar-avatar { height: 44px; width: 44px; }
  .page-header { margin-bottom: var(--sp-4); }
  .page-title { font-size: 18px; }
}

/* ── TOAST STACK ────────────────────────────────────────────────── */
#toast-stack {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--sp-4));
  right: var(--sp-4);
  z-index: 80;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
  width: min(360px, calc(100vw - var(--sp-8)));
  pointer-events: none;
}

@media (min-width: 1024px) {
  #toast-stack { bottom: var(--sp-6); }
}

/* ── MODAL STACK ────────────────────────────────────────────────── */
#modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 70;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 0;
  transition: opacity var(--dur-base);
}
#modal-overlay.open {
  display: flex;
  opacity: 1;
}

/* ── CONTENT GRID PATTERNS ──────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-4);
}

.content-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

@media (max-width: 767px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
  .content-grid { grid-template-columns: 1fr; }
  .content-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 479px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ── SIDEBAR COLLAPSE ───────────────────────────────────────────── */
#sidebar.collapsed { width:var(--sidebar-icon); }
#sidebar.collapsed .logo-wordmark,
#sidebar.collapsed .user-info,
#sidebar.collapsed .nav-label,
#sidebar.collapsed .nav-badge,
#sidebar.collapsed .nav-kbd,
#sidebar.collapsed .nav-section-items,
#sidebar.collapsed .nav-section-label { display:none; }
#sidebar.collapsed .nav-item { justify-content:center; padding:10px; gap:0; }
#sidebar.collapsed .sidebar-footer { justify-content:center; }
#sidebar.collapsed .sidebar-collapse-btn { right:50%; transform:translateX(50%); }

/* Section collapse */
.nav-section-label {
  display:flex; align-items:center; justify-content:space-between;
}
.section-toggle {
  background:none; border:none; cursor:pointer; padding:2px 4px;
  color:var(--c-text-3); border-radius:var(--r-xs); display:flex;
  align-items:center; opacity:.6; transition:opacity var(--dur-fast);
}
.section-toggle:hover { opacity:1; background:var(--c-surface-2); }
.nav-section-items { display:flex; flex-direction:column; gap:2px; }
.section-collapsed .nav-section-items { display:none; }

/* Sidebar collapse button */
.sidebar-collapse-btn {
  position:absolute; top:72px; right:-12px;
  width:24px; height:24px; border-radius:50%;
  background:var(--c-surface); border:1px solid var(--c-border);
  box-shadow:var(--sh-raised); cursor:pointer; z-index:10;
  display:flex; align-items:center; justify-content:center;
  color:var(--c-text-3); transition:all var(--dur-fast);
}
.sidebar-collapse-btn:hover { background:var(--c-primary-s); color:var(--c-primary); border-color:var(--c-primary-s); }
@media(max-width:1023px) { .sidebar-collapse-btn { display:none; } }

/* Topbar search kbd hint */
.topbar-search { position:relative; }
.topbar-search input { cursor:pointer; }

/* Transition for page-wrapper when sidebar collapses */
#page-wrapper { transition:margin-left var(--dur-base) var(--ease-spring); }
