/* ==========================================================================
   Trade Detail drawer

   Sibling of .modal, not a variant of it: right-edge panel on desktop,
   full-screen sheet on mobile, and it stays open while a modal (Edit /
   Delete confirm) sits on top - hence the lower z-index pair and its own
   `drawer-open` scroll-lock class.
   ========================================================================== */

.detail-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: var(--z-drawer-backdrop);
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-standard);
  touch-action: none;
}

.detail-drawer-backdrop.is-open {
  opacity: 1;
}

.detail-drawer {
  position: relative;
  z-index: var(--z-drawer);
  width: 100%;
  max-width: 460px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-surface-raised);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-spring);
  touch-action: auto;
}

.detail-drawer-backdrop.is-open .detail-drawer {
  transform: translateX(0);
}

.detail-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.detail-drawer__title {
  font-size: var(--fs-footnote);
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.detail-drawer__body {
  flex: 1;
  min-height: 0;
  padding: var(--space-5);
  overflow-x: hidden;
  overflow-y: auto;
  /* Screenshots load in asynchronously and change the panel's height; the
     gutter is reserved so that arrival doesn't nudge the whole panel. */
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.detail-drawer__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ---- Header block ---- */

.detail-head__top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.detail-head__symbol {
  font-size: var(--fs-title3);
  font-weight: var(--fw-semibold);
}

.detail-head__pnl {
  font-size: var(--fs-title1);
  font-weight: var(--fw-semibold);
  line-height: 1.1;
  margin-top: var(--space-2);
  overflow-wrap: anywhere;
}

.detail-head__meta {
  margin-top: 2px;
  font-size: var(--fs-footnote);
  color: var(--color-text-secondary);
}

/* ---- Sections ---- */

.detail-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
}

.detail-section__title {
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.detail-rows {
  display: flex;
  flex-direction: column;
}

.detail-rows__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-footnote);
}

.detail-rows__row:last-child {
  border-bottom: none;
}

.detail-rows__row dt {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.detail-rows__row dd {
  text-align: right;
  font-weight: var(--fw-medium);
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-partials {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-hover);
  font-size: var(--fs-caption);
}

.detail-partials__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
}

.detail-partials__row--rest {
  color: var(--color-text-tertiary);
}

.detail-notes {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-hover);
  font-size: var(--fs-footnote);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---- Planned vs realized bar ----
   A price axis, so left-to-right is price order rather than profit order.
   Labels alternate above/below the track so two close markers can't
   overprint each other. */

.level-bar {
  /* Top padding clears the Stop/TP label row (labels are absolutely
     positioned inside the track). The two lower rows are cleared by the
     caption's margin-top instead, so the block ends right under the text. */
  padding: 32px 6px 4px;
}

.level-bar__track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--color-surface-hover);
}

.level-bar__zone {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.level-bar__zone--risk {
  background: var(--color-loss);
  opacity: 0.35;
}

.level-bar__zone--reward {
  background: var(--color-profit);
  opacity: 0.35;
}

.level-bar__partial {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--color-text-secondary);
}

.level-bar__marker {
  position: absolute;
  top: 50%;
  width: 0;
}

.level-bar__tick {
  position: absolute;
  left: -1px;
  top: -8px;
  width: 2px;
  height: 16px;
  border-radius: 1px;
  background: var(--color-text-tertiary);
}

.level-bar__label {
  position: absolute;
  left: 0;
  transform: translateX(-50%);
  font-size: var(--fs-caption);
  color: var(--color-text-tertiary);
  white-space: nowrap;
}

.level-bar__marker--above .level-bar__label {
  bottom: 13px;
}

.level-bar__marker--below .level-bar__label {
  top: 13px;
}

/* Second lower row - Exit only, so it can never overprint Entry. The 18px
   step is one label line-box, so the two rows clear each other exactly. */
.level-bar__marker--below-far .level-bar__label {
  top: 31px;
}

.level-bar__marker--stop .level-bar__tick {
  background: var(--color-loss);
}

.level-bar__marker--tp .level-bar__tick {
  background: var(--color-profit);
}

.level-bar__marker--entry .level-bar__tick {
  background: var(--color-text-primary);
}

/* The one marker that is fact rather than plan - drawn as a filled dot so
   it reads differently from the three planned ticks. */
.level-bar__marker--exit .level-bar__tick {
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-surface-raised);
}

.level-bar__marker--exit .level-bar__label {
  color: var(--color-accent);
  font-weight: var(--fw-medium);
}

.level-bar__caption {
  margin-top: 48px;
  font-size: var(--fs-caption);
  color: var(--color-text-tertiary);
}

/* ---- Screenshots ---- */

.shot-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.shot-tile {
  position: relative;
  width: 84px;
  height: 62px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface-hover);
}

.shot-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

.shot-tile__remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
}

.shot-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.shot-actions .btn.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.shot-lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: rgba(0, 0, 0, 0.82);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-standard);
  cursor: zoom-out;
}

.shot-lightbox.is-open {
  opacity: 1;
}

.shot-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-lg);
  object-fit: contain;
}

/* ---- Mobile: full-screen sheet ----
   Same breakpoint as the rest of the mobile shell (880px, see layout.css). */
@media (max-width: 880px) {
  .detail-drawer {
    max-width: 100%;
    border-left: none;
  }

  .detail-drawer__footer {
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  }

  .shot-tile {
    width: 76px;
    height: 56px;
  }
}

