/* ============================================
   TOOLSLAB — APP SHELL & LAYOUT
   Handles: base reset, app grid, screen states,
   mobile-first responsive collapse.
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden; /* app behaves like a native shell, inner regions scroll */
}

body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur-base) var(--ease), color var(--dur-base) var(--ease);
}

/* subtle noise texture over the whole app — adds tactile depth without being visible as "a texture" */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.025;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
textarea, input { font-family: inherit; color: inherit; }
svg { display: block; }

/* ---------- APP SHELL ---------- */
#app {
  position: relative;
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  z-index: 2;
  overflow: hidden;
}

/* ---------- MAIN COLUMN (top bar + chat + input) ---------- */
.main-col {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ---------- SCREEN STATES ----------
   Only .screen-chat and .screen-settings toggle via [data-screen] on #app.
   Sidebar / sheets are overlays and layer independently. */
.screen { display: none; height: 100%; flex-direction: column; min-height: 0; overflow: hidden; }
.screen.is-active { display: flex; }

/* --- Home screen visibility rules --- */
#app[data-screen="chat"] .main-col > .screen-home { display: none; }
#app[data-screen="settings"] .main-col > .screen-home { display: none; }
#app[data-screen="home"] .main-col > .screen-chat { display: none; }
#app[data-screen="home"] .main-col > .screen-settings { display: none; }

#app[data-screen="settings"] .main-col > .screen-chat { display: none; }
#app[data-screen="chat"] .main-col > .screen-settings { display: none; }

/* settings pushes in from the right */
.screen-settings {
  position: absolute;
  inset: 0;
  background: var(--bg-app);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease);
  z-index: 5;
}
#app[data-screen="settings"] .screen-settings {
  transform: translateX(0);
  display: flex;
}

/* ---------- SCROLL REGIONS ---------- */
.scroll-y {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-med) transparent;
}
.scroll-y::-webkit-scrollbar { width: 6px; }
.scroll-y::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: var(--r-full); }

/* ---------- SETTINGS SCREEN ---------- */
.settings-topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-4);
  flex-shrink: 0;
}
.settings-topbar-title { font-size: var(--fs-base); font-weight: 600; }
.settings-body { flex: 1; min-height: 0; }
.settings-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-9);
  display: flex; flex-direction: column; gap: var(--sp-6);
}

.settings-account-card {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}
.settings-avatar-lg {
  width: 52px; height: 52px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-text-on);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--fs-lg);
  flex-shrink: 0;
}
.settings-account-email { font-size: var(--fs-base); font-weight: 500; color: var(--text-primary); }
.settings-plan-badge {
  display: inline-block; margin-top: var(--sp-1);
  font-size: var(--fs-xs); font-weight: 600;
  padding: 2px var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--bg-surface-3); color: var(--text-secondary);
}

.settings-upgrade-card {
  padding: var(--sp-5);
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border-subtle);
}
.settings-upgrade-title { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--sp-1); }
.settings-upgrade-sub { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: var(--sp-4); }

.settings-group { display: flex; flex-direction: column; gap: 2px; }
.settings-group-label { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 0 var(--sp-2) var(--sp-1); }

.settings-logout { color: var(--danger); font-weight: 500; }
.settings-logout .list-row-icon { color: var(--danger); }
.settings-logout:hover { background: rgba(224,93,93,0.08); }

/* ---------- RESPONSIVE: MOBILE COLLAPSE ---------- */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(300px, 84vw);
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    z-index: var(--z-sidebar);
    box-shadow: var(--sh-xl);
  }
  #app[data-sidebar="open"] .sidebar { transform: translateX(0); }

  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none;
    transition: opacity var(--dur-base) var(--ease);
    z-index: calc(var(--z-sidebar) - 1);
  }
  #app[data-sidebar="open"] .sidebar-overlay { opacity: 1; pointer-events: auto; }
}

@media (min-width: 861px) {
  .sidebar-overlay { display: none; }
  .hamburger-btn { display: none; } /* sidebar always visible on desktop */
  
  /* Home screen should span full width on desktop without sidebar */
  #app[data-screen="home"] { grid-template-columns: 1fr; }
  #app[data-screen="home"] .sidebar { display: none; }
}
