/* ═══════════════════════════════════════════════════════════════════════════
   CTRL-A Shell — Shared left nav + right chat panel
   Include on any page: <link rel="stylesheet" href="/shared/shell.css">
   Requires: theme.css loaded first for CSS custom properties
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Left Sidebar ─────────────────────────────────────────────────────────── */
.shell-sidebar {
  position: fixed; top: 0; left: 0; height: 100vh;
  background: var(--t-surface); border-right: 1px solid var(--t-border);
  z-index: 200; display: flex; flex-direction: column;
  transition: width .3s cubic-bezier(.4,0,.2,1);
  width: 64px; overflow: hidden;
}
.shell-sidebar.open { width: 220px; }

.shell-sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: 56px; border-bottom: 1px solid var(--t-border);
  flex-shrink: 0; overflow: hidden; white-space: nowrap; cursor: pointer;
  text-decoration: none;
}
.shell-sidebar-brand-icon {
  width: 32px; height: 32px; min-width: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--t-accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 800;
}
.shell-sidebar-brand-text {
  font-size: 14px; font-weight: 700; color: var(--t-text);
  opacity: 0; transition: opacity .2s;
}
.shell-sidebar.open .shell-sidebar-brand-text { opacity: 1; }

.shell-sidebar-toggle {
  width: 100%; padding: 14px 0;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  color: var(--t-text2); transition: all .15s; flex-shrink: 0;
}
.shell-sidebar-toggle:hover { background: var(--t-surface2); color: var(--t-text); }
.shell-sidebar-toggle svg { flex-shrink: 0; transition: transform .3s; }
.shell-sidebar.open .shell-sidebar-toggle svg { transform: rotate(180deg); }

.shell-sidebar-nav {
  flex: 1; overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.shell-sidebar-section {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--t-text3); padding: 8px 16px 4px;
  opacity: 0; transition: opacity .2s; white-space: nowrap;
}
.shell-sidebar.open .shell-sidebar-section { opacity: 1; }
.shell-sidebar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; border: none;
  background: transparent; cursor: pointer; color: var(--t-text2);
  font-size: 13px; font-weight: 500; transition: all .15s;
  white-space: nowrap; overflow: hidden;
  text-decoration: none; width: 100%; text-align: left;
}
.shell-sidebar-item:hover { background: var(--t-surface2); color: var(--t-text); }
.shell-sidebar-item.active { background: var(--t-accent-bg); color: var(--t-accent-lt); }
.shell-sidebar-item-icon {
  width: 36px; min-width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.shell-sidebar-item-label { opacity: 0; transition: opacity .2s; }
.shell-sidebar.open .shell-sidebar-item-label { opacity: 1; }
.shell-sidebar-divider { height: 1px; background: var(--t-border); margin: 8px 12px; }

/* ── Floating Theme Toggle (top-right) ───────────────────────────────────── */
.shell-theme-toggle {
  position: fixed; top: 14px; right: 30px; z-index: 210;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--t-border); background: var(--t-surface);
  color: var(--t-text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  transition: right .3s cubic-bezier(.4,0,.2,1), background .15s, color .15s, border-color .15s;
  box-shadow: var(--t-shadow);
}
.shell-theme-toggle:hover {
  background: var(--t-card-hover); color: var(--t-text);
  border-color: var(--t-border-lt);
}
/* Shift right when chat panel is open */
body:not(.shell-chat-collapsed) .shell-theme-toggle { right: 370px; }

/* ── Right Chat Panel ─────────────────────────────────────────────────────── */
.shell-chat {
  position: fixed; top: 0; right: 0; height: 100vh; width: 340px;
  background: var(--t-surface); border-left: 1px solid var(--t-border);
  z-index: 200; display: flex; flex-direction: column;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  transform: translateX(0);
}
.shell-chat.collapsed { transform: translateX(100%); }

.shell-chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--t-border); flex-shrink: 0;
}
.shell-chat-title { font-size: 14px; font-weight: 700; color: var(--t-text); flex: 1; }
.shell-chat-close {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--t-border);
  background: transparent; color: var(--t-text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.shell-chat-close:hover { background: var(--t-surface2); color: var(--t-text); }

/* Agent list (default view) */
.shell-agent-list { flex: 1; overflow-y: auto; padding: 8px; }
.shell-agent-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  transition: all .15s; border: none; background: transparent;
  width: 100%; text-align: left; color: inherit;
}
.shell-agent-row:hover { background: var(--t-surface2); }
.shell-agent-row.active { background: var(--t-accent-bg); }
.shell-agent-avatar {
  width: 36px; height: 36px; min-width: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.shell-agent-info { flex: 1; min-width: 0; }
.shell-agent-name {
  font-size: 13px; font-weight: 600; color: var(--t-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-agent-role {
  font-size: 11px; color: var(--t-text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-agent-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--t-success); flex-shrink: 0;
}

/* Search in agent list */
.shell-agent-search {
  display: flex; align-items: center; padding: 8px 12px;
  border-bottom: 1px solid var(--t-border); flex-shrink: 0;
}
.shell-agent-search input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--t-border);
  border-radius: 8px; background: var(--t-input-bg); color: var(--t-text);
  font-size: 13px; outline: none; font-family: inherit;
}
.shell-agent-search input:focus { border-color: var(--t-accent); }
.shell-agent-search input::placeholder { color: var(--t-text3); }

/* Chat conversation view */
.shell-chat-conv { display: none; flex-direction: column; flex: 1; min-height: 0; }
.shell-chat-conv.active { display: flex; }
.shell-chat-agent-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--t-border); flex-shrink: 0;
}
.shell-chat-back {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--t-border);
  background: transparent; color: var(--t-text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.shell-chat-back:hover { background: var(--t-surface2); color: var(--t-text); }
.shell-chat-agent-name { font-size: 13px; font-weight: 600; color: var(--t-text); flex: 1; }
.shell-chat-messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.shell-msg {
  max-width: 90%; padding: 10px 14px; border-radius: 14px;
  font-size: 13px; line-height: 1.5; word-wrap: break-word;
}
.shell-msg.user {
  align-self: flex-end; background: var(--t-accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.shell-msg.ai {
  align-self: flex-start; background: var(--t-surface2); color: var(--t-text);
  border: 1px solid var(--t-border); border-bottom-left-radius: 4px;
}
.shell-msg.ai strong { color: var(--t-text); }
.shell-msg.ai code {
  background: var(--t-code-bg); padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-family: var(--t-font-mono);
}
.shell-chat-input-area {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--t-border); flex-shrink: 0;
  align-items: flex-end;
}
.shell-chat-input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--t-border);
  border-radius: 10px; background: var(--t-input-bg); color: var(--t-text);
  font-size: 13px; outline: none; font-family: inherit;
  min-height: 60px; max-height: 120px; overflow-y: auto; resize: none;
  line-height: 1.4;
}
.shell-chat-input:focus { border-color: var(--t-accent); }
.shell-chat-input::placeholder { color: var(--t-text3); }
.shell-chat-send {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: var(--t-border); color: var(--t-text2); cursor: default;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all .15s;
}
.shell-chat-send.ready {
  background: linear-gradient(135deg, #8b5cf6, var(--t-accent));
  color: #fff; cursor: pointer;
}

/* Toggle button on edge */
.shell-chat-toggle {
  position: fixed; top: 50%; right: 0; transform: translateY(-50%);
  z-index: 201; width: 36px; height: 72px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1); border: none;
  border-radius: 10px 0 0 10px; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  box-shadow: -2px 0 8px rgba(99,102,241,.3);
}
.shell-chat-toggle:hover { background: linear-gradient(135deg, #7c3aed, #4f46e5); box-shadow: -2px 0 12px rgba(99,102,241,.5); }
.shell-chat-toggle.shifted { right: 340px; }

/* Typing indicator */
.shell-typing { display: flex; gap: 4px; padding: 10px 14px; align-self: flex-start; }
.shell-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--t-text3);
  animation: shell-pulse 1.2s ease-in-out infinite;
}
.shell-typing span:nth-child(2) { animation-delay: .15s; }
.shell-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes shell-pulse { 0%,80%,100%{opacity:.3;transform:scale(.8)} 40%{opacity:1;transform:scale(1)} }

/* ── Main Content Push ────────────────────────────────────────────────────── */
.shell-main {
  margin-left: 64px; margin-right: 340px;
  transition: margin-left .3s, margin-right .3s;
  min-height: 100vh;
}
body.shell-sidebar-open .shell-main { margin-left: 220px; }
body.shell-chat-collapsed .shell-main { margin-right: 0; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell-sidebar { width: 0 !important; overflow: hidden; }
  .shell-sidebar.open { width: 0 !important; overflow: hidden; }
  .shell-chat { width: 100%; }
  .shell-main { 
    margin-left: 0 !important; 
    margin-right: 0 !important; 
    width: 100%;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  .shell-chat-toggle { display: none !important; }
  .shell-theme-toggle { right: 16px !important; }
  .shell-chat { display: none !important; }
}
