/* ═══════════════════════════════════════════════════════════════
   RepuVerse AI — Layout (Sidebar · Topbar · Main Grid)
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset ── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background: var(--bg-root);
  min-height: 100vh;
  overflow: hidden;
}

/* ── App shell ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns var(--dur-normal) var(--ease-out);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* ── Sidebar ── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  overflow: hidden;
  transition: width var(--dur-normal) var(--ease-out);
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-5);
  gap: var(--sp-3);
  border-bottom: var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-md);
  color: var(--text-inverse);
  flex-shrink: 0;
}

.sidebar-logo-img {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.sidebar-collapsed .sidebar-brand { opacity: 0; pointer-events: none; }

.sidebar-nav {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: var(--sp-4) var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-1);
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

.nav-section-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-collapsed .nav-section-label { opacity: 0; height: 0; padding: 0; }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 24px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-item-icon {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: var(--fs-md);
}

.nav-item-label {
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  opacity: 1;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.sidebar-collapsed .nav-item-label { opacity: 0; width: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 20px; text-align: center;
}

.sidebar-collapsed .nav-badge { display: none; }

.sidebar-footer {
  border-top: var(--border);
  padding: var(--sp-4) var(--sp-3);
  flex-shrink: 0;
}

.sidebar-collapse-btn {
  width: 100%; display: flex; align-items: center; justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: none; border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--fs-base);
  transition: all var(--dur-fast) var(--ease-out);
}

.sidebar-collapse-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }

/* ── Topbar ── */
.topbar {
  grid-area: topbar;
  background: var(--bg-surface);
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  z-index: var(--z-topbar);
}

.topbar-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  flex-shrink: 0;
}

.topbar-search {
  flex: 1; max-width: 420px;
  position: relative;
}

.topbar-search input {
  width: 100%;
  padding: var(--sp-2) var(--sp-4) var(--sp-2) 40px;
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: var(--fs-base);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--dur-fast);
}

.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search input:focus { border-color: var(--accent); }

.topbar-search .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: var(--fs-md); pointer-events: none;
}

.topbar-actions {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-left: auto;
}

.topbar-btn {
  width: 40px; height: 40px;
  border: none; border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: var(--fs-md);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: all var(--dur-fast) var(--ease-out);
}

.topbar-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.topbar-btn .badge {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-surface);
}

.topbar-avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-2), var(--accent-3));
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  color: #fff;
  cursor: pointer;
  transition: box-shadow var(--dur-fast);
}

.topbar-avatar:hover { box-shadow: var(--shadow-glow-purple); }

/* ── Main content ── */
.main-content {
  grid-area: main;
  background: var(--bg-body);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-6);
}

.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

/* Page containers */
.page { display: none; }
.page.active { display: block; animation: pageIn var(--dur-slow) var(--ease-out) both; }

/* ── Responsive ── */

/* Tablet & below */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
      "topbar"
      "main";
    height: 100vh;
    height: 100dvh;
  }

  /* Bottom nav: FIXED position — works on all real phones */
  .sidebar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    height: 60px !important;
    width: 100% !important;
    grid-area: unset;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid rgba(255,255,255,.08);
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--bg-surface) !important;
    z-index: 9999 !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,.5);
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .sidebar-header,
  .sidebar-footer,
  .nav-section-label { display: none; }

  .sidebar-nav {
    flex-direction: row;
    padding: var(--sp-1) var(--sp-2);
    gap: 0;
    justify-content: space-around;
    width: 100%;
    flex-shrink: 0;
    align-items: center;
    height: 100%;
  }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-1) var(--sp-2);
    font-size: var(--fs-xs);
    min-width: 0;
    flex: 1;
    justify-content: center;
    align-items: center;
    border-radius: var(--radius-sm);
    text-decoration: none;
  }

  .nav-item.active::before { display: none; }

  .nav-item.active {
    background: var(--accent-dim);
  }

  .nav-item-icon {
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
  }

  .nav-item-label {
    font-size: 9px;
    opacity: 1 !important;
    width: auto !important;
    text-align: center;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 72px;
  }

  .nav-badge { display: none; }

  /* Main content: bottom padding clears the fixed nav */
  .main-content {
    padding: var(--sp-4);
    padding-bottom: 76px;
  }

  .topbar-title {
    font-size: var(--fs-md);
  }

  .topbar-search {
    max-width: 260px;
  }
}

/* Mobile phone */
@media (max-width: 640px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    height: 100dvh;
    grid-template-rows: 54px 1fr;
  }

  .sidebar {
    height: 56px;
  }

  .topbar {
    padding: 0 var(--sp-3);
    gap: var(--sp-2);
  }

  .topbar-title {
    font-size: var(--fs-base);
  }

  .topbar-search { display: none; }

  .topbar-btn {
    width: 34px; height: 34px;
    font-size: var(--fs-sm);
  }

  .topbar-avatar {
    width: 32px; height: 32px;
    font-size: var(--fs-xs);
  }

  .main-content {
    padding: var(--sp-3);
    padding-bottom: 72px;
    -webkit-overflow-scrolling: touch;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
  }

  .page-header h1 {
    font-size: var(--fs-xl);
  }

  .page-subtitle {
    font-size: var(--fs-sm);
  }

  .sidebar-nav {
    padding: var(--sp-1) 0;
  }

  .nav-item {
    padding: var(--sp-1);
    min-width: 44px;
  }

  .nav-item-label {
    font-size: 8px;
    max-width: 56px;
  }
}

