/* ═══════════════════════════════════════════════════════════════════
   FITFORGE TRACKER — MAIN LAYOUT SYSTEM
   App shell, sidebar, topbar, content areas, responsive grid
   ═══════════════════════════════════════════════════════════════════ */

/* ── Font Face Declarations ────────────────────────────────────── */
/* Using Google Fonts CDN - Audiowide for brand, Syne for headings,
   Plus Jakarta Sans for body, JetBrains Mono for data */

:root {
  --font-brand:   'Audiowide', 'Exo 2', sans-serif;
  --font-display: 'Syne', 'Exo 2', sans-serif;
  --font-body:    'Plus Jakarta Sans', 'DM Sans', sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
  --font-data:    'Syne', var(--font-display);
}

/* ── App Shell ─────────────────────────────────────────────────── */

.app-container {
  display: flex;
  min-height: 100dvh;
  position: relative;
  z-index: var(--z-base);
}

.app-container.hidden { display: none; }

/* ── Sidebar ───────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  height: 100dvh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: var(--z-sticky);
  background: linear-gradient(180deg,
    rgba(6,6,20,0.98) 0%,
    rgba(10,10,26,0.96) 100%
  );
  backdrop-filter: var(--blur-xl);
  -webkit-backdrop-filter: var(--blur-xl);
  border-right: 1px solid var(--border-dim);
  display: flex;
  flex-direction: column;
  transition: width var(--t-slow), transform var(--t-slow);
  overflow: hidden;
}

.sidebar.mini { width: var(--sidebar-w-mini); }
.sidebar.mini .sidebar-label,
.sidebar.mini .sidebar-section-label,
.sidebar.mini .sidebar-logo-text,
.sidebar.mini .sidebar-user-name,
.sidebar.mini .sidebar-user-role { display: none; }
.sidebar.mini .sidebar-logo { justify-content: center; padding: var(--s5); }
.sidebar.mini .nav-item { justify-content: center; padding: var(--s3) 0; }
.sidebar.mini .nav-item-badge { display: none; }

/* Sidebar Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s5) var(--s6);
  border-bottom: 1px solid var(--border-dim);
  min-height: 72px;
  flex-shrink: 0;
}
.sidebar-logo img {
  width: 220px;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 10px rgba(0,242,254,0.3));
}
.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--s4) var(--s3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-nav::-webkit-scrollbar { width: 0; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-disabled);
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: var(--s4) var(--s3) var(--s2);
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 10px var(--s3);
  border-radius: var(--r3);
  color: var(--text-tertiary);
  font-size: 13.5px;
  font-weight: 600;
  transition: all var(--t-base);
  cursor: pointer;
  position: relative;
  user-select: none;
  white-space: nowrap;
}
.nav-item:hover {
  background: var(--glass-06);
  color: var(--text-primary);
}
.nav-item.active {
  background: linear-gradient(90deg,
    rgba(0,242,254,0.12) 0%,
    rgba(0,242,254,0.04) 100%
  );
  color: var(--accent-primary);
  border: 1px solid rgba(0,242,254,0.15);
}
.nav-item.active .nav-icon { filter: drop-shadow(0 0 5px rgba(0,242,254,0.5)); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--grad-primary);
  border-radius: var(--rfull);
  box-shadow: var(--glow-xs-cyan);
}

.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  transition: filter var(--t-base);
}
.sidebar-label { flex: 1; }

.nav-item-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--rfull);
  background: rgba(0,242,254,0.12);
  color: var(--accent-primary);
  border: 1px solid rgba(0,242,254,0.2);
  flex-shrink: 0;
}
.nav-item-badge.new {
  background: rgba(16,185,129,0.12);
  color: var(--green-400);
  border-color: rgba(16,185,129,0.2);
}

/* Sidebar Bottom */
.sidebar-bottom {
  flex-shrink: 0;
  border-top: 1px solid var(--border-dim);
  padding: var(--s3);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3);
  border-radius: var(--r3);
  cursor: pointer;
  transition: all var(--t-base);
}
.sidebar-user:hover { background: var(--glass-06); }
.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
  box-shadow: var(--glow-xs-cyan);
}
.sidebar-user-name  { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sidebar-user-role  { font-size: 11px; color: var(--text-muted); }

/* Sidebar mini-toggle button */
.sidebar-toggle-btn {
  position: fixed;
  top: 18px;
  left: calc(var(--sidebar-w) - 14px);
  width: 28px; height: 28px;
  background: var(--elevated);
  border: 1px solid var(--border-soft);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: calc(var(--z-sticky) + 1);
  transition: left var(--t-slow), background var(--t-base);
  color: var(--text-tertiary);
}
.sidebar-toggle-btn:hover { background: var(--surface); color: var(--text-primary); }
.sidebar.mini ~ .sidebar-toggle-btn { left: calc(var(--sidebar-w-mini) - 14px); }

/* ── Main Content Area ─────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: margin-left var(--t-slow);
  position: relative;
  z-index: var(--z-base);
}
.main-content.expanded { margin-left: var(--sidebar-w-mini); }

/* ── Top Bar ───────────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 0 var(--s8);
  background: rgba(6,6,20,0.85);
  backdrop-filter: var(--blur-lg);
  -webkit-backdrop-filter: var(--blur-lg);
  border-bottom: 1px solid var(--border-dim);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  flex-shrink: 0;
}

.topbar-hamburger {
  display: none;
  width: 36px; height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r2);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--t-fast);
}
.topbar-hamburger:hover { background: var(--glass-08); color: var(--text-primary); }

.topbar-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-right: auto;
}
.topbar-title span { color: var(--accent-primary); }

/* Search Bar */
.topbar-search {
  position: relative;
  flex: 0 0 280px;
}
.topbar-search input {
  background: var(--glass-04);
  border: 1px solid var(--border-dim);
  border-radius: var(--rfull);
  padding: 8px 16px 8px 38px;
  font-size: 13px;
  color: var(--text-primary);
  width: 100%;
  transition: all var(--t-base);
}
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search input:focus {
  border-color: rgba(0,242,254,0.3);
  background: var(--glass-06);
  box-shadow: var(--glow-xs-cyan);
}
.topbar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 15px; height: 15px;
}

/* Topbar Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.topbar-action-btn {
  width: 36px; height: 36px;
  border-radius: var(--rfull);
  background: var(--glass-04);
  border: 1px solid var(--border-dim);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--t-base);
  position: relative;
}
.topbar-action-btn:hover {
  background: var(--glass-08);
  border-color: rgba(0,242,254,0.2);
  color: var(--accent-primary);
  box-shadow: var(--glow-xs-cyan);
}
.topbar-action-btn svg { width: 16px; height: 16px; }
.topbar-notif-dot {
  position: absolute;
  top: 7px; right: 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: var(--glow-xs-cyan);
  border: 1.5px solid var(--deep);
}

/* User Profile Button */
.topbar-profile {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 4px 12px 4px 4px;
  background: var(--glass-04);
  border: 1px solid var(--border-dim);
  border-radius: var(--rfull);
  cursor: pointer;
  transition: all var(--t-base);
}
.topbar-profile:hover {
  background: var(--glass-08);
  border-color: rgba(0,242,254,0.2);
}
.topbar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #000;
}
.topbar-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Pages Container ───────────────────────────────────────────── */

.pages-container {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.page {
  display: none;
  padding: var(--s8);
  min-height: calc(100dvh - var(--topbar-h));
  animation: pageEnter 0.5s var(--ease-out) both;
}
.page.active { display: block; }

/* Page header */
.page-header {
  margin-bottom: var(--s8);
}
.page-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: var(--s2);
}
.page-header h1 .gradient-word {
  background: var(--grad-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.page-header p {
  font-size: 14px;
  color: var(--text-tertiary);
  max-width: 560px;
}

/* ── Grid Systems ──────────────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s6); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s6); }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s5); }

.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s5); }
.grid-auto-sm { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s4); }

/* Asymmetric grids */
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--s6); }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: var(--s6); }
.grid-3-1 { display: grid; grid-template-columns: 3fr 1fr; gap: var(--s6); }
.grid-1-3 { display: grid; grid-template-columns: 1fr 3fr; gap: var(--s6); }

/* Flex utilities */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-start { display: flex; align-items: flex-start; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: var(--s1); }
.gap-2 { gap: var(--s2); }
.gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); }
.gap-5 { gap: var(--s5); }
.gap-6 { gap: var(--s6); }
.gap-8 { gap: var(--s8); }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

/* ── Section Dividers ──────────────────────────────────────────── */

.section-gap { margin-bottom: var(--s8); }
.section-gap-lg { margin-bottom: var(--s12); }

/* ── Typography ────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: 1.25;
}

.text-xs   { font-size: 11px; }
.text-sm   { font-size: 12px; }
.text-base { font-size: 14px; }
.text-md   { font-size: 15px; }
.text-lg   { font-size: 17px; }
.text-xl   { font-size: 20px; }
.text-2xl  { font-size: 24px; }
.text-3xl  { font-size: 30px; }
.text-4xl  { font-size: 36px; }

.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.fw-900 { font-weight: 900; }

.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-muted     { color: var(--text-muted); }
.text-cyan      { color: var(--accent-primary); }
.text-forge     { color: var(--forge-orange); }
.text-green     { color: var(--green-400); }
.text-red       { color: var(--red-400); }
.text-amber     { color: var(--amber-400); }
.text-purple    { color: var(--purple-400); }

.font-mono { font-family: var(--font-mono); }
.font-brand { font-family: var(--font-brand); }
.font-display { font-family: var(--font-display); }

.uppercase { text-transform: uppercase; }
.tracking-wide  { letter-spacing: 1px; }
.tracking-wider { letter-spacing: 2px; }
.tracking-widest{ letter-spacing: 3px; }

/* ── Spacing Utilities ─────────────────────────────────────────── */

.mt-2 { margin-top: var(--s2); } .mt-3 { margin-top: var(--s3); }
.mt-4 { margin-top: var(--s4); } .mt-5 { margin-top: var(--s5); }
.mt-6 { margin-top: var(--s6); } .mt-8 { margin-top: var(--s8); }
.mb-2 { margin-bottom: var(--s2); } .mb-3 { margin-bottom: var(--s3); }
.mb-4 { margin-bottom: var(--s4); } .mb-5 { margin-bottom: var(--s5); }
.mb-6 { margin-bottom: var(--s6); } .mb-8 { margin-bottom: var(--s8); }

.p-4 { padding: var(--s4); } .p-5 { padding: var(--s5); }
.p-6 { padding: var(--s6); } .p-8 { padding: var(--s8); }

.w-full { width: 100%; }
.h-full { height: 100%; }
.min-w-0 { min-width: 0; }

/* ── Overflow ──────────────────────────────────────────────────── */

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

/* ── Display ───────────────────────────────────────────────────── */

.hidden { display: none !important; }
.invisible { visibility: hidden; }

/* ── Overlay / Modal ───────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: var(--blur-sm);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease both;
}
.overlay.hidden { display: none; }

.modal {
  background: linear-gradient(135deg, var(--panel) 0%, var(--elevated) 100%);
  border: 1px solid var(--border-mid);
  border-radius: var(--r6);
  padding: var(--s8);
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  overflow-y: auto;
  animation: scaleInSpring 0.4s var(--ease-spring) both;
  box-shadow: var(--shadow-2xl);
  position: relative;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s6);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--glass-06);
  border: 1px solid var(--border-dim);
  cursor: pointer;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.modal-close:hover { background: var(--glass-10); color: var(--text-primary); }

/* ── Toast Container ───────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: var(--s5);
  right: var(--s5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 12px 16px;
  background: var(--elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--r4);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  backdrop-filter: var(--blur-md);
  min-width: 280px;
  max-width: 380px;
  pointer-events: all;
  animation: toastIn 0.35s var(--ease-spring) both;
}
.toast.toast-exit { animation: toastOut 0.3s var(--ease-smooth) both; }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--green-400); }
.toast.error   .toast-icon { color: var(--red-400); }
.toast.info    .toast-icon { color: var(--accent-primary); }
.toast.warning .toast-icon { color: var(--amber-400); }
.toast.success { border-left: 3px solid var(--green-400); }
.toast.error   { border-left: 3px solid var(--red-400); }
.toast.info    { border-left: 3px solid var(--accent-primary); }
.toast.warning { border-left: 3px solid var(--amber-400); }

/* ── Responsive Breakpoints ────────────────────────────────────── */

@media (max-width: 1280px) {
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2-1 { grid-template-columns: 1fr; }
  .topbar-search { flex: 0 0 200px; }
}

@media (max-width: 900px) {
  .page { padding: var(--s5); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-1-2 { grid-template-columns: 1fr; }
  .grid-3-1 { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);
    z-index: var(--z-modal);
    box-shadow: var(--shadow-2xl);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .topbar-hamburger { display: flex; }
  .sidebar-toggle-btn { display: none; }
}

@media (max-width: 640px) {
  .page { padding: var(--s4); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .grid-5 { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 var(--s4); }
  .page-header h1 { font-size: 22px; }
  .modal { padding: var(--s5); border-radius: var(--r5); }
}

/* ── Mobile Overlay for Sidebar ────────────────────────────────── */

.sidebar-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: calc(var(--z-modal) - 1);
  backdrop-filter: blur(2px);
}
.sidebar-mobile-overlay.visible { display: block; }
