.panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: var(--panel-width);
  background-color: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  display: flex;
  flex-direction: column;
  z-index: var(--z-panel);
}

.panel--open {
  transform: translateX(0);
}

.panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.panel__avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--color-accent-soft);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  color: var(--color-accent);
  font-size: var(--font-size-md);
}

.panel__heading {
  flex: 1;
  min-width: 0;
}

.panel__name {
  font-family: var(--font-serif);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel__dates {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-xxs);
}

.panel__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.panel__close:hover {
  background-color: var(--color-surface-alt);
  color: var(--color-text);
}

.panel__tabs {
  display: flex;
  gap: var(--space-xxs);
  padding: var(--space-xs) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  overflow-x: auto;
}

.panel__tab {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.panel__tab--active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
}

.panel__section {
  margin-bottom: var(--space-lg);
}

.panel__section-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
  margin-bottom: var(--space-sm);
}

.panel__field-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel__field-value {
  font-size: var(--font-size-sm);
  color: var(--color-text);
  white-space: pre-wrap;
}

.panel__bio {
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: var(--line-height-loose);
  white-space: pre-wrap;
}

.panel__photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-xs);
}

.panel__photo-cell {
  position: relative;
  aspect-ratio: 1;
}

.panel__photo {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  background-color: var(--color-surface-alt);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: transform var(--transition-fast);
}

.panel__photo:hover {
  transform: scale(1.04);
}

.panel__photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: rgba(28, 25, 23, 0.78);
  color: var(--color-surface);
  border: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.panel__photo-cell:hover .panel__photo-remove,
.panel__photo-remove:focus-visible {
  opacity: 1;
}

.panel__photo-remove:hover {
  background-color: var(--color-error);
}

/* Photo gallery drop zone — present on every photo grid (even empty ones)
   so the user can drop files anywhere in the section. The overlay is
   hidden by default and fades in only while a file drag is over the
   wrapper. */
.panel__photos-dropzone {
  position: relative;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.panel__photos-dropzone--active {
  background-color: var(--color-accent-soft);
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

.panel__photos-drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--font-size-md);
  color: var(--color-accent);
  background-color: rgba(245, 240, 230, 0.86);
  border-radius: var(--radius-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.panel__photos-dropzone--active .panel__photos-drop-overlay {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .panel__photos-dropzone,
  .panel__photos-drop-overlay {
    transition: none;
  }
}

/* Empty-state starter prompts for the Stories section. Renders only when
   `person.stories.length === 0`; chips are gentle, italic, and clickable —
   they open the Add Story modal with a suggested title pre-filled. The
   "or start blank" link below the chips guarantees prompts feel optional. */
.panel__story-prompts {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
}

.panel__story-prompts-intro {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: 0;
  line-height: var(--line-height-normal);
}

.panel__story-prompts-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.panel__story-prompt-chip {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text);
  background-color: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    color var(--transition-fast),
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
}

.panel__story-prompt-chip:hover,
.panel__story-prompt-chip:focus-visible {
  color: var(--color-accent);
  background-color: var(--color-accent-soft);
  border-color: var(--color-accent);
  transform: translateY(-1px);
}

/* Era prompts get a subtle brass left edge so the "this happened during
   their lifetime" prompts read as the most context-rich of the three. */
.panel__story-prompt-chip[data-qualifier="era"] {
  border-left: 3px solid var(--color-highlight);
}

.panel__story-prompt-chip[data-qualifier="relationship"] {
  border-left: 3px solid var(--color-accent);
}

.panel__story-prompt-skip {
  align-self: flex-start;
  padding: var(--space-xxs) var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.panel__story-prompt-skip:hover,
.panel__story-prompt-skip:focus-visible {
  color: var(--color-accent);
  background-color: var(--color-accent-soft);
}

.panel__story {
  padding: var(--space-sm);
  background-color: var(--color-surface-alt);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  border: 1px solid var(--color-border);
}

.panel__story-title {
  font-family: var(--font-serif);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-xxs);
}

.panel__story-date {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.panel__story-content {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-loose);
  /* Story bodies are rendered via MV_Utils.renderMarkdownInline now, which
     emits <p> + <br> markup. pre-wrap would double up the whitespace, so
     leave it normal and lean on the emitted tags for layout. */
}

.panel__story-content p {
  margin: 0 0 var(--space-xs) 0;
}

.panel__story-content p:last-child {
  margin-bottom: 0;
}

.panel__story-content a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.panel__story-content a:hover {
  color: var(--color-highlight);
}

.panel__story-content strong {
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

.panel__story-content em {
  font-style: italic;
}

/* Block-level markdown — headings (h3/h4 inside the story body), lists,
   blockquotes. Stayed conservative on sizes so they don't compete with the
   panel's own heading hierarchy (panel__name is h2; story title is its own
   element). */
.panel__story-content h3 {
  font-family: var(--font-serif);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  margin: var(--space-sm) 0 var(--space-xs);
}

.panel__story-content h3:first-child {
  margin-top: 0;
}

.panel__story-content h4 {
  font-family: var(--font-serif);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: var(--space-sm) 0 var(--space-xxs);
}

/* Restore bullets / numbers stripped by the global reset (reset.css:56-58). */
.panel__story-content ul,
.panel__story-content ol {
  margin: var(--space-xs) 0;
  padding-left: var(--space-lg);
}

.panel__story-content ul {
  list-style: disc;
}

.panel__story-content ol {
  list-style: decimal;
}

.panel__story-content li {
  margin-bottom: 2px;
}

.panel__story-content blockquote {
  margin: var(--space-xs) 0;
  padding: var(--space-xxs) var(--space-sm);
  border-left: 3px solid var(--color-highlight);
  background-color: var(--color-surface-alt);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--color-text);
}

/* Moments — photo-first counterparts to stories. Each row pairs a date +
   optional caption with a horizontal photo strip that scrolls if there
   are more thumbnails than fit the panel width. Subjects beyond the
   panel's focus person appear as small "with X" chips. */
.panel__moment {
  padding: var(--space-sm);
  background-color: var(--color-surface-alt);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  border: 1px solid var(--color-border);
}

.panel__moment-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-xs);
  margin-bottom: var(--space-xs);
  flex-wrap: wrap;
}

.panel__moment-date {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--font-size-base);
  color: var(--color-accent);
}

.panel__moment-with {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.panel__moment-chip {
  display: inline-block;
  padding: 2px var(--space-xs);
  border-radius: var(--radius-pill);
  background-color: var(--color-highlight-soft);
  color: var(--color-highlight);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.panel__moment-strip {
  display: flex;
  gap: var(--space-xs);
  overflow-x: auto;
  padding-bottom: var(--space-xxs);
  margin-bottom: var(--space-xs);
  scrollbar-width: thin;
}

.panel__moment-photo {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border-radius: var(--radius-sm);
  background-color: var(--color-accent-soft);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.panel__moment-photo:hover {
  transform: scale(1.04);
}

.panel__moment-photo:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.panel__moment-caption {
  font-size: var(--font-size-sm);
  color: var(--color-text);
  margin-bottom: var(--space-xs);
  line-height: var(--line-height-loose);
}

.panel__moment-actions {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
}

.moment-form__counter {
  text-align: right;
  margin-top: 4px;
}

.moment-form__counter--warning {
  color: var(--color-highlight);
}

.panel__story-photos {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.panel__story-photo {
  width: 72px;
  height: 72px;
  background-color: var(--color-surface);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.panel__story-photo:hover {
  transform: scale(1.04);
}

.panel__story-actions {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  padding-top: var(--space-xs);
  border-top: 1px dashed var(--color-border);
}

.panel__story-actions .btn {
  font-size: var(--font-size-xs);
  padding: 4px 10px;
}

.panel__pet {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs);
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-xs);
}

.panel__pet:hover {
  background-color: var(--color-surface-alt);
}

.panel__pet-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--color-accent-soft);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.panel__pet-info {
  flex: 1;
  min-width: 0;
}

.panel__pet-name {
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
}

.panel__pet-species {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.panel__footer {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.panel__footer .btn {
  flex: 1;
}

@media (max-width: 640px) {
  .panel {
    width: 100%;
  }
}

@media (min-width: 960px) {
  .panel {
    width: var(--panel-width-md);
  }
}
