/* chat-history.css — saved-conversation panel for the shared SB_CHAT bots.
   Ported from the Sofia frontpage panel, restyled with this site's palette:
   teal #629d9b accent, grey scale from sidebar.css, white surfaces.
   Only loaded on pages that enable SB_CHAT history. */

/* The site has no global border-box reset, and these rows mix width:100% with
   padding — without this the row measures wider than the panel and the delete
   button lands outside it. Scoped so nothing else on the page is affected. */
.sb-chat-history-bar,
.sb-chat-history-bar *,
.sb-hist-panel,
.sb-hist-panel * {
  box-sizing: border-box;
}

/* ---------- trigger button (above the chat, outside .mwai-window-box) ------ */

/* The bar lives in the gap between the page header and the white chat frame,
   with the button pushed to the right edge. */
.sb-chat-history-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 0 0 14px;
  padding: 0;
}

/* Labelled pill — clock-arrow icon plus the "Chat historik" text. Mockup
   geometry on this site's palette (teal #629d9b), so the trigger and the panel
   it opens read as one family. */
.sb-chat-history-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 9px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #ffffff;
  color: #4b5563;
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.sb-chat-history-btn:hover {
  border-color: #629d9b;
  color: #3f6b69;
  box-shadow: 0 2px 8px rgba(31, 45, 51, 0.08);
}

.sb-chat-history-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}

/* ---------- backdrop + panel shell ---------- */

.sb-hist-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1099;
  background: rgba(17, 24, 39, 0.16);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.sb-hist-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sb-hist-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1100;
  width: min(420px, 100vw - 32px);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -16px 0 48px rgba(17, 24, 39, 0.12);
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
  font-family: inherit;
}

.sb-hist-panel.is-open {
  transform: translateX(0);
}

/* ---------- header ---------- */

.sb-hist-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 26px 22px 0;
  flex-shrink: 0;
}

.sb-hist-header h2 {
  margin: 0;
  color: #111827;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
}

.sb-hist-header p {
  margin: 4px 0 0;
  color: #9ca3af;
  font-size: 13px;
  line-height: 1.4;
}

.sb-hist-close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.sb-hist-close:hover {
  background: #f3f4f6;
  color: #111827;
}

.sb-hist-close svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* ---------- search ---------- */

.sb-hist-search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 22px 0;
  padding: 0 14px;
  height: 44px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  flex-shrink: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sb-hist-search:focus-within {
  border-color: #629d9b;
  box-shadow: 0 0 0 3px rgba(98, 157, 155, 0.15);
}

.sb-hist-search svg {
  width: 18px;
  height: 18px;
  stroke: #9ca3af;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}

.sb-hist-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #111827;
  font-size: 14px;
  font-family: inherit;
}

.sb-hist-search input::placeholder {
  color: #9ca3af;
}

/* ---------- list ---------- */

.sb-hist-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 24px;
}

.sb-hist-group {
  padding: 16px 22px 6px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sb-hist-empty,
.sb-hist-loading {
  padding: 28px 22px;
  color: #9ca3af;
  font-size: 14px;
  text-align: center;
}

.sb-hist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 22px;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.sb-hist-item:hover {
  background: #f4faf9;
}

.sb-hist-item.is-active {
  background: #eef6f5;
  box-shadow: inset 3px 0 0 #629d9b;
}

.sb-hist-item-text {
  flex: 1;
  min-width: 0;
}

.sb-hist-item-title {
  display: block;
  color: #111827;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-hist-item-date {
  display: block;
  margin-top: 2px;
  color: #9ca3af;
  font-size: 12px;
}

.sb-hist-item-actions {
  display: none;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.sb-hist-item:hover .sb-hist-item-actions,
.sb-hist-item.is-editing .sb-hist-item-actions {
  display: flex;
}

.sb-hist-item-edit,
.sb-hist-item-delete {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.sb-hist-item-edit:hover {
  color: #629d9b;
  background: rgba(98, 157, 155, 0.12);
}

.sb-hist-item-delete:hover {
  color: #dc2626;
  background: #fee2e2;
}

.sb-hist-item-edit svg,
.sb-hist-item-delete svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Inline rename input — replaces the title span while editing and keeps the
   same typography so the row does not reflow. */
.sb-hist-item-input {
  display: block;
  width: 100%;
  margin: -4px 0;
  padding: 4px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sb-hist-item-input:focus {
  border-color: #629d9b;
  box-shadow: 0 0 0 3px rgba(98, 157, 155, 0.18);
}

.sb-hist-item-input:disabled {
  opacity: 0.6;
  cursor: progress;
}

@media (max-width: 767px) {
  .sb-hist-panel {
    width: 100vw;
  }
}

/* Narrow screens: collapse back to the icon-only square. The label is also in
   aria-label/title, so the accessible name survives the span being hidden. */
@media (max-width: 720px) {
  .sb-chat-history-btn span {
    display: none;
  }

  .sb-chat-history-btn {
    gap: 0;
    padding: 9px 11px;
  }
}
