/* side-panel.css — the two side panels, one grammar: the Rooms panel on the
   LEFT edge (navigation, account — the old sidebar's own markup) and the
   Chats panel on the RIGHT edge (new chat, search, conversation history).

     HIDDEN   only a slim vertical tab on the panel's own edge (44 px hand)
     OPEN     slides in over the content; auto-hides 2.5 s after the pointer
              leaves it, on Esc, on a press outside, after a room or a
              conversation is chosen
     PINNED   docked: the main column yields by the panel width on that side
              and it never auto-hides until unpinned

   State is carried on the <aside data-side data-state="hidden|open|pinned">
   and mirrored on <html class="sp-left-pinned sp-right-pinned …"> for the
   yield. Every colour is one of the app's own tokens: --panel, --border,
   --text, --accent, --kit-seal. Phone first (375×812); desk and tablet
   inherit. Built by js/side-panel.js. */

:root {
  --sp-left-w: var(--sidebar-w, 260px);
  --sp-right-w: 320px;
  --sp-ease: 600ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
@media (max-width: 899.98px) { :root { --sp-right-w: 300px; } }

/* ---------- the tabs (HIDDEN state) ---------- */
.side-panel-tab {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;                 /* the hand */
  min-height: 132px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  z-index: var(--z-bar, 200);
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--sp-ease), visibility 0s linear 0s;
}
.side-panel-tab-right { right: 0; justify-content: flex-end; }
.side-panel-tab-left { left: 0; justify-content: flex-start; }
.side-panel-tab-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 30px;
  min-height: 132px;
  padding: 14px 0;
  border: 1px solid var(--border);
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
  color: var(--text);
}
.side-panel-tab-right .side-panel-tab-face { border-right: 0; border-radius: var(--radius-md) 0 0 var(--radius-md); box-shadow: -1px 0 0 var(--text); }
.side-panel-tab-left .side-panel-tab-face { border-left: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; box-shadow: 1px 0 0 var(--text); }
.side-panel-tab-face svg { flex: none; }
.side-panel-tab-word {
  writing-mode: vertical-rl;
  font: 600 11px/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}
.side-panel-tab-right .side-panel-tab-word { transform: rotate(180deg); }
.side-panel-tab:hover .side-panel-tab-face,
.side-panel-tab:focus-visible .side-panel-tab-face { border-color: var(--accent); color: var(--accent); }
.side-panel-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* while the panel is out its tab steps aside — the panel's own close does the job */
.side-panel-tab[aria-expanded="true"] { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--sp-ease), visibility 0s linear 600ms; }

/* ---------- the panels ---------- */
.side-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  height: 100dvh;
  max-width: 100vw;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  backdrop-filter: blur(16px) saturate(1.1);
  color: var(--text);
  z-index: calc(var(--z-drawer, 900) + 1);
  visibility: hidden;
  transition: transform var(--sp-ease), visibility 0s linear 600ms;
}
.side-panel-right {
  right: 0;
  width: var(--sp-right-w);
  border-left: 1px solid var(--border);
  box-shadow: -1px 0 0 var(--text), -12px 0 40px rgba(0, 0, 0, 0.14);   /* 1 px pearl hairline on its left edge */
  transform: translateX(100%);
}
.side-panel-left {
  left: 0;
  width: var(--sp-left-w);
  border-right: 1px solid var(--border);
  box-shadow: 1px 0 0 var(--text), 12px 0 40px rgba(0, 0, 0, 0.14);     /* 1 px pearl hairline on its right edge */
  transform: translateX(-100%);
}
.side-panel[data-state="open"],
.side-panel[data-state="pinned"] {
  transform: translateX(0);
  visibility: visible;
  transition: transform var(--sp-ease), visibility 0s linear 0s;
}
.side-panel-right[data-state="pinned"] { box-shadow: -1px 0 0 var(--text); }
.side-panel-left[data-state="pinned"] { box-shadow: 1px 0 0 var(--text); }
/* a pinned panel is part of the page, not a drawer over it */
.side-panel[data-state="pinned"], .sidebar.side-panel[data-state="pinned"].is-open { z-index: var(--z-bar, 200) !important; }

/* the main column yields to a pinned panel; nothing else moves */
.main { transition: padding-left var(--sp-ease), padding-right var(--sp-ease); }
html.sp-left-pinned .main { padding-left: var(--sp-left-w); }
html.sp-right-pinned .main { padding-right: var(--sp-right-w); }

/* the resize hand on the panel's inner edge (desk only) */
.side-panel-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  background: transparent;
  border: 0;
  padding: 0;
  display: none;
}
.side-panel-right .side-panel-resize { left: -4px; }
.side-panel-left .side-panel-resize { right: -4px; }
.side-panel-resize:focus-visible { outline: 2px solid var(--accent); }
@media (min-width: 900px) and (hover: hover) and (pointer: fine) { .side-panel-resize { display: block; } }

/* ---------- head ---------- */
.side-panel-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 6px 6px 6px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.side-panel-title {
  flex: 1;
  margin: 0;
  font: 700 12px/1 var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
}
.side-panel-head .icon-btn { width: 44px; height: 44px; display: inline-flex; color: var(--text); border-radius: var(--radius-pill); }
.side-panel-head .icon-btn:hover { background: var(--accent-soft, rgba(0,0,0,.06)); }
.side-panel-pin[aria-pressed="true"] { color: var(--kit-seal); background: var(--accent-soft, rgba(0,0,0,.06)); }
.side-panel-pin[aria-pressed="true"] svg { transform: rotate(-35deg); }
.side-panel-pin svg { transition: transform 200ms ease; }

/* ---------- the head's view strip (right panel): Chats | Team, the
   active one underlined in the accent — same grammar as the back end's
   Explorer | Terminal strip ---------- */
.side-panel-views { flex: 1; display: flex; align-items: stretch; align-self: stretch; gap: 2px; min-width: 0; }
.side-panel-view {
  min-width: 44px; min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--text-muted, var(--text));
  font: 700 11px/1 var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -5px;
}
.side-panel-view:hover { color: var(--text); }
.side-panel-view.is-active { color: var(--text); border-bottom-color: var(--accent); }
.side-panel-view:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.side-panel-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-panel-pane[hidden] { display: none; }

/* ---------- new chat: a primary hollow button ---------- */
.side-panel-newchat {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 12px 12px 4px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  flex: none;
  transition: background 150ms ease, color 150ms ease;
}
.side-panel-newchat:hover { background: var(--accent); color: var(--accent-contrast, var(--panel)); }

/* ---------- search ---------- */
.side-panel-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 6px;
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  flex: none;
}
.side-panel-search:focus-within { border-color: var(--accent); }
.side-panel-search svg { flex: none; opacity: .7; }
.side-panel-search input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.side-panel-search input::placeholder { color: var(--text); opacity: .55; }
.side-panel-search kbd {
  font: 600 10px/1 var(--font-mono);
  letter-spacing: .04em;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  opacity: .65;
  display: none;
}
@media (hover: hover) and (pointer: fine) { .side-panel-search kbd { display: inline-block; } }

/* ---------- the scrolling middle ---------- */
.side-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.side-panel-list { padding: 4px 8px 10px; }
.side-panel-list .history-item { color: var(--text); min-height: 44px; }   /* a 44 px hand on every row */
.side-panel-list .history-item.is-active { background: var(--accent-soft, rgba(0,0,0,.06)); box-shadow: inset 2px 0 0 var(--kit-seal); color: var(--text); }
.side-panel-left .sidebar-nav { border-top: 0; }
.side-panel-left .sidebar-user { flex: none; }

/* ---------- under 900 px the phone tab bar rides over the panels' foot ----------
   (#shell is its own stacking context; the bar is its sibling): pad the foot
   by the bar's height so nothing in a panel is hidden. */
@media (max-width: 899.98px) {
  .side-panel { padding-bottom: calc(var(--tabbar-h, 60px) + env(safe-area-inset-bottom)); }
}

/* ---------- phone: a full-height sheet from its own edge ---------- */
@media (max-width: 480px) {
  .side-panel {
    width: calc(100% - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    padding-top: env(safe-area-inset-top) !important;
    padding-bottom: calc(var(--tabbar-h, 60px) + env(safe-area-inset-bottom)) !important;
    z-index: calc(var(--z-drawer, 900) + 1) !important;
  }
  .side-panel-pin { display: none !important; }            /* pinning is disabled on a phone */
  html.sp-left-pinned .main { padding-left: 0 !important; }
  html.sp-right-pinned .main { padding-right: 0 !important; }
  .side-panel-resize { display: none !important; }
  .side-panel-head { padding-left: 14px; }
  .side-panel-head .icon-btn { min-width: 44px; min-height: 44px; }
  /* the tabs sit above the bottom nav and never cover the composer or the
     orb: vertically centred on their own edges they are clear of both (measured). */
  .side-panel-tab { top: 50% !important; bottom: auto !important; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .side-panel, .side-panel-tab, .side-panel-pin svg, .main { transition: none !important; }
  .side-panel-tab[aria-expanded="true"] { transition: none !important; }
}
