/* File History page — scrollable control-plane content + left-date timeline.
   Pattern: left-aligned activity rail (date + time under) with continuous spine. */

.fh-root {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(1200px 480px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 55%),
    var(--bg);
}

.fh-inner {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 20px 16px 96px;
  box-sizing: border-box;
}

@media (min-width: 720px) {
  .fh-inner {
    padding: 28px 28px 120px;
  }
}

/* ── Hero ─────────────────────────────────────────────── */

.fh-hero {
  margin-bottom: 1.75rem;
}

.fh-back {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0;
  margin-bottom: 1rem;
}

.fh-back:hover {
  text-decoration: underline;
}

.fh-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.fh-hero-top {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 720px) {
  .fh-hero-top {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
  }
}

.fh-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.fh-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 750;
  line-height: 1.15;
  color: var(--text);
  text-wrap: balance;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (min-width: 720px) {
  .fh-title {
    font-size: 1.85rem;
  }
}

.fh-path {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.fh-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  min-width: min(100%, 260px);
}

.fh-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.fh-stat-n {
  font-size: 1.15rem;
  font-weight: 750;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fh-stat-l {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.fh-search {
  margin-top: 1.15rem;
}

.fh-search-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.fh-search-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.fh-search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
}

.fh-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.fh-search-btn {
  border: none;
  border-radius: 10px;
  padding: 0 1rem;
  min-height: 44px;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg);
  white-space: nowrap;
}

.fh-suggest {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.fh-suggest-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.fh-suggest-row:last-child {
  border-bottom: 0;
}

.fh-suggest-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.fh-suggest-name {
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.fh-suggest-path {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.fh-suggest-open {
  display: none;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font: 700 12px/1 inherit;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  flex-shrink: 0;
}

@media (hover: hover) and (min-width: 840px) {
  .fh-suggest-row:hover .fh-suggest-open,
  .fh-suggest-row:focus-within .fh-suggest-open {
    display: inline-flex;
    align-items: center;
  }
}

.fh-preview {
  position: fixed;
  z-index: 70;
  inset: 0;
  bottom: var(--phone-thumb, 0px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}

.fh-preview-x {
  align-self: flex-end;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.fh-preview-x:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fh-preview-name,
.fh-preview-path {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.fh-preview-name {
  font-size: 1.25rem;
  line-height: 1.3;
}

.fh-preview-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.fh-preview-go {
  align-self: flex-start;
}

.fh-search-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.fh-search-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fh-summary-bar {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.fh-summary-text {
  flex: 1 1 100%;
  margin: 0.15rem 0 0;
  color: var(--text2, var(--text));
  font-size: 0.9rem;
  line-height: 1.45;
  max-width: 70ch;
}

/* ── States ───────────────────────────────────────────── */

.fh-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 260px;
  color: var(--muted);
}

.fh-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: fh-spin 0.75s linear infinite;
}

.fh-loading-text {
  font-size: 0.92rem;
}

.fh-banner {
  padding: 1rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.fh-banner-error {
  color: #f87171;
  border-color: color-mix(in srgb, #ef4444 35%, var(--border));
  background: color-mix(in srgb, #ef4444 10%, var(--surface));
}

.fh-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.fh-empty-glyph {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  opacity: 0.7;
}

/* ── Sections ─────────────────────────────────────────── */

.fh-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.fh-section-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.fh-section-meta {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.fh-panel {
  margin-top: 1.75rem;
  padding: 1.1rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

@media (min-width: 720px) {
  .fh-panel {
    padding: 1.25rem 1.25rem;
  }
}

.fh-panel-last {
  margin-bottom: 1rem;
}

.fh-note {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ── Timeline (date | rail | card) ────────────────────── */

.fh-timeline-section {
  margin-top: 0.5rem;
}

.fh-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.fh-item {
  display: grid;
  grid-template-columns: 4.75rem 1.35rem 1fr;
  column-gap: 0.65rem;
  align-items: stretch;
}

@media (min-width: 640px) {
  .fh-item {
    grid-template-columns: 6.25rem 1.5rem 1fr;
    column-gap: 0.9rem;
  }
}

@media (max-width: 839px) {
  .fh-inner {
    width: 100%;
    padding: 12px 12px calc(88px + env(safe-area-inset-bottom, 0px));
  }

  .fh-back {
    display: none;
  }

  .fh-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
  }

  .fh-rail {
    display: none;
  }

  .fh-when {
    align-items: flex-start;
    text-align: start;
    padding-top: 0;
  }

  .fh-result,
  .fh-summary-text {
    max-width: none;
  }

  .fh-suggest-row {
    flex-direction: column;
    align-items: stretch;
  }

  .fh-suggest-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
    min-height: 40px;
  }

  .fh-search-input {
    font-size: 16px;
  }
}

.fh-when {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-top: 0.35rem;
  text-align: end;
  gap: 0.12rem;
}

.fh-date {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  text-wrap: balance;
}

@media (min-width: 640px) {
  .fh-date {
    font-size: 0.86rem;
  }
}

.fh-time {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

@media (min-width: 640px) {
  .fh-time {
    font-size: 0.75rem;
  }
}

.fh-rail {
  position: relative;
  display: flex;
  justify-content: center;
}

.fh-rail::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 55%, transparent),
    color-mix(in srgb, var(--border) 90%, transparent) 40%,
    color-mix(in srgb, var(--border) 90%, transparent)
  );
}

.fh-item:first-child .fh-rail::before {
  top: 0.85rem;
}

.fh-item:last-child .fh-rail::before {
  bottom: calc(100% - 1.15rem);
}

.fh-marker {
  position: relative;
  z-index: 1;
  width: 12px;
  height: 12px;
  margin-top: 0.7rem;
  border-radius: 50%;
  background: var(--bg);
  border: 2.5px solid var(--accent);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent),
    0 0 18px color-mix(in srgb, var(--accent) 35%, transparent);
  flex-shrink: 0;
}

.fh-kind-planned .fh-marker { border-color: #94a3b8; box-shadow: 0 0 0 4px color-mix(in srgb, #94a3b8 18%, transparent); }
.fh-kind-touched .fh-marker { border-color: var(--accent); }
.fh-kind-active .fh-marker {
  border-color: #34d399;
  box-shadow:
    0 0 0 4px color-mix(in srgb, #34d399 20%, transparent),
    0 0 16px color-mix(in srgb, #34d399 40%, transparent);
  animation: fh-pulse 2.2s ease-out infinite;
}
.fh-kind-discovered .fh-marker { border-color: #60a5fa; box-shadow: 0 0 0 4px color-mix(in srgb, #60a5fa 18%, transparent); }
.fh-kind-reopened .fh-marker { border-color: #fbbf24; box-shadow: 0 0 0 4px color-mix(in srgb, #fbbf24 18%, transparent); }

.fh-card {
  margin-bottom: 0.95rem;
  padding: 0.85rem 0.9rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px color-mix(in srgb, #000 12%, transparent);
  transition: border-color 160ms ease, transform 160ms ease;
}

@media (min-width: 640px) {
  .fh-card {
    padding: 1rem 1.1rem;
    margin-bottom: 1.1rem;
  }
}

.fh-item:hover .fh-card {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.fh-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.fh-kind,
.fh-state,
.fh-file-chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.18rem 0.48rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent-subtle-fg, var(--text));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.fh-state {
  background: color-mix(in srgb, var(--text) 6%, var(--surface));
  color: var(--text2, var(--text));
  border-color: var(--border);
  font-weight: 600;
}

.fh-kind-dep {
  background: color-mix(in srgb, #60a5fa 16%, var(--surface));
  border-color: color-mix(in srgb, #60a5fa 30%, transparent);
  color: #93c5fd;
}

.fh-kind-graph {
  background: color-mix(in srgb, #c084fc 16%, var(--surface));
  border-color: color-mix(in srgb, #c084fc 30%, transparent);
  color: #d8b4fe;
}

.fh-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  text-wrap: pretty;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.fh-meta-rows {
  margin-top: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.fh-meta-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.5rem;
  font-size: 0.82rem;
  line-height: 1.35;
}

.fh-meta-row > span:first-child {
  color: var(--muted);
  font-weight: 600;
}

.fh-meta-row > span:last-child {
  color: var(--text2, var(--text));
  word-break: break-word;
}

.fh-result {
  margin: 0.65rem 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text2, var(--text));
  max-width: 68ch;
}

.fh-files {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.65rem;
}

.fh-file-chip {
  max-width: 100%;
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-weight: 600;
  background: color-mix(in srgb, var(--text) 5%, var(--surface));
  color: var(--muted);
  border-color: var(--border);
}

.fh-details-toggle {
  margin-top: 0.7rem;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
}

.fh-details-toggle:hover {
  text-decoration: underline;
}

.fh-details-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.fh-details {
  margin: 0.55rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 70%, var(--surface));
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.fh-detail-row {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin: 0;
}

.fh-detail-label {
  color: var(--muted);
  font-weight: 650;
}

.fh-detail-value {
  color: var(--text);
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
}

.fh-more {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.fh-more:disabled {
  opacity: 0.6;
  cursor: wait;
}

.fh-more:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

/* ── Open / impact ────────────────────────────────────── */

.fh-candidates,
.fh-open-list,
.fh-impact-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.fh-candidate {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  text-align: start;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

@media (min-width: 640px) {
  .fh-candidate {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
  }
}

.fh-candidate:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.fh-candidate-path {
  font-size: 0.85rem;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.fh-candidate-meta {
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
}

.fh-open-item,
.fh-impact-item {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.fh-open-item:last-child,
.fh-impact-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.fh-open-bullet {
  width: 8px;
  height: 8px;
  margin-top: 0.4rem;
  border-radius: 50%;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.fh-open-title {
  font-weight: 650;
  color: var(--text);
  font-size: 0.92rem;
}

.fh-open-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  align-items: center;
}

.fh-impact-item {
  align-items: center;
  flex-wrap: wrap;
}

/* ── Motion ───────────────────────────────────────────── */

@keyframes fh-spin {
  to { transform: rotate(360deg); }
}

@keyframes fh-pulse {
  0%, 100% { box-shadow: 0 0 0 4px color-mix(in srgb, #34d399 18%, transparent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, #34d399 8%, transparent), 0 0 20px color-mix(in srgb, #34d399 35%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .fh-spinner,
  .fh-kind-active .fh-marker {
    animation: none;
  }

  .fh-card {
    transition: none;
  }
}
