/* Phase 5 — appointment history modal.
 *
 * Surfaces the per-appointment timeline as a stacked dialog above the
 * existing details modal. One stylesheet drives both the dashboard
 * (.agenda-detail-overlay) and schedule (.event-modal-card) surfaces;
 * there are no per-surface selectors here, per the design spec's
 * "principle 1 — unified interface" rule.
 *
 * Design source of truth: docs/specs/appointment-history-ui.md.
 */

/* Restore the meaning of the HTML ``hidden`` attribute for every element
 * this stylesheet sets a ``display:`` value on. Without these the JS that
 * toggles ``node.hidden = true`` is silently dead — my rules above (and
 * the global ``.btn-v2 { display: inline-flex }``) outrank the UA
 * stylesheet's ``[hidden] { display: none }`` and the element stays
 * visible. This was the root cause of "Could not load history" appearing
 * unconditionally when the History modal opened. */
.appointment-history-trigger[hidden],
.appointment-history-empty[hidden],
.appointment-history-error[hidden],
.appointment-history-error [hidden],
/* Org-wide page: the Load more button is `.btn-v2` which sets
 * display: inline-flex and would otherwise override [hidden]. */
.org-history-load-more button[hidden],
.org-history-list[hidden] {
  display: none !important;
}

.appointment-history-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  margin-inline-start: auto;
  margin-inline-end: 8px;
  border: 0;
  background: transparent;
  font: 600 13px/1 inherit;
  color: var(--midnight, #1b3559);
  text-decoration: none;
  border-radius: var(--radius-sm, 2px);
  cursor: pointer;
}
.appointment-history-trigger:hover {
  color: var(--brass, #b8893a);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.appointment-history-trigger:focus-visible {
  outline: 2px solid var(--brass, #b8893a);
  outline-offset: 2px;
  text-decoration: underline;
}
.appointment-history-trigger__chevron {
  font-size: 14px;
  line-height: 1;
  transform: translateY(-1px);
}
@media (max-width: 360px) {
  .appointment-history-trigger {
    padding: 8px 10px;
  }
}

.appointment-history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 5100;
  overscroll-behavior: contain;
}
.appointment-history-overlay.is-open { display: flex; }
.appointment-history-overlay[hidden] { display: none !important; }

.appointment-history-card {
  position: relative;
  background: var(--bone, #fff);
  border: 1px solid var(--line, var(--border, #d4d8df));
  border-radius: var(--radius-md, 4px);
  width: min(720px, 100%);
  max-height: min(80vh, calc(100% - 48px));
  display: flex;
  flex-direction: column;
  box-shadow: 0 28px 48px rgba(15, 23, 42, 0.22);
  animation: agendaDetailIn 160ms ease;
}

.appointment-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px 20px;
  gap: 12px;
  border-bottom: 1px solid var(--line-2, var(--border, #d4d8df));
}
.appointment-history-header h3 {
  margin: 0;
  font: 600 18px/1.2 "Source Serif 4", Georgia, serif;
  color: var(--ink, var(--primary-700, #15161a));
}

.appointment-history-status {
  padding: 6px 20px 0 20px;
  color: var(--muted, #5b6470);
  font-size: 13px;
  min-height: 1.2em;
}
.appointment-history-status:empty { padding: 0; min-height: 0; }

.appointment-history-body {
  flex: 1 1 auto;
  padding: 12px 20px 16px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.appointment-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.appointment-history-row {
  display: grid;
  /* Phase 9 redesign — tighten the actor column so the sentence has more
   * room for the inline diff. */
  grid-template-columns: minmax(96px, 140px) 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-2, var(--border, #d4d8df));
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink, #15161a);
}
.appointment-history-row:last-child { border-bottom: 0; }

.appointment-history-row__actor {
  font-weight: 500;
  color: var(--ink, #15161a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appointment-history-row__sentence {
  color: var(--ink, #15161a);
}
.appointment-history-row__sentence strong {
  font-weight: 600;
  color: var(--ink, #15161a);
}
/* Phase 9 redesign — inline diff run instead of a filled <dl> card.
 * docs/specs/appointment-history-modal-redesign.md */
.appointment-history-row__changes {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted, #5b6470);
}
.appointment-history-row__changes-list {
  display: inline;
}
.appointment-history-row__change + .appointment-history-row__change::before {
  content: " · ";
  color: var(--line-2, var(--border, #d4d8df));
  padding: 0 4px;
}
.appointment-history-row__change-label {
  color: var(--muted, #5b6470);
}
.appointment-history-row__change-old {
  color: var(--muted, #5b6470);
  text-decoration: line-through;
  text-decoration-color: var(--muted, #5b6470);
  font-variant-numeric: tabular-nums;
}
.appointment-history-row__change-new {
  color: var(--ink, #15161a);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.appointment-history-row__changes-summary {
  cursor: pointer;
  display: inline;
  list-style: none;
  color: var(--midnight, #1b3559);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.appointment-history-row__changes-summary::-webkit-details-marker { display: none; }
details[open] > .appointment-history-row__changes-summary { display: none; }
.appointment-history-row__time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  /* Phase 9 redesign — promote the time column so the operator can scan a
   * stack of rows quickly. Previous color was --muted which made it the
   * smallest element on the row. */
  color: var(--ink, #15161a);
  white-space: nowrap;
  cursor: help;
}

.appointment-history-empty {
  margin: 24px 0;
  text-align: center;
  color: var(--muted, #5b6470);
  font-size: 14px;
  font-style: italic;
}

.appointment-history-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--danger-800, #991b1b);
  font-size: 14px;
  text-align: center;
}
.appointment-history-error p { margin: 0; }

/* Org-wide history page (templates/dashboard_history.html).
 *
 * Reuses ``.appointment-history-row`` / ``-label`` / ``-value`` for the row
 * anatomy so the timeline looks identical between the per-appointment modal
 * and the org-wide feed. Extra container chrome lives here. */
.org-history-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.org-history-filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--ink, #15161a);
}
.org-history-filter input,
.org-history-filter select {
  padding: 8px 10px;
  border: 1px solid var(--line, var(--border, #d4d8df));
  border-radius: var(--radius-sm, 2px);
  font: inherit;
}
.org-history-filter-actions {
  display: flex;
  gap: 8px;
  align-self: end;
}
.org-history-status {
  min-height: 1.2em;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted, #5b6470);
}
.org-history-status:empty { margin-bottom: 0; min-height: 0; }
.org-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.org-history-row {
  border-bottom: 1px solid var(--line-2, var(--border, #d4d8df));
}
.org-history-row__link {
  color: var(--midnight, #1b3559);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-variant-numeric: tabular-nums;
}
.org-history-row__link:hover {
  color: var(--brass, #b8893a);
}
.org-history-load-more {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

@media (max-width: 540px) {
  .appointment-history-overlay { padding: 0; align-items: flex-start; }
  .appointment-history-card {
    width: 100%;
    margin-top: calc(env(safe-area-inset-top, 0px) + 32px);
    max-height: 90vh;
    border-radius: var(--radius-md, 4px);
  }
  .appointment-history-header { padding: 16px 18px 10px 18px; }
  .appointment-history-body { padding: 10px 18px 16px 18px; }
  .appointment-history-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px 0;
  }
  .appointment-history-row__time {
    order: 3;
    font-size: 12px;
  }
  .appointment-history-row__actor { font-size: 13px; }
}
