/* Shared modal shell and utilities */

.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0); z-index: 275; display: none;
  align-items: center; justify-content: center; cursor: pointer;
  transition: background 0.25s ease; overflow: hidden;
  padding: 32px;
}
.modal-overlay.show {
  display: flex;
  background: rgba(0,0,0,0.68);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal {
  position: relative; cursor: default;
  background: var(--bg-secondary); border-radius: var(--radius);
  border: 1px solid var(--border); width: 90%; max-width: 700px;
  max-height: 85vh; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 32px;
  transform: scale(0.96) translateY(8px); opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.modal-overlay.show .modal { transform: scale(1) translateY(0); opacity: 1; }
.gb-form-modal,
.gb-history-modal,
.marker-detail-modal {
  padding: 0;
  width: min(94vw, 880px);
  max-height: 90vh;
  background: var(--bg-secondary);
  box-shadow: var(--shadow-lg);
}
.gb-form-modal { max-width: 680px; }
.gb-history-modal { max-width: 840px; }
.gb-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-secondary) 92%, var(--bg-card));
}
.gb-modal-kicker {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.gb-modal-title {
  margin-top: 3px;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}
.gb-modal-head .modal-close {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.gb-modal-head .modal-close:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--bg-hover);
}
.context-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.gb-modal-head > .context-back-btn + div {
  margin-right: auto;
}
.context-back-btn svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.context-back-btn:hover,
.context-back-btn:focus-visible {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--bg-hover);
}
.gb-form-body {
  padding: 24px 26px 26px;
}
.gb-form-modal .modal-unit,
.gb-history-modal .modal-unit {
  margin-bottom: 18px;
  color: var(--text-secondary);
}
.gb-form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) > h3:first-of-type,
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) > .modal-header:first-child {
  margin: -32px -32px 20px;
  padding: 22px 56px 18px 26px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-secondary) 92%, var(--bg-card));
}
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) > h3:first-of-type {
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) > .modal-header:first-child h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 22px;
}
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) > .modal-unit:first-of-type {
  margin-top: -6px;
}
.modal:not(.marker-detail-modal):not(.gb-form-modal):not(.gb-history-modal):not(.settings-modal) .modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
@media (max-width: 720px) {
  .modal-overlay { padding: 12px; }
  .gb-modal-head { padding: 18px 20px; }
  .gb-form-body { padding: 20px; }
  .gb-form-actions {
    justify-content: stretch;
  }
  .gb-form-actions .import-btn {
    flex: 1 1 100%;
  }
}

/* Knowledge Base modal - wider than the default 700px to fit the
   per-backend controls (model picker, library list, document list,
   ingest UI) without horizontal cramping. */
.kb-modal { max-width: 760px; }

.report-builder-modal {
  display: flex;
  flex-direction: column;
  width: min(94vw, 840px);
  max-width: 840px !important;
  max-height: min(92vh, 860px);
  overflow: hidden;
  padding: 0;
}
.report-builder-modal .gb-modal-head {
  flex: 0 0 auto;
}
.report-builder-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}
.report-builder-scroll {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}
.report-builder-actions {
  flex: 0 0 auto;
  margin-top: 0;
}
.report-builder-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-card) 72%, transparent);
}
.report-builder-two-col {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.2fr);
  align-items: start;
}
.report-builder-label {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.report-builder-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.report-builder-select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}
.report-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.report-preset-btn,
.report-mini-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.report-preset-btn {
  display: flex;
  min-height: 64px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px;
  text-align: left;
}
.report-preset-btn:hover,
.report-mini-btn:hover,
.report-preset-btn.active {
  border-color: var(--accent);
  background: var(--accent-fill);
}
.report-preset-title {
  font-size: 13px;
  font-weight: 700;
}
.report-preset-meta,
.report-category-meta {
  color: var(--text-muted);
  font-size: 11px;
}
.report-builder-help {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 3px;
}
.report-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.report-builder-check,
.report-category-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
}
.report-builder-check input,
.report-category-row input {
  flex: 0 0 auto;
}
.report-builder-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.report-category-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.report-mini-btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}
.report-category-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: min(32vh, 280px);
  overflow: auto;
  padding-right: 2px;
}
.report-category-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.report-category-title {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.report-builder-empty {
  color: var(--text-muted);
  font-size: 13px;
}
.report-ai-builder {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: 12px;
}
.report-ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.report-ai-status {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 10px;
}
.report-ai-summary-text {
  width: 100%;
  height: min(28vh, 220px);
  min-height: 96px;
  max-height: 320px;
  margin-top: 10px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  overflow-y: auto;
  overscroll-behavior: contain;
  resize: vertical;
  -webkit-overflow-scrolling: touch;
}
.report-builder-preview-btn {
  min-width: 132px;
  color: #07111f;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 24%, transparent);
}
.report-builder-preview-btn:hover {
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}
@media (max-width: 720px) {
  .report-builder-modal {
    width: min(96vw, 560px);
    max-height: calc(100dvh - 24px);
  }
  .report-builder-two-col,
  .report-preset-grid,
  .report-section-grid,
  .report-category-list {
    grid-template-columns: 1fr;
  }
  .report-category-list {
    max-height: min(36vh, 320px);
  }
  .report-builder-row-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .report-category-actions,
  .report-ai-actions {
    justify-content: flex-start;
  }
}

.modal-nudge { animation: modal-nudge 0.3s ease; }
@keyframes modal-nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.015); box-shadow: 0 0 0 2px var(--accent); } }

.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; color: var(--text-muted);
  font-size: 24px; cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }
.modal h3 { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin-bottom: 4px; }

/* Reserve room for the absolutely-positioned close button so long titles
   (e.g. "Log session - Mitochondriak Maxi UVB") don't run under it
   when they wrap on narrow viewports. */
.modal-header { position: relative; padding-right: 40px; }
.modal-header h3 { margin-bottom: 4px; }

.changelog-modal.gb-history-modal {
  max-width: 680px;
}

/* Feedback modal */
.feedback-redesign-modal {
  width: min(94vw, 560px);
  max-width: 560px !important;
}
.feedback-form-body {
  background: transparent;
}
.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.feedback-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}
.feedback-label {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.feedback-select,
.feedback-input,
.feedback-textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.feedback-select {
  color-scheme: dark;
}
[data-theme="light"] .feedback-select {
  color-scheme: light;
}
.feedback-textarea {
  min-height: 160px;
  max-height: min(34vh, 260px);
  resize: vertical;
  line-height: 1.5;
}
.feedback-select:focus,
.feedback-input:focus,
.feedback-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-fill);
  outline: none;
}
.feedback-input::placeholder,
.feedback-textarea::placeholder {
  color: var(--text-muted);
}
.feedback-notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-card) 76%, transparent);
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.5;
}
.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.feedback-action-btn {
  min-height: 38px;
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  transition: all 0.15s;
}
.feedback-action-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent, #07111f);
}
.feedback-action-primary:hover {
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}
.feedback-action-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
}
.feedback-action-secondary:hover {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--text-primary);
}
@media (max-width: 720px) {
  .feedback-redesign-modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .feedback-textarea {
    min-height: 180px;
    max-height: 34vh;
  }
  .feedback-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .feedback-action-btn {
    width: 100%;
    min-height: 42px;
  }
}

.gb-form-modal .manual-entry-form { margin-top: 18px; }
.gb-form-modal .manual-entry-form .me-field {
  margin-bottom: 14px;
}
.gb-form-modal .manual-entry-form .me-field label {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.gb-form-modal .manual-entry-form .me-field input,
.gb-form-modal .manual-entry-form .me-field textarea,
.gb-form-modal .manual-entry-form .me-field select,
.gb-form-modal .api-key-input,
.gb-form-modal .ctx-note-input,
.gb-form-modal .ctx-notes-textarea {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  min-height: 40px;
}
.gb-form-modal .manual-entry-form .me-field input:focus,
.gb-form-modal .manual-entry-form .me-field textarea:focus,
.gb-form-modal .manual-entry-form .me-field select:focus,
.gb-form-modal .api-key-input:focus,
.gb-form-modal .ctx-note-input:focus,
.gb-form-modal .ctx-notes-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-fill);
}
.gb-form-modal .cm-cat-row,
.gb-form-modal .me-field > div {
  min-width: 0;
}

#profile-share-overlay.modal-overlay {
  z-index: 650;
}
.profile-share-modal {
  max-width: 640px;
}
.profile-share-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.profile-share-intro {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}
.profile-share-intro-title {
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.35;
}
.profile-share-intro-copy {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}
.profile-share-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.profile-share-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.profile-share-field .api-key-input {
  width: 100%;
  padding: 9px 11px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}
.profile-share-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.profile-share-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.profile-share-icon-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  color: var(--text-primary);
}
.profile-share-icon-btn:disabled {
  cursor: progress;
  opacity: 0.65;
}
.profile-share-result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.profile-share-consent {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--yellow) 35%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--yellow) 7%, var(--bg-card));
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}
.profile-share-consent input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}
.profile-share-active {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-secondary) 72%, transparent);
}
.profile-share-active-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 750;
}
.profile-share-active-head small {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}
.profile-share-active-list {
  display: flex;
  max-height: 176px;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.profile-share-active-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}
.profile-share-active-main {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.profile-share-active-title {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
}
.profile-share-active-meta,
.profile-share-active-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}
.profile-share-active-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.profile-share-stop-btn {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--red) 40%, var(--border));
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--red);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.profile-share-stop-btn:hover {
  background: color-mix(in srgb, var(--red) 10%, transparent);
}
.profile-share-stop-btn:disabled {
  cursor: progress;
  opacity: 0.7;
}
.profile-share-note {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-card) 72%, transparent);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}
.profile-share-status {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}
.profile-share-status[data-status="error"] {
  border-color: color-mix(in srgb, var(--red) 45%, var(--border));
  color: var(--red);
}
@media (max-width: 640px) {
  .profile-share-input-row {
    grid-template-columns: minmax(0, 1fr) 38px;
  }
  .profile-share-active-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .profile-share-active-actions {
    justify-content: flex-end;
  }
}

/* Styled Confirmation Dialog */
.confirm-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7); z-index: 1200; display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.confirm-overlay.show { display: flex; }
.confirm-dialog {
  background: var(--bg-secondary); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 24px 26px;
  max-width: 460px; width: min(100%, 460px); box-shadow: var(--shadow-lg);
}
.confirm-message {
  font-size: 15px; line-height: 1.6; color: var(--text-primary); margin-bottom: 24px;
}
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
.confirm-btn {
  padding: 8px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.15s;
}
.confirm-btn-cancel {
  background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border);
}
.confirm-btn-cancel:hover { background: var(--bg-hover); color: var(--text-primary); }
.confirm-btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.confirm-btn-danger:hover { opacity: 0.9; transform: translateY(-1px); }

/* Changelog */
.changelog-entry { margin-bottom: 20px; }
.changelog-entry + .changelog-entry { padding-top: 20px; border-top: 1px solid var(--border); }
.changelog-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.changelog-version {
  display: inline-block; background: var(--accent-gradient); color: #fff;
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  padding: 4px 12px; border-radius: 20px;
}
.changelog-date { font-size: 13px; color: var(--text-muted); }
.changelog-items { list-style: none; margin: 0; padding: 0 0 0 4px; }
.changelog-item {
  position: relative; padding: 3px 0 3px 16px;
  font-size: 14px; color: var(--text-secondary); line-height: 1.5;
}
.changelog-item::before { content: '\2013'; position: absolute; left: 0; color: var(--accent); font-weight: 600; }
.changelog-item a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.changelog-item a:hover { text-decoration-thickness: 2px; }

.modal .modal-unit {
  color: var(--text-muted); font-size: 14px; margin-bottom: 8px;
  /* Source-name + delta + trend separated by middle-dots; let them wrap
     gracefully on narrow viewports rather than overflow the modal box. */
  display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center;
}
.modal .modal-unit.modal-unit-alt {
  font-size: 12px; opacity: 0.7; margin-top: -4px; margin-bottom: 12px;
}
.modal .wearable-modal-source-swap {
  margin-left: auto;
  font-size: 11px;
}

.ref-editable { cursor: pointer; border-bottom: 1px dashed var(--text-muted); padding-bottom: 1px; }
.ref-editable:hover { color: var(--accent); border-color: var(--accent); }
.ref-edit-field { display: inline-flex; align-items: center; position: relative; }
.ref-edit-input { width: 60px; padding: 2px 20px 2px 6px; font-size: 13px; font-family: var(--font-mono); background: var(--bg-primary); color: var(--text-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.ref-edit-input:focus { border-color: var(--accent); outline: none; }
.ref-edit-clear { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 0 3px; line-height: 1; opacity: 0.5; }
.ref-edit-clear:hover { opacity: 1; color: var(--red); }
.ref-edit-save { padding: 2px 8px; font-size: 12px; background: var(--accent-gradient); color: white; border: none; border-radius: var(--radius-sm); cursor: pointer; margin-left: 4px; }
.ref-edited-badge { font-size: 10px; color: var(--yellow); cursor: pointer; margin-left: 4px; opacity: 0.8; }
.ref-edited-badge:hover { opacity: 1; text-decoration: underline; }

.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border); border-radius: 20px; transition: background 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; bottom: 3px; background: var(--text-secondary); border-radius: 50%; transition: transform 0.2s, background 0.2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid color-mix(in srgb, var(--accent) 82%, transparent);
  outline-offset: 3px;
}
.toggle-switch input:disabled + .toggle-slider {
  cursor: not-allowed;
}

.emoji-picker { position: fixed; z-index: 10001; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 320px; max-height: 400px; display: flex; flex-direction: column; }
.emoji-picker-search { padding: 8px; border-bottom: 1px solid var(--border); }
.emoji-picker-search input { width: 100%; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-primary); font-size: 14px; outline: none; box-sizing: border-box; }
.emoji-picker-search input:focus { border-color: var(--accent); }
.emoji-picker-cats { display: flex; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.emoji-picker-cats button { background: none; border: none; font-size: 16px; padding: 4px 6px; cursor: pointer; border-radius: 4px; opacity: 0.6; }
.emoji-picker-cats button.active, .emoji-picker-cats button:hover { opacity: 1; background: var(--bg-secondary); }
.emoji-picker-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px; overflow-y: auto; flex: 1; }
.emoji-picker-grid span { font-size: 22px; text-align: center; cursor: pointer; padding: 4px; border-radius: 4px; line-height: 1.2; }
.emoji-picker-grid span:hover { background: var(--bg-secondary); }
.emoji-picker-label { grid-column: 1 / -1; font-size: 11px; color: var(--text-secondary); padding: 6px 2px 2px; text-transform: uppercase; letter-spacing: 0.5px; }

@media (max-width: 640px) {
  .modal-overlay { padding: 8px; }
}
@media (max-width: 480px) {
  .confirm-dialog { padding: 22px 18px; }
}
@media (pointer: coarse) {
  .modal-close,
  .context-back-btn { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
}
