/* ── Archive viewing rail ──────────────────────────────────── */
.archive-rail {
  display: none;
  position: relative;
  flex-shrink: 0;
  z-index: 40;
  pointer-events: auto;
}

.app.is-viewing-archived .archive-rail {
  display: block;
}

.archive-rail-bar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 0;
  min-height: 44px;
  padding: 4px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.archive-rail-center {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  text-align: center;
  padding: 4px 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
}

.archive-rail-center:hover .archive-rail-label,
.archive-rail-center[aria-expanded="true"] .archive-rail-label {
  color: var(--accent);
}

.archive-rail-center:hover .archive-rail-chevron,
.archive-rail-center[aria-expanded="true"] .archive-rail-chevron {
  color: var(--accent);
}

.archive-rail-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1.2;
}

.archive-rail-label-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}

.archive-rail-label {
  max-width: 100%;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-rail-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-3);
  transition: transform 0.15s ease;
}

.archive-rail-center[aria-expanded="true"] .archive-rail-chevron {
  transform: rotate(180deg);
}

.archive-rail-nav {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.archive-rail-nav svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

.archive-rail-nav:hover:not(:disabled) {
  color: var(--accent);
}

.archive-rail-nav:active:not(:disabled) {
  color: var(--accent);
}

.archive-rail-nav:disabled {
  opacity: 0.28;
  cursor: default;
}

.archive-rail-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  display: flex;
  flex-direction: column;
  max-height: min(52vh, 340px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 16px 32px color-mix(in srgb, var(--scrim) 55%, transparent);
  z-index: 45;
}

.archive-rail-menu[hidden] {
  display: none;
}

.archive-rail-menu-list {
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.archive-rail-menu-item {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  font-family: var(--font);
  text-align: left;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.archive-rail-menu-item:hover,
.archive-rail-menu-item:active {
  background: var(--fill-subtle);
}

.archive-rail-menu-item.is-current {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.archive-rail-menu-item-main {
  display: contents;
}

.archive-rail-menu-item .period-card-lamp,
.archive-rail-menu-item .period-card-lamp-slot {
  grid-column: 1;
  justify-self: start;
}

.archive-rail-menu-item-label {
  grid-column: 2;
  justify-self: center;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-width: 0;
  white-space: nowrap;
}

.archive-rail-menu-item-meta {
  grid-column: 3;
  justify-self: end;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.archive-rail-menu-exit {
  flex-shrink: 0;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.archive-rail-menu-exit:hover,
.archive-rail-menu-exit:active {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

[data-theme="dark"] .archive-rail-bar,
[data-theme="dark"] .archive-rail-menu {
  background: color-mix(in srgb, var(--surface) 94%, var(--accent));
}

[data-theme="dark"] .archive-rail-menu-exit {
  background: color-mix(in srgb, var(--surface) 94%, var(--accent));
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
}

.view.active { display: flex; }

.view.subview.active { padding-bottom: 0; }

.view-body {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

#home-body {
  overflow-anchor: none;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

#home-body.is-dragging {
  cursor: grabbing;
}

#home-body button,
#home-body a,
#home-body input,
#home-body textarea,
#home-body select,
#home-body label {
  cursor: pointer;
  user-select: none;
}

.view-body.flush { padding: 0; }

#tx-body {
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.view-body:not(#home-body) {
  cursor: grab;
}

.view-body.is-drag-scrolling {
  cursor: grabbing;
  user-select: none;
}

.view-body:not(#home-body) button,
.view-body:not(#home-body) a,
.view-body:not(#home-body) input,
.view-body:not(#home-body) textarea,
.view-body:not(#home-body) select,
.view-body:not(#home-body) label {
  cursor: pointer;
}

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .meta {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 400;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon:active { background: var(--surface-2); }

.btn-text {
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 0;
}

/* ── Period selector ───────────────────────────────────────── */
.period-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  max-width: 58%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
}

.period-btn svg { flex-shrink: 0; color: var(--text-3); }

/* ── Bottom nav ────────────────────────────────────────────── */
.bottom-nav-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  overflow: visible;
  pointer-events: none;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.bottom-nav {
  width: 100%;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: visible;
  pointer-events: auto;
}

.bottom-nav-wrap.hidden { display: none; }

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  padding: 6px 0;
  min-width: 0;
}

.nav-btn svg { width: 20px; height: 20px; }

.nav-btn.active { color: var(--accent); }

.nav-btn.add {
  position: relative;
  overflow: visible;
}

.nav-add-fab {
  --fab: var(--nav-fab);
  width: var(--fab);
  height: var(--fab);
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% - var(--fab) * 0.8);
  transition: background 0.15s, box-shadow 0.15s;
}

.nav-add-fab svg {
  width: 24px;
  height: 24px;
}

.nav-btn.add:active .nav-add-fab {
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}

/* ── Section ───────────────────────────────────────────────── */
.section { margin-bottom: 20px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.section-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font);
  font-weight: 500;
}

/* ── Cards & panels ────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  min-width: 0;
  max-width: 100%;
}

.panel + .panel { margin-top: 8px; }

.panel.flat { border-radius: 0; border-left: none; border-right: none; }
