/* Home23 Chat — tile, overlay, standalone — ReginaCosmo glass-morphism */

/* ── Chat Tile (in home grid) ── */

.h23-tile-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  padding: 0;
  overflow: hidden;
  border-radius: 22px;
  background:
    radial-gradient(circle at top right, rgba(42, 214, 214, 0.08), transparent 34%),
    linear-gradient(180deg, rgba(6, 40, 55, 0.94), rgba(6, 26, 40, 0.96));
}

.h23-chat-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.h23-chat-selects {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1.2fr);
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.h23-chat-selects-overlay {
  grid-template-columns: minmax(150px, 0.7fr) minmax(220px, 1.3fr);
  min-width: min(560px, 100%);
}

.h23-chat-agent-select {
  background: var(--glass-secondary);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  width: 100%;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.h23-chat-agent-select:focus {
  border-color: var(--accent-blue);
}

.h23-chat-model-select {
  background: var(--glass-secondary);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  width: 100%;
  min-width: 0;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.h23-chat-model-select:focus {
  border-color: var(--accent-blue);
}

.h23-chat-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-self: start;
}

.h23-chat-expand-btn {
  background: none;
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.h23-chat-expand-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ── Messages Area ── */

.h23-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(2, 17, 28, 0.44);
}

.h23-chat-msg {
  max-width: 90%;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.h23-chat-msg.user {
  align-self: flex-end;
  background: rgba(10, 132, 255, 0.2);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 12px 12px 4px 12px;
}

.h23-chat-msg.assistant {
  align-self: flex-start;
  color: var(--text-primary);
  padding: 8px 0;
}

.h23-chat-msg.assistant p {
  margin: 0 0 8px 0;
}
.h23-chat-msg.assistant p:last-child {
  margin-bottom: 0;
}
.h23-chat-msg.assistant code {
  background: var(--glass-secondary);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}
.h23-chat-msg.assistant pre {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  margin: 8px 0;
  line-height: 1.4;
}
.h23-chat-msg.assistant strong {
  color: #fff;
}
.h23-chat-msg.assistant ul, .h23-chat-msg.assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}
.h23-chat-msg.assistant li {
  margin-bottom: 2px;
}

/* ── Thinking ── */

.h23-chat-thinking {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 2px solid var(--glass-border);
  border-radius: 0 6px 6px 0;
}

/* ── Tool Cards ── */

.h23-chat-tool {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 4px 0;
}

.h23-chat-tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.h23-chat-tool-name {
  font-weight: 600;
  color: var(--accent-blue);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.h23-chat-tool-status {
  font-size: 10px;
  color: var(--text-muted);
}
.h23-chat-tool-status.done {
  color: var(--accent-green);
}
.h23-chat-tool-status.error {
  color: var(--accent-red);
}

.h23-chat-tool-args {
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow: auto;
}

.h23-chat-tool-result {
  color: var(--text-secondary);
  font-size: 11px;
  margin-top: 4px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ── Error ── */

.h23-chat-error {
  color: var(--accent-red);
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(255, 69, 58, 0.08);
  border-radius: 6px;
}

/* ── Input Area ── */

.h23-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--glass-border);
  background: rgba(7, 26, 42, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
}

.h23-chat-input {
  flex: 1;
  background: var(--glass-secondary);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 120px;
}
.h23-chat-input:focus {
  border-color: var(--accent-blue);
}

.h23-chat-input::placeholder {
  color: var(--text-muted);
}

.h23-chat-send-btn {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.h23-chat-send-btn:hover {
  background: #3b82f6;
}
.h23-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Overlay ── */

.h23-chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background:
    radial-gradient(circle at top left, rgba(10, 132, 255, 0.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(0, 199, 190, 0.12), transparent 30%),
    rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(12px);
  padding: 24px;
}

.h23-chat-overlay.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.h23-chat-overlay-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05)),
    rgba(6, 12, 24, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 1100px;
  height: min(88vh, 940px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-glass);
  position: relative;
}

.h23-chat-overlay-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent);
}

.h23-chat-overlay-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

.h23-chat-overlay-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.h23-chat-overlay-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.46);
}

.h23-chat-overlay-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.h23-chat-overlay-controls {
  display: flex;
  align-items: start;
  gap: 12px;
  min-width: 0;
}

.h23-chat-overlay .h23-chat-messages {
  background:
    linear-gradient(180deg, rgba(2, 6, 23, 0.48), rgba(2, 6, 23, 0.18)),
    rgba(0, 0, 0, 0.18);
  padding: 18px 24px;
}

.h23-chat-overlay .h23-chat-input-area {
  padding: 16px 24px 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
}

.h23-chat-overlay .h23-chat-msg.assistant {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px 14px 14px 6px;
  padding: 10px 14px;
  max-width: min(94%, 820px);
}

/* ── System Stats Bar (relocated) ── */

.h23-system-bar {
  display: flex;
  gap: 24px;
  padding: 12px 20px;
  background: var(--glass-primary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: var(--shadow-glass);
}

.h23-system-bar-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.h23-system-bar-item label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
}

.h23-system-bar-item .value {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
}

/* ── Scrollbar for messages ── */

.h23-chat-messages::-webkit-scrollbar { width: 4px; }
.h23-chat-messages::-webkit-scrollbar-track { background: transparent; }
.h23-chat-messages::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 2px; }

/* ── Empty state ── */

.h23-chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ── Conversation List Panel ── */

.h23-chat-conv-panel {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--glass-primary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 5;
  flex-direction: column;
}
.h23-chat-conv-panel.open {
  display: flex;
}

.h23-chat-conv-list {
  flex: 1;
  overflow-y: auto;
}

.h23-chat-conv-item {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background 0.1s;
}
.h23-chat-conv-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.h23-chat-conv-item.active {
  background: rgba(10, 132, 255, 0.08);
  border-left: 2px solid var(--accent-blue);
}

.h23-chat-conv-preview {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.h23-chat-conv-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Make chat tile position:relative for the panel overlay */
.h23-tile-chat {
  position: relative;
}

@media (max-width: 980px) {
  .h23-chat-header,
  .h23-chat-overlay-header {
    grid-template-columns: 1fr;
  }

  .h23-chat-selects,
  .h23-chat-selects-overlay {
    grid-template-columns: 1fr;
  }

  .h23-chat-overlay-controls {
    width: 100%;
    flex-direction: column;
  }

  .h23-chat-actions {
    align-self: end;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   Task 3 additions — shared chat DOM (single message-list + input moves
   between tile and overlay slots via appendChild). The overlay stays a
   <div> with the existing .open-class pattern; this adds the slot layout
   rules so the moved subtree fills either container correctly. Task 6
   will consolidate everything in a full responsive pass.
   ═══════════════════════════════════════════════════════════════════════ */

.h23-chat-slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.h23-chat-shared {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* Within the overlay panel, the slot takes the remaining vertical space
   under the header and contains the moved #chat-shared node. */
.h23-chat-overlay-panel > .h23-chat-slot {
  flex: 1;
  overflow: hidden;
}

/* Narrow viewports: the overlay fills the screen rather than floating a
   small panel in the middle. */
@media (max-width: 900px) {
  .h23-chat-overlay {
    padding: 0;
  }
  .h23-chat-overlay-panel {
    max-width: 100vw;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   Task 7 additions — standalone page content max-width on wide screens
   The standalone page (/home23/chat) is intentionally mobile-first with a
   drawer + bottom sheet; on desktop viewports the message column would
   otherwise sprawl across the entire width. Cap it for readability.
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 1100px) {
  body > .sh-shell .sh-body {
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   Task 4 additions — agent pill + ⋯ menu popover
   ═══════════════════════════════════════════════════════════════════════ */

.h23-chat-agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: transparent;
  color: inherit;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  max-width: 60%;
  min-width: 0;
}
.h23-chat-agent-pill:hover {
  background: var(--glass-hover, rgba(255,255,255,0.06));
}
.h23-chat-agent-avatar {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-color, #0a84ff);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.h23-chat-agent-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Model pill — compact sibling of the agent pill. Shows the current model
   and opens the model picker on click. Wider than it is tall; one line. */
.h23-chat-model-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: transparent;
  color: inherit;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  opacity: 0.82;
  max-width: 200px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.h23-chat-model-pill:hover {
  opacity: 1;
  background: var(--glass-hover, rgba(255,255,255,0.06));
}
.h23-chat-model-pill > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Narrow tile: hide model pill to preserve room for agent + actions. */
@media (max-width: 420px) {
  .h23-chat-model-pill { display: none; }
}

.h23-chat-menu {
  min-width: 220px;
  background: rgba(6, 12, 24, 0.96);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 4px;
  z-index: 1100;
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
}
.h23-chat-menu[hidden] { display: none; }
.h23-chat-list-popover {
  max-height: min(420px, calc(100vh - 16px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.h23-chat-menu-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  color: inherit;
  border: none;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.h23-chat-menu-item:hover {
  background: var(--glass-hover, rgba(255,255,255,0.08));
}

/* Collapse the tile header to the essentials: agent pill on the left,
   expand + ⋯ on the right. */
.h23-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.h23-chat-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* Narrow tile: hide agent name, show avatar only. */
@media (max-width: 360px) {
  .h23-chat-agent-name { display: none; }
}

/* ── Image Attachments ──────────────────────────────────── */

/* Override the original row-flex on the input containers — we now stack
   tray / row / drop-overlay vertically. */
.h23-chat-input-area,
.sh-input-bar {
  flex-direction: column;
  align-items: stretch;
  position: relative;
}

.h23-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.h23-chat-attach-btn {
  background: transparent;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.12));
  color: var(--text-muted, #888);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
  align-self: flex-end;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
  line-height: 1;
}
.h23-chat-attach-btn:hover {
  background: var(--glass-secondary, rgba(255,255,255,0.06));
  color: var(--text-primary, #fff);
}

.h23-chat-attach-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
}
.h23-chat-attach-tray[hidden] { display: none; }

.h23-chat-attach-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.12));
  background: var(--glass-secondary, #1a1a1a);
}
.h23-chat-attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.h23-chat-attach-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 18px;
  cursor: pointer;
  padding: 0;
}

.h23-chat-drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 100, 200, 0.18);
  border: 2px dashed rgba(80, 160, 230, 0.7);
  color: #fff;
  font-weight: 500;
  pointer-events: none;
  z-index: 50;
  border-radius: 8px;
}
.h23-chat-drop-overlay[hidden] { display: none; }

/* User-bubble image rendering */
.h23-chat-msg.user .h23-chat-msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.h23-chat-msg.user .h23-chat-msg-images img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  display: block;
}
