/* 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] {
  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;
  grid-template-columns: minmax(120px, 180px) 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: 600;
  color: var(--ink, #15161a);
  overflow-wrap: anywhere;
}
.appointment-history-row__sentence {
  color: var(--ink, #15161a);
}
.appointment-history-row__sentence strong {
  font-weight: 600;
  color: var(--ink, #15161a);
}
.appointment-history-row__time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted, #5b6470);
  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; }

@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; }
}
