html,
body {
  overflow-x: hidden;
}

body.reflections-lock {
  overflow: hidden;
}

:root {
  --rf-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --rf-fast: 180ms;
  --rf-med: 280ms;
}

.reflections-page {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 10px calc(96px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.reflections-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid #262c37;
  background: linear-gradient(170deg, rgba(24, 27, 35, 0.96), rgba(14, 17, 24, 0.98));
}

.reflections-eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 12px;
  color: #9aa6ba;
}

.reflections-header h1 {
  margin: 0;
  color: var(--gold);
}

.reflections-subtitle {
  margin: 8px 0 0;
  color: #bcc5d2;
  font-size: 13px;
}

.reflections-header-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.reflections-controls {
  gap: 10px;
  position: sticky;
  top: 8px;
  z-index: 30;
  backdrop-filter: blur(8px);
  background: rgba(18, 22, 29, 0.78);
  border: 1px solid #2a3442;
}

.memory-radar {
  border: 1px solid #2b3a4e;
  background: linear-gradient(155deg, #18202c, #121821);
  animation: cardIn var(--rf-med) var(--rf-ease) both;
}

.memory-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.memory-eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #96a9c7;
}

.memory-head h2 {
  margin: 0;
  font-size: 18px;
}

.memory-subtitle {
  margin: 0;
  color: #b7c2d3;
  font-size: 13px;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.memory-box {
  margin: 0;
  border: 1px solid #2d3a4d;
  border-radius: 12px;
  padding: 10px;
  background: #151d29;
}

.memory-label {
  margin: 0 0 4px;
  color: #9fb0c7;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.memory-risk {
  display: inline-flex;
  border-radius: 999px;
  border: 1px solid #42506a;
  padding: 4px 9px;
  font-size: 12px;
}

.memory-risk.low {
  border-color: rgba(46, 204, 113, 0.55);
  color: #9fe6bf;
}

.memory-risk.medium {
  border-color: rgba(245, 196, 0, 0.65);
  color: #f7dd90;
}

.memory-risk.high {
  border-color: rgba(231, 76, 60, 0.65);
  color: #ffb0a9;
}

.memory-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.memory-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #d8e0eb;
  font-size: 13px;
}

.reflection-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.reflection-tab,
.reflection-type-btn {
  border: 1px solid #333d4a;
  border-radius: 10px;
  background: #171c25;
  color: #d7deea;
  font-weight: 700;
  font-size: 13px;
  padding: 11px 8px;
  min-height: 44px;
  cursor: pointer;
  transition: transform var(--rf-fast) var(--rf-ease), border-color var(--rf-fast) var(--rf-ease), background var(--rf-fast) var(--rf-ease);
}

.reflection-tab.active,
.reflection-type-btn.active {
  color: #f8dfa0;
  border-color: rgba(245, 196, 0, 0.68);
  background: linear-gradient(140deg, rgba(245, 196, 0, 0.18), rgba(40, 32, 8, 0.3));
}

.reflection-tab:active,
.reflection-type-btn:active {
  transform: scale(0.98);
}

.reflection-search-wrap input {
  width: 100%;
}

.reflections-loading {
  display: grid;
  gap: 10px;
}

.skeleton-card {
  min-height: 102px;
  border-radius: 14px;
  border: 1px solid #28303c;
  background: linear-gradient(90deg, #1a1f28 20%, #232a35 35%, #1a1f28 50%);
  background-size: 260% 100%;
  animation: reflectionShimmer 1.3s linear infinite;
}

@keyframes reflectionShimmer {
  to { background-position: -200% 0; }
}

.reflections-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reflection-card {
  border: 1px solid #2a3442;
  border-radius: 14px;
  padding: 12px;
  background: #141921;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s ease, transform 0.2s ease;
  animation: cardIn var(--rf-med) var(--rf-ease) both;
  animation-delay: calc(var(--stagger, 0) * 28ms);
}

.reflection-card:hover {
  border-color: rgba(245, 196, 0, 0.55);
  transform: translateY(-1px);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.reflection-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.reflection-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.reflection-date {
  color: #9ca8ba;
  font-size: 11px;
  white-space: nowrap;
}

.badges-row,
.meta-row,
.chip-list,
.card-actions,
.template-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border: 1px solid #374254;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  color: #dbe2ee;
  background: #1a202b;
}

.badge.market { border-color: rgba(245, 196, 0, 0.45); color: #f6d67c; }
.badge.psycho { border-color: rgba(67, 175, 255, 0.5); color: #9dd5ff; }
.badge.general { border-color: rgba(106, 241, 184, 0.45); color: #a8f6d3; }
.badge.cyclical { border-color: rgba(255, 144, 69, 0.6); color: #ffc59c; }
.badge.pinned { border-color: rgba(255, 211, 111, 0.6); color: #ffe7af; }

.chip {
  border-radius: 999px;
  border: 1px solid #3a4453;
  background: #1a202b;
  color: #d0d8e3;
  padding: 4px 8px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip button {
  background: none;
  border: none;
  color: #cdd5e1;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.meta-item {
  font-size: 11px;
  color: #adb7c7;
}

.card-actions .btn {
  padding: 10px 12px;
  min-height: 40px;
  font-size: 12px;
}

.show-more-tags {
  padding: 6px 10px;
  min-height: 32px;
  font-size: 11px;
  line-height: 1;
}

.reflections-pagination {
  display: flex;
  justify-content: center;
}

.reflections-empty h2 {
  margin: 0;
  font-size: 18px;
}

.reflections-empty p {
  margin: 0;
  color: #b6c0ce;
  font-size: 13px;
}

.reflections-guest-eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 12px;
  color: #9aa6ba;
}

.reflections-guest-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: #c6d0de;
  font-size: 13px;
}

.reflections-guest-cta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.6);
  z-index: 12020;
  animation: fadeIn var(--rf-fast) var(--rf-ease) both;
  pointer-events: auto;
}

.sheet-backdrop.hidden {
  display: none;
  pointer-events: none;
}

.side-sheet {
  position: fixed;
  right: 0;
  top: 0;
  width: min(380px, 92vw);
  height: 100vh;
  background: #111722;
  border-left: 1px solid rgba(245, 196, 0, 0.35);
  z-index: 12030;
  transform: translateX(105%);
  transition: transform var(--rf-med) var(--rf-ease);
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.side-sheet.open {
  transform: translateX(0);
  pointer-events: auto;
}

#sheetBackdrop.hidden,
#filtersDrawer:not(.open),
#reflectionModal.hidden,
#detailModal.hidden {
  pointer-events: none !important;
  visibility: hidden !important;
}

#sheetBackdrop:not(.hidden),
#filtersDrawer.open,
#reflectionModal:not(.hidden),
#detailModal:not(.hidden) {
  visibility: visible;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.side-sheet-head,
.side-sheet-actions {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #252d39;
}

.side-sheet-actions {
  margin-top: auto;
  border-top: 1px solid #252d39;
  border-bottom: none;
}

.side-sheet-body {
  padding: 14px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 12px;
  color: #9ba8bb;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.checkbox-item {
  border: 1px solid #2d3746;
  background: #171d28;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #d3dcea;
}

.checkbox-item.is-collapsed {
  display: none;
}

.checkbox-item input {
  width: auto;
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sheet-close {
  border: 1px solid #3a4557;
  background: #18202c;
  color: #cfd8e7;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 14px;
}

.reflection-modal-content {
  max-width: 760px;
  width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
  overflow: auto;
  border: 1px solid #27313f;
  animation: modalPop var(--rf-med) var(--rf-ease) both;
  pointer-events: auto;
}

.detail-modal-content {
  max-width: 680px;
  width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
  overflow: auto;
  animation: modalPop var(--rf-med) var(--rf-ease) both;
  pointer-events: auto;
}

#reflectionModal,
#detailModal {
  z-index: 14050;
  pointer-events: auto;
}

#reflectionModal .modal-content,
#detailModal .modal-content {
  position: relative;
  z-index: 2;
  isolation: isolate;
  pointer-events: auto;
}

.reflections-page .btn,
.reflections-page button,
.reflections-page a.btn {
  touch-action: manipulation;
}

@keyframes modalPop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.reflection-type-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.template-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: #9db0ca;
}

.template-chip {
  border: 1px solid #365072;
  border-radius: 999px;
  background: #16253a;
  color: #b9d4f2;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.reflection-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reflection-form textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid #2a2d35;
  border-radius: 12px;
  padding: 13px;
  color: white;
  font-size: 16px;
}

.reflection-form textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #d9e1ee;
  padding: 2px 0;
  background: transparent;
  border: none;
}

.toggle-line input {
  appearance: none;
  -webkit-appearance: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid #3a4558;
  background: #1b2230;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-line input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #d4dbe7;
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-line input:checked {
  background: rgba(212, 175, 55, 0.28);
  border-color: rgba(212, 175, 55, 0.85);
}

.toggle-line input:checked::after {
  transform: translateX(16px);
  background: #f5d574;
}

.toggle-line span {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.cycle-fields {
  border: 1px solid #2f3d51;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #151d2a;
}

.range-value {
  margin: -6px 0 0;
  color: #afbbc9;
  font-size: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-text {
  margin: 0;
  color: #d8e0eb;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.toast-area {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 13000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  border: 1px solid #2d3542;
  border-radius: 10px;
  background: #12171f;
  color: #e6edf8;
  padding: 10px 12px;
  font-size: 13px;
  min-width: 220px;
  animation: cardIn var(--rf-fast) var(--rf-ease) both;
  pointer-events: auto;
}

.toast.success { border-color: rgba(46, 204, 113, 0.5); }
.toast.error { border-color: rgba(231, 76, 60, 0.55); }

.hidden {
  display: none !important;
}

@media (min-width: 860px) {
  .reflections-page {
    padding-top: 22px;
    padding-bottom: 32px;
  }

  .reflections-controls {
    position: static;
    backdrop-filter: none;
    background: transparent;
    border: none;
  }

  .reflections-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .reflections-header-actions {
    grid-template-columns: repeat(3, auto);
    align-items: start;
  }

  .reflections-guest-cta {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .reflection-card {
    padding: 13px 14px;
  }

  .memory-columns {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 859px) {
  .reflections-header-actions .btn,
  .reflections-header-actions a.btn {
    min-height: 44px;
  }

  .reflection-date {
    font-size: 10px;
  }

  .side-sheet {
    width: 100%;
    max-width: 100%;
    height: min(78vh, 780px);
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    border-left: none;
    border-top: 1px solid rgba(245, 196, 0, 0.28);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    transform: translateY(108%);
  }

  .side-sheet.open {
    transform: translateY(0);
  }

  .reflection-modal-content,
  .detail-modal-content {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: none;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    animation: sheetUp var(--rf-med) var(--rf-ease) both;
  }

  .modal-top {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #171c24;
    padding-bottom: 6px;
  }

  .toast-area {
    right: 8px;
    left: 8px;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}

@keyframes sheetUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
