/* The chat history rail (js/history-rail.js): rows, the row menu, renaming, history search and the share dialog.
   Moved out of base.css, shared-components.css and features.css in their
   original cascade order; loaded after features.css and before type.css. */

.chat-history-rail {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.chat-history-rail.is-loading,
.chat-history-rail.is-empty {
  display: none;
}

.chat-history-title {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  padding: 8px 8px 6px;
}

.chat-history-head { position: relative; }

/* The second section's label, inside the list because that is where the row
   it introduces lives. Matches the rail heading above it, with room over it
   to separate the groups. */
/* A chat its owner deleted, listed under "Smazané" for an administrator. */
.chat-history-item.is-deleted .chat-history-name {
  color: var(--muted);
}

.chat-history-group {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  padding: 8px 8px 6px;
  margin-top: 10px;
}

.chat-history-list {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: 0;
  overflow-y: visible;
  padding: 0 0 6px;
  min-height: auto;
}

.chat-history-error {
  font-size: var(--text-xs);
  padding: 8px 10px;
  border-radius: 0;
  background: transparent;
  border: 0;
  line-height: 1.35;
}

.chat-history-item {
  position: relative;
  display: block;
  height: 36px;
  padding: 0;
  border-radius: var(--r-sm);
}

.chat-history-main {
  position: relative;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  min-height: 36px;
  font-weight: 400;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
  transition: background 0.15s, color 0.15s;
}

.chat-history-item.active .chat-history-main {
  white-space: nowrap;
}

.chat-history-name {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 400;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* A title cut mid-letter reads as a rendering fault. Fading the last few
   millimetres says the same thing -- there is more text -- without the
   hard edge. Only titles that actually overflow are masked, so a short one
   keeps its final character at full strength. */
.chat-history-name[data-overflowing="true"] {
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
}

/* No transition at rest: the reveal is animated only while hovered, so
   leaving the row snaps the title back to the start instead of slowly
   sliding back over an already-abandoned row. */
.chat-history-name-track {
  display: inline-block;
  min-width: max-content;
  transform: translateX(0);
  transition: none;
  will-change: transform;
}

.chat-history-item:hover .chat-history-name[data-overflowing="true"]:not(.is-renaming) .chat-history-name-track {
  transform: translateX(var(--chat-history-title-shift, 0));
  transition: transform var(--chat-history-title-duration, 1800ms) linear 240ms;
}

.chat-history-item:hover .chat-history-name,
.chat-history-item.opening .chat-history-name,
.chat-history-item.pending .chat-history-name {
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 72px), transparent calc(100% - 46px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 72px), transparent calc(100% - 46px), transparent 100%);
}

.chat-history-name.is-renaming {
  overflow: hidden;
}

.chat-history-name.is-renaming .chat-history-letter {
  display: inline-block;
  white-space: pre;
  opacity: 0;
  animation: chatHistoryLetterIn 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: var(--letter-delay, 0ms);
}

.chat-history-status {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  flex: 0 0 auto;
  z-index: 1;
}

.pending-dot {
  display: block;
  flex: none;
  width: 12px;
  height: 12px;
}

/* Animate vector geometry directly: scaling a tiny rasterized circle can
   snap between pixel sizes in Firefox. Keep the SVG viewport stationary. */
.pending-dot circle {
  fill: currentColor;
  stroke: none;
  animation: pendingDotBreathe 2.8s ease-in-out infinite;
  animation-delay: var(--pending-delay, 0ms);
}

.chat-history-status.pending { color: var(--text); }

.chat-history-status .pending-dot {
  width: 8px;
  height: 8px;
}

.chat-history-delete {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 0;
  line-height: 1;
  cursor: pointer;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transition: opacity .14s, background .14s, color .14s, transform .14s;
}

.chat-history-item:hover .chat-history-delete,
.chat-history-item.opening .chat-history-delete,
.chat-history-item.is-menu-open .chat-history-delete {
  opacity: 1;
  pointer-events: auto;
}

/* Renaming happens in the row, in place of the row's button -- the field
   takes the same box so the title does not jump as it becomes editable. */
.chat-history-item.is-renaming-row .chat-history-main,
.chat-history-item.is-renaming-row .chat-history-delete { display: none; }

.chat-history-rename {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 36px;
  margin: 0;
  padding: 7px 8px;
  border: 1px solid var(--border-focus);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--text-md);
  line-height: 20px;
  outline: none;
}

/* Three dots rather than a bin: the button opens the row's options now, and
   one of them is destructive. */
.chat-history-delete::before {
  content: "";
  width: 16px;
  height: 16px;
  display: block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='black' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='5' cy='12' r='1.7'/%3E%3Ccircle cx='12' cy='12' r='1.7'/%3E%3Ccircle cx='19' cy='12' r='1.7'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='black' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='5' cy='12' r='1.7'/%3E%3Ccircle cx='12' cy='12' r='1.7'/%3E%3Ccircle cx='19' cy='12' r='1.7'/%3E%3C/svg%3E") center / contain no-repeat;
}

.chat-history-delete:hover {
  color: var(--ink-strong);
  transform: translateY(-50%);
}

.chat-history-item.is-deleting {
  overflow: hidden;
  pointer-events: none;
  will-change: height, opacity, transform;
  animation: chatHistoryDeleteOut 200ms cubic-bezier(.4, 0, .2, 1) forwards;
}

.chat-history-item.is-entering {
  overflow: hidden;
  min-height: 0;
  will-change: height, opacity, transform;
  animation: chatHistoryEnter 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .pending-dot circle {
      animation: none;
    }

  .chat-history-name-track {
      transition: none;
      transform: none !important;
    }

  .chat-history-item.is-deleting {
      animation-duration: 1ms;
      transform: none;
    }
}
/* A link and the one thing anyone does with it. Nothing is filled in here,
   so it drops the rules an upload form needs and reads as the app's own
   floating card: warm ground, one hairline, generous corners. Dismissing is
   a click anywhere off it, so no button competes with the copy. */
/* Narrower than the upload dialog it borrows its shell from. Both classes,
   so the width holds whichever sheet loads first. */
.upload-modal.share-modal { width: 424px; }

.share-modal .upload-modal-header { padding: 20px 22px 2px; border-bottom: 0; }

.share-modal .upload-modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.share-modal .upload-modal-body { padding: 8px 22px 0; }

.share-modal .upload-modal-footer { padding: 16px 22px 20px; border-top: 0; justify-content: flex-end; }

/* The glyph rides with the label rather than sitting in its own box: same
   optical weight as the app's other icons, and the padding closes up so the
   pair reads as one control instead of a wide green slab. */
/* An upload button with its own size; both classes, so that holds whichever
   sheet loads first. */
.upload-btn.share-modal-copy {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px 8px 13px;
  border-radius: var(--r-md);
}

.share-modal-copy svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.share-modal-intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

/* The link is the point of the dialog, so it is selectable and scrolls
   sideways rather than wrapping into something nobody can copy by hand. */
.share-modal-link {
  display: block;
  padding: 11px 13px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.4;
  overflow-x: auto;
  white-space: nowrap;
  user-select: all;
}

/* The cross is drawn, not typed, so it needs the stroke every other dialog
   gives its own -- without it the paths fill to nothing and the button is
   an invisible target. */
.share-modal .upload-modal-close svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

/* ── Chat row menu ─── */
/* The rail's per-chat options. Same light floating language as the notice
   and the tooltips: surface ground, hairline, the app's float shadow. */
.chat-row-menu {
  position: fixed;
  z-index: 130;
  min-width: 180px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-row-menu[hidden] { display: none; }

.chat-row-menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  /* The rail's own type -- 14px at 450 -- so the menu reads as part of it;
     at 13px and regular weight it looked faint beside the rows it acts on. */
  font-size: var(--text-md);
  font-weight: 450;
  line-height: 20px;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background var(--dur);
}

.chat-row-menu-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* A touch quieter than its label, as in the rail. */
  opacity: .85;
}

.chat-row-menu-item.is-destructive .chat-row-menu-icon { opacity: 1; }

.chat-row-menu-item:hover,
.chat-row-menu-item:focus-visible {
  background: var(--hover-bg);
  outline: none;
}

/* Deleting a chat cannot be undone, so it does not read like the two above
   it -- but it stays quiet until pointed at, rather than colouring the menu. */
.chat-row-menu-item.is-destructive { color: var(--red); }

.chat-row-menu-item.is-destructive:hover,
.chat-row-menu-item.is-destructive:focus-visible {
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

.chat-history-rename::selection {
  background: rgba(15, 23, 42, 0.14);
  color: inherit;
}

.chat-history-rail {
  border-top-color: transparent;
}

.chat-history-title,
.chat-history-empty,
.chat-history-loading,
.chat-history-error {
  color: var(--muted);
}

.chat-history-main,
.chat-history-name {
  color: var(--ink);
}

.chat-history-name {
  font-size: var(--text-md);
  font-weight: 450;
}

.chat-history-main:hover {
  background: var(--rail-hover-bg);
  color: var(--ink);
}

.chat-history-item:hover .chat-history-main {
  background: var(--rail-hover-bg);
  color: var(--ink);
}

.chat-history-item.active .chat-history-main {
  background: var(--rail-active-bg);
  color: var(--ink);
  box-shadow: none;
}

.chat-history-item.active .chat-history-name {
  font-weight: 500;
}

.chat-history-item.pending:hover .chat-history-status {
  opacity: 0;
  pointer-events: none;
}

.chat-history-status {
  color: var(--muted);
}

/* ── History search ──────────────────────────────────────────────
   Chats and výzkumné zprávy only. A palette rather than a field in the
   rail: the rail is narrow, the results want the whole title on one line,
   and searching is a thing you do rather than a place you go. */
.history-search-btn {
  flex: 0 0 auto;
  /* Pushed to the far edge of the rail, away from the wordmark: it is a
     tool, not part of the brand lockup. */
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

.history-search-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.history-search-btn:hover,
.history-search-btn:focus-visible {
  background: var(--hover-bg);
  color: var(--ink);
}

.history-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 20px 20px;
  background: rgb(var(--muted-rgb) / .22);
}

.history-search-overlay[hidden] { display: none; }

.history-search-panel {
  width: min(620px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
}

.history-search-field {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.history-search-icon {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.7;
  stroke-linecap: round;
}

#history-search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-base);
}

#history-search-input::placeholder { color: var(--faint); }

.history-search-close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}

.history-search-close svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.history-search-close:hover { background: var(--hover-bg); color: var(--ink); }

.history-search-results {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
}

.history-search-result {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 0;
  border-radius: var(--r-md);
  padding: 9px 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.history-search-result-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  color: var(--faint);
}

.history-search-result-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-search-result-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-search-result-when {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: var(--text-xs);
}

/* Hover and keyboard selection are the same state: the arrow keys move the
   same highlight the pointer does, so there is only ever one place to look. */
.history-search-result:hover,
.history-search-result.is-active {
  background: var(--hover-bg);
  color: var(--ink);
}

.history-search-empty {
  padding: 22px 12px;
  color: var(--faint);
  font-size: var(--text-sm);
  text-align: center;
}

@media (max-width: 560px) {
  .history-search-overlay { padding: 8vh 12px 12px; }

  .history-search-panel { max-height: 80vh; }
}
