/* ============================================================
   shell.css — AppShell Grid Layout (E1 skeleton)
   ============================================================ */

/* ── Grid Root ────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 64px var(--task-sidebar-w, 260px) minmax(0, 1fr) var(--inspector-w, 0px);
  grid-template-rows: 1fr;
  grid-template-areas: "nav sidebar main inspector";
  height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 2;
}

/* ── Collapsed States ─────────────────────────────────────── */
.app-shell.sidebar-collapsed {
  grid-template-columns: 64px 0px minmax(0, 1fr) var(--inspector-w, 0px);
}
.app-shell.sidebar-collapsed .task-sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.app-shell.inspector-visible {
  --inspector-w: 400px;
}

/* ── Global Nav (64px icon rail) ──────────────────────────── */
.global-nav {
  grid-area: nav;
  width: 64px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  background: var(--bg2, #1e1e2e);
  border-right: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  z-index: 50;
  user-select: none;
  -webkit-user-select: none;
}

.gn-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.2s;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.gn-logo:hover {
  background: var(--bg3, rgba(255,255,255,0.06));
}
.gn-logo svg {
  width: 36px;
  height: 36px;
}

.gn-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.gn-spacer {
  flex: 1;
}

.gn-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.gn-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: var(--text2, #a0a0b0);
  transition: background 0.2s, color 0.2s;
  position: relative;
}
.gn-btn:hover {
  background: var(--bg3, rgba(255,255,255,0.08));
  color: var(--text1, #e0e0e8);
}
.gn-btn.active {
  background: var(--accent-bg, rgba(99,102,241,0.15));
  color: var(--accent, #818cf8);
}
.gn-btn.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent, #818cf8);
}

/* ── Task Sidebar ─────────────────────────────────────────── */
.task-sidebar {
  grid-area: sidebar;
  width: var(--task-sidebar-w, 260px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg2, #1e1e2e);
  border-right: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  transition: transform 0.25s ease, opacity 0.25s ease, width 0.25s ease;
  overflow: hidden;
  position: relative;
}

.task-sidebar .sidebar-overlay {
  display: none;
}

.ts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  flex-shrink: 0;
}
.ts-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text1, #e0e0e8);
}

.ts-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--text3, #707080);
  transition: background 0.2s, color 0.2s;
}
.ts-toggle:hover {
  background: var(--bg3, rgba(255,255,255,0.08));
  color: var(--text1, #e0e0e8);
}

.new-chat-btn {
  margin: 4px 16px 8px;
  padding: 8px 0;
  border: 1px dashed var(--glass-border, rgba(255,255,255,0.12));
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2, #a0a0b0);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.new-chat-btn:hover {
  background: var(--accent-bg, rgba(99,102,241,0.1));
  color: var(--accent, #818cf8);
  border-color: var(--accent, #818cf8);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px;
}

.ts-footer {
  display: flex;
  gap: 4px;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  flex-shrink: 0;
}
.ts-footer button {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--text3, #707080);
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.ts-footer button:hover {
  background: var(--bg3, rgba(255,255,255,0.08));
  color: var(--text1, #e0e0e8);
}

/* ── Main Workspace ───────────────────────────────────────── */
.main-workspace {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  position: relative;
}

.workspace-header {
  height: var(--topbar-h, 52px);
  min-height: var(--topbar-h, 52px);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg2, #1e1e2e);
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  z-index: 10;
  gap: 12px;
}

.wh-menu-btn {
  width: 36px;
  height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: var(--text2, #a0a0b0);
  transition: background 0.2s;
  flex-shrink: 0;
}
.wh-menu-btn:hover {
  background: var(--bg3, rgba(255,255,255,0.08));
}

.wh-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text1, #e0e0e8);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wh-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.composer-root {
  flex-shrink: 0;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg2, #1e1e2e);
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.06));
}

/* ── Inspector (right panel) ──────────────────────────────── */
.inspector-root {
  grid-area: inspector;
  width: var(--inspector-w, 0px);
  height: 100dvh;
  overflow: hidden;
  background: var(--bg2, #1e1e2e);
  border-left: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, opacity 0.25s ease;
}
.app-shell:not(.inspector-visible) .inspector-root {
  width: 0;
  opacity: 0;
  pointer-events: none;
  border-left: none;
}

.insp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  flex-shrink: 0;
}
.insp-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text1, #e0e0e8);
}

.insp-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--text3, #707080);
  transition: background 0.2s, color 0.2s;
}
.insp-close:hover {
  background: var(--bg3, rgba(255,255,255,0.08));
  color: var(--text1, #e0e0e8);
}

.insp-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
}

/* ── Responsive: Tablet (< 1024px) ────────────────────────── */
@media (max-width: 1024px) {
  .wh-menu-btn {
    display: flex;
  }
  .task-sidebar {
    position: fixed;
    left: 64px;
    top: 0;
    bottom: 0;
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .app-shell.sidebar-collapsed .task-sidebar {
    left: 0;
  }
}

/* ── Responsive: Mobile (< 768px) ─────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 0 0 minmax(0, 1fr) 0;
    grid-template-areas: "main main main main";
  }

  .global-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 56px;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    z-index: 100;
    border-right: none;
    border-top: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  }

  .gn-logo {
    width: 36px;
    height: 36px;
    margin-bottom: 0;
  }
  .gn-logo svg {
    width: 30px;
    height: 30px;
  }

  .gn-actions {
    flex-direction: row;
    gap: 2px;
  }

  .gn-bottom {
    flex-direction: row;
    gap: 2px;
    margin-bottom: 0;
  }

  .gn-spacer {
    display: none;
  }

  .gn-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .gn-btn.active::before {
    left: 50%;
    top: auto;
    bottom: 0;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  .task-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 320px);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .task-sidebar.show {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .task-sidebar .sidebar-overlay {
    display: none;
  }
  .task-sidebar.show .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: -1;
  }

  .main-workspace {
    height: calc(100dvh - 56px);
  }

  .wh-menu-btn {
    display: flex;
  }

  .inspector-root {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 360px);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  }
  .inspector-root.show {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
}