/* ---------- App shell ---------- */
.layout { display: flex; width: 100%; height: 100vh; height: 100dvh; background: var(--bg); }
.main {
  flex: 1; min-width: 0;
  position: relative;
  display: flex; flex-direction: column;
  background: var(--bg);
}

/* ---------- Sidebar (H4, I1) ---------- */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-side);
  display: flex; flex-direction: column; gap: 2px;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
  transition: margin-left .28s var(--ease), transform .28s var(--ease);
  z-index: 30;
}
.layout.sidebar-closed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.sidebar-head { display: flex; justify-content: space-between; padding: 0 0 6px; }
.new-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  transition: background .15s;
}
.new-chat:hover { background: var(--bg-hover); }
.logo-dot {
  width: 24px; height: 24px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #b85c3f);
  display: grid; place-items: center; color: #fff;
}
.search {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 0 4px; padding: 0 10px;
  height: 36px; border-radius: 10px;
  color: var(--text-3);
  transition: background .15s;
}
.search:hover, .search:focus-within { background: var(--bg-hover); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 14px; color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }

.thread-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px 8px; }
.thread-group { margin-top: 16px; }
.thread-group:first-child { margin-top: 6px; }
.thread-group-title { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 4px 10px; }
.thread { position: relative; display: flex; align-items: center; border-radius: 10px; font-size: 14px; transition: background .12s; }
.thread:hover { background: var(--bg-hover); }
.thread.active { background: var(--bg-active); }
.thread-link {
  flex: 1; min-width: 0; padding: 8px 10px; text-align: left;
  white-space: nowrap; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent);
  mask-image: linear-gradient(90deg, #000 82%, transparent);
}
.thread-actions { display: flex; opacity: 0; transition: opacity .12s; padding-right: 4px; }
.thread:hover .thread-actions, .thread.active .thread-actions, .thread:focus-within .thread-actions { opacity: 1; }
.thread-actions .icon-btn { width: 28px; height: 28px; border-radius: 7px; }
.thread-rename {
  flex: 1; min-width: 0; margin: 3px; padding: 5px 8px;
  border: 1px solid var(--brand); border-radius: 8px;
  background: var(--bg); outline: none; font-size: 16px;
}
.thread-empty { color: var(--text-3); font-size: 13px; padding: 14px 10px; }
.thread.streaming .thread-link::after {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 8px;
  border-radius: 50%; background: var(--brand); vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.foot-btn { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; font-size: 14px; text-align: left; }
.foot-btn:hover { background: var(--bg-hover); }
.foot-btn .ico { color: var(--text-2); }

.backdrop {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px 10px;
  min-height: calc(54px + var(--safe-top));
  position: relative; z-index: 5;
  background: var(--bg);
}
.topbar-spacer { flex: 1; }
#btn-menu { display: none; }
.layout.sidebar-closed #btn-menu { display: inline-grid; }
#btn-new-top { display: none; }
.layout.sidebar-closed #btn-new-top { display: inline-grid; }
.model-chip {
  position: relative; min-width: 0; min-height: 40px;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 14px; border-radius: 999px;
  font-size: 17px; font-weight: 600;
  max-width: 60vw;
  transition: background .15s;
}
.model-chip:has(select:not([hidden])):hover { background: var(--bg-hover); }
.model-chip:has(select:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-model-select { display: none; }
.model-chip .chev { color: var(--text-3); }
.model-chip { cursor: pointer; }
.model-chip[aria-expanded="true"] { background: var(--bg-soft); }
.model-chip[aria-expanded="true"] .chev { transform: rotate(180deg); }
/* Higher specificity than the shared .menu rules loaded in popups.css. */
.menu.model-menu {
  top: calc(100% + 8px); bottom: auto; left: 0;
  width: min(280px, 75vw); min-width: 0; max-width: none;
  max-height: min(60dvh, 480px); overflow-y: auto;
  padding: 8px; border-radius: 22px; transform-origin: top left;
}
.menu.model-menu button {
  position: relative; min-height: 56px; padding: 9px 12px 9px 34px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  border-radius: 12px; line-height: 1.4; overflow-wrap: anywhere;
}
.model-menu .model-option-name { font-weight: 600; }
.model-menu .model-option-detail { color: var(--text-2); font-size: 12px; font-weight: 400; }
.menu.model-menu button[aria-selected="true"]::before {
  content: '✓'; position: absolute; left: 10px; top: 18px; color: var(--text);
}
.menu.model-menu button:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }

/* ---------- Mobile: sidebar becomes a drawer ---------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(84vw, 320px);
    transform: translateX(-100%);
    box-shadow: none;
  }
  .layout.sidebar-closed .sidebar { margin-left: 0; }
  .layout.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .layout.drawer-open .backdrop { opacity: 1; pointer-events: auto; }
  #btn-menu, #btn-new-top { display: inline-grid; }
  #btn-collapse { display: none; }
  .kbd { display: none; }
  .thread-actions { opacity: 1; }
  .topbar {
    min-height: calc(58px + var(--safe-top));
    padding-top: calc(8px + var(--safe-top));
    padding-left: calc(14px + var(--safe-left));
    padding-right: calc(14px + var(--safe-right));
  }
  .model-chip { font-size: 16px; min-height: 38px; padding-inline: 10px; }
}
