/* ── Chat History Drawer — Calm Canon ──
   Right-side drawer for "Tidligere samtaler".
   Warm palette + sage for active/focus only.
   Does NOT reuse the legacy sidebar styles. */

/* ── Trigger ── */
.chd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0 14px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #7A6C5F;
  font: 500 12.5px/1 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  align-self: flex-start;
}
.chd-trigger:hover {
  background: rgba(58,47,38,0.04);
  border-color: rgba(58,47,38,0.06);
  color: #5C4D43;
}
.chd-trigger[aria-expanded="true"] {
  background: rgba(110,138,126,0.10);
  border-color: rgba(110,138,126,0.22);
  color: #4A7A68;
}
.chd-trigger:focus-visible {
  outline: none;
  border-color: rgba(110,138,126,0.45);
  box-shadow: 0 0 0 3px rgba(110,138,126,0.18);
}
.chd-trigger:focus:not(:focus-visible) {
  outline: none;
}
.chd-trigger-icon {
  flex-shrink: 0;
}
.chd-trigger-label {
  white-space: nowrap;
}

/* ── Scrim ── */
.chd-scrim {
  position: fixed;
  inset: 0;
  background: rgba(58,47,38,0.22);
  z-index: 8999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.chd-scrim--visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Drawer ── */
.chd-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  z-index: 9000;
  background: #FBF8F2;
  border-left: 1px solid rgba(92,77,67,0.10);
  box-shadow: -3px 0 16px rgba(58,47,38,0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  pointer-events: none;
}
.chd-drawer--open {
  transform: translateX(0);
  pointer-events: auto;
}

/* ── Header ── */
.chd-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 0;
  flex-shrink: 0;
}
.chd-header-text {
  flex: 1;
  min-width: 0;
}
.chd-title {
  font-size: var(--font-size-lg, 17px);
  font-weight: var(--font-weight-semibold, 600);
  color: #3A2F26;
  margin: 0;
  line-height: 1.3;
}
.chd-subtitle {
  font-size: var(--font-size-sm, 13px);
  color: #7A6C5F;
  margin: 2px 0 0;
  line-height: 1.4;
}

/* ── Close ── */
.chd-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #7A6C5F;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: -2px;
  transition: background 0.15s, border-color 0.15s;
}
.chd-close:hover {
  background: rgba(154,142,130,0.09);
}
.chd-close:focus-visible {
  outline: 3px solid rgba(110,138,126,0.45);
  outline-offset: 1px;
  border-color: #6E8A7E;
}

/* ── Search ── */
.chd-search-wrap {
  position: relative;
  margin: 14px 20px 8px;
  flex-shrink: 0;
}
.chd-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #7A6C5F;
  pointer-events: none;
}
.chd-search {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  border: 1px solid rgba(92,77,67,0.18);
  border-radius: 14px;
  background: #FFFEFB;
  color: #3A2F26;
  font-size: var(--font-size-base, 14px);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.chd-search:focus {
  border-color: rgba(110,138,126,0.65);
}
.chd-search::placeholder {
  color: #7A6C5F;
}
.chd-search::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ── List ── */
.chd-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(154,142,130,0.25) transparent;
}
.chd-list::-webkit-scrollbar { width: 5px; }
.chd-list::-webkit-scrollbar-track { background: transparent; }
.chd-list::-webkit-scrollbar-thumb {
  background: rgba(154,142,130,0.30);
  border-radius: 3px;
}

/* ── Group labels ── */
.chd-group-label {
  padding: 14px 8px 4px;
  font-size: var(--font-size-xs, 11px);
  font-weight: var(--font-weight-semibold, 600);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #7A6C5F;
}

/* ── Items ── */
.chd-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  margin: 2px 0;
  transition: background 0.15s, border-color 0.15s;
}
.chd-item:hover {
  background: rgba(154,142,130,0.07);
  border-color: rgba(92,77,67,0.08);
}
.chd-item:focus-visible {
  outline: 2px solid rgba(110,138,126,0.45);
  outline-offset: -2px;
  border-color: #6E8A7E;
}
.chd-item:focus:not(:focus-visible) {
  outline: none;
}

/* ── Active row: current conversation ── */
.chd-item--active {
  background: rgba(110,138,126,0.10);
  border-color: rgba(110,138,126,0.30);
}
.chd-item--active .chd-item-title {
  color: #4A7A68;
  font-weight: var(--font-weight-chd-active, 650);
}

/* ── Keyboard-focused via activedescendant ── */
.chd-item--focused {
  outline: 3px solid rgba(110,138,126,0.45);
  outline-offset: -1px;
  border-color: #6E8A7E;
}

/* ── Visually hidden (screen-reader only) ── */
.chd-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  clip: rect(0, 0, 0, 0) !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  border: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
}

/* ── Pinned row refinements ── */
.chd-item--pinned {
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
}
.chd-item--pinned .chd-item-content {
  /* min-width:0 lets flex children truncate instead of overflowing */
  min-width: 0;
}
.chd-item--pinned .chd-item-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: unset;
  -webkit-box-orient: unset;
  font-size: var(--font-size-base, 14px);
  font-weight: var(--font-weight-medium, 500);
  color: #3A2F26;
}
.chd-item--pinned.chd-item--active .chd-item-title {
  color: #4A7A68;
  font-weight: var(--font-weight-chd-active, 650);
}
.chd-item--pinned .chd-item-meta {
  font-size: var(--font-size-xs, 12px);
  color: #7A6C5F;
}
.chd-item--pinned .chd-item-actions {
  opacity: 0;
}
.chd-item--pinned:hover .chd-item-actions,
.chd-item--pinned:focus-within .chd-item-actions,
.chd-item--pinned.chd-item--focused .chd-item-actions {
  opacity: 1;
}
@media (hover: none) {
  .chd-item--pinned .chd-item-actions {
    opacity: 1;
  }
}

/* ── Pin indicator (inline marker) ── */
.chd-pin-indicator {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: #2f7d6b;
  pointer-events: none;
}
.chd-pin-indicator svg {
  width: 14px;
  height: 14px;
}

/* ── Content lane ── */
.chd-item-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Item title: two-line clamp ── */
.chd-item-title {
  font-size: var(--font-size-base, 14px);
  font-weight: var(--font-weight-medium, 500);
  color: #3A2F26;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* ── Search match mark: sage pill, anchor text ── */
.chd-mark {
  background: rgba(110,138,126,0.15);
  color: inherit;
  border-radius: 3px;
  padding: 1px 2px;
  margin: 0 -1px;
}

/* ── Item meta ── */
.chd-item-meta {
  font-size: var(--font-size-xs, 12px);
  color: #7A6C5F;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

/* ── Row actions ── */
.chd-item-actions {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}
.chd-item:hover .chd-item-actions,
.chd-item:focus-within .chd-item-actions,
.chd-item--focused .chd-item-actions {
  opacity: 1;
}
.chd-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44x44 a11y/touch hit target. The negative margin pulls the visual
     footprint back to the original 28x28 slot so the larger target never
     grows row height or shifts the resting title/meta rhythm; the icon
     stays 14x14 and centered, only the interactive/hover area grows. */
  width: 44px;
  height: 44px;
  margin: -8px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #7A6C5F;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.chd-action-btn svg {
  width: 14px;
  height: 14px;
}
.chd-action-btn:hover {
  background: rgba(92,77,67,0.08);
  color: #5C4D43;
}
.chd-action-btn:focus-visible {
  outline: 2px solid rgba(110,138,126,0.45);
  outline-offset: 1px;
}
.chd-pin-btn:hover {
  background: rgba(110,138,126,0.12);
  color: rgb(74,122,104);
}
.chd-pin-btn[aria-pressed="true"] {
  color: #4A7A68;
}
.chd-trash-btn:hover {
  background: rgba(176,96,80,0.12);
  color: rgb(168,88,72);
}
.chd-item--confirming {
  background: rgba(166,89,75,0.04);
  border-color: rgba(166,89,75,0.12);
}
.chd-item--confirming .chd-item-actions {
  opacity: 1;
}
.chd-confirm-pill {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: rgba(166,89,75,0.06);
}
.chd-confirm-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.chd-confirm-yes {
  color: #A6594B;
}
.chd-confirm-yes:hover {
  background: rgba(166,89,75,0.12);
  color: #8B4438;
}
.chd-confirm-yes:focus-visible {
  outline: 3px solid rgba(166,89,75,0.35);
  outline-offset: -1px;
}
.chd-confirm-no {
  color: #7A6C5F;
}
.chd-confirm-no:hover {
  background: rgba(92,77,67,0.08);
  color: #5C4D43;
}
.chd-confirm-no:focus-visible {
  outline: 3px solid rgba(110,138,126,0.35);
  outline-offset: -1px;
}
.chd-item[data-calm-removing="1"] {
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* ── Empty state ── */
.chd-empty {
  padding: 48px 24px;
  text-align: center;
}
.chd-empty-title {
  font-size: var(--font-size-base, 15px);
  font-weight: var(--font-weight-medium, 500);
  color: #5C4D43;
  margin: 0 0 6px;
}
.chd-empty-sub {
  font-size: var(--font-size-sm, 13px);
  color: #7A6C5F;
  margin: 0;
  line-height: 1.5;
}

/* ── Loading skeleton ── */
.chd-loading {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chd-loading-bar {
  height: 14px;
  width: 75%;
  border-radius: 7px;
  background: rgba(154,142,130,0.18);
  animation: chd-pulse 1.2s ease-in-out infinite;
}
.chd-loading-bar--short {
  width: 50%;
}
@keyframes chd-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .chd-drawer,
  .chd-scrim,
  .chd-trigger,
  .chd-item,
  .chd-item-actions,
  .chd-action-btn,
  .chd-confirm-btn,
  .chd-close,
  .chd-search {
    transition: none;
  }
  .chd-item[data-calm-removing="1"] {
    transform: none;
    transition: none;
  }
  .chd-loading-bar {
    animation: none;
    opacity: 0.7;
  }
}

/* ── Dark mode ── */
[data-theme="dark"] .chd-drawer {
  background: #1e1c1a;
  border-left-color: rgba(255,255,255,0.06);
  box-shadow: -3px 0 16px rgba(0,0,0,0.30);
}
[data-theme="dark"] .chd-scrim {
  background: rgba(0, 0, 0, 0.45);
}
[data-theme="dark"] .chd-title {
  color: #f0ece6;
}
[data-theme="dark"] .chd-subtitle,
[data-theme="dark"] .chd-group-label,
[data-theme="dark"] .chd-item-meta,
[data-theme="dark"] .chd-close,
[data-theme="dark"] .chd-trigger {
  color: #8a857d;
}
[data-theme="dark"] .chd-search {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.10);
  color: #f0ece6;
}
[data-theme="dark"] .chd-search::placeholder {
  color: #8a857d;
}
[data-theme="dark"] .chd-item-title {
  color: #f0ece6;
}
[data-theme="dark"] .chd-item:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.06);
}
[data-theme="dark"] .chd-action-btn:hover {
  background: rgba(255,255,255,0.07);
}
[data-theme="dark"] .chd-pin-btn:hover {
  background: rgba(110,138,126,0.20);
  color: #7eb3a0;
}
[data-theme="dark"] .chd-trash-btn:hover {
  background: rgba(176,96,80,0.20);
  color: #d99e90;
}
[data-theme="dark"] .chd-item--confirming {
  background: rgba(166,89,75,0.08);
  border-color: rgba(166,89,75,0.18);
}
[data-theme="dark"] .chd-confirm-pill {
  background: rgba(166,89,75,0.10);
}
[data-theme="dark"] .chd-close:hover,
[data-theme="dark"] .chd-trigger:hover {
  background: rgba(255,255,255,0.07);
}
[data-theme="dark"] .chd-item--active {
  background: rgba(110,138,126,0.12);
  border-color: rgba(110,138,126,0.25);
}
[data-theme="dark"] .chd-item--active .chd-item-title {
  color: #7eb3a0;
}
[data-theme="dark"] .chd-mark {
  background: rgba(110,138,126,0.20);
}
[data-theme="dark"] .chd-empty-title {
  color: #c5bfb5;
}
[data-theme="dark"] .chd-loading-bar {
  background: rgba(255,255,255,0.08);
}
[data-theme="dark"] .chd-item--pinned .chd-item-title {
  color: #f0ece6;
}
[data-theme="dark"] .chd-item--pinned.chd-item--active .chd-item-title {
  color: #7eb3a0;
}
[data-theme="dark"] .chd-pin-indicator {
  color: #7eb3a0;
}

/* ── Mobile (< 768px) ── */
@media (max-width: 767px) {
  .chd-drawer {
    width: 100vw;
  }
  .chd-trigger {
    font-size: var(--font-size-chd-trigger-mobile, 11.5px);
    padding: 5px 8px;
  }
}

/* ── Tablet (768-1024) ── */
@media (min-width: 768px) and (max-width: 1024px) {
  .chd-drawer {
    width: min(360px, 85vw);
  }
}
