/* THE 1870 PROJECT — Weekly Beta Update
   Announcement bar + desktop drawer + mobile bottom sheet.
   Uses only tokens from design-tokens.css.
   No persistence, purchase, or auto-open logic lives here.

   Z-INDEX CONTRACT (from ALERT-1 audit):
     header              = 100
     --wu-z-bar          = 101   (announcement bar, above header)
     --wu-z-panel        = 10001 (drawer/sheet, below all transaction UI)
     transaction modals  = 99998–100000
*/

:root {
  /* Header height dependency — isolated here so it appears in exactly one place.
     If the header height ever changes, update only this variable. */
  --wu-header-height: 64px;

  /* Z-index slots */
  --wu-z-bar:   101;
  --wu-z-panel: 10001;

  /* Panel dimensions */
  --wu-drawer-width: clamp(420px, 38vw, 500px);
  --wu-sheet-max-height: 88dvh;

  /* Transition */
  --wu-transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── ANNOUNCEMENT BAR ──────────────────────────────────────────────────────── */

#weekly-update-bar {
  position: sticky;
  top: var(--wu-header-height);
  z-index: var(--wu-z-bar);
  background: var(--bg-parchment);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 2px 8px rgba(139, 69, 19, 0.07);
  transition: opacity 0.2s ease;
}

#weekly-update-bar[hidden] {
  display: none;
}

/* new state — slightly warmer, gold left accent */
#weekly-update-bar[data-update-state="new"] {
  border-left: 3px solid var(--brand-gold);
  background: var(--bg-warm);
}

/* seen state — quieter, no accent border */
#weekly-update-bar[data-update-state="seen"] {
  border-left: none;
  background: var(--bg-parchment);
  opacity: 0.88;
}

.wu-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.55rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.wu-bar-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-mahogany);
  background: rgba(139, 69, 19, 0.09);
  border: 1px solid rgba(139, 69, 19, 0.18);
  border-radius: 20px;
  padding: 0.2rem 0.6rem;
  white-space: nowrap;
  flex-shrink: 0;
}

#weekly-update-bar[data-update-state="new"] .wu-bar-badge {
  background: rgba(212, 165, 116, 0.22);
  border-color: var(--brand-gold);
  color: var(--brand-oak);
}

.wu-bar-message {
  flex: 1;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.95rem;
  color: var(--text-body);
  line-height: 1.4;
  min-width: 0;
}

.wu-bar-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.wu-bar-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-mahogany);
  cursor: pointer;
  padding: 0.3rem 0;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s;
  min-height: 44px;
}

.wu-bar-trigger:hover {
  color: var(--brand-oak);
}

.wu-bar-trigger:focus-visible {
  outline: 2px solid var(--brand-mahogany);
  outline-offset: 3px;
  border-radius: 3px;
}

.wu-bar-trigger-arrow {
  font-size: 1rem;
  transition: transform 0.15s;
}

.wu-bar-trigger:hover .wu-bar-trigger-arrow {
  transform: translateX(3px);
}

@media (max-width: 768px) {
  .wu-bar-inner {
    padding: 0.6rem 1rem;
    gap: 0.6rem;
  }

  .wu-bar-meta {
    display: none;
  }

  .wu-bar-message {
    font-size: 0.88rem;
  }
}

@media (max-width: 480px) {
  /* Grid layout: content column left, dismiss pinned top-right.
     Row 1: badge | dismiss (spans rows 1-3)
     Row 2: message
     Row 3: trigger
  */
  .wu-bar-inner {
    display: grid;
    grid-template-columns: 1fr 44px;
    grid-template-rows: auto auto auto;
    align-items: start;
    padding: 10px 16px 12px;
    column-gap: 0;
    row-gap: 0;
  }

  .wu-bar-badge {
    grid-column: 1;
    grid-row: 1;
    margin-bottom: 6px;
  }

  /* Dismiss spans all 3 rows, anchored top-right */
  .wu-bar-dismiss {
    grid-column: 2;
    grid-row: 1 / 4;
    align-self: start;
    justify-self: end;
    margin-top: -4px;
  }

  .wu-bar-message {
    grid-column: 1;
    grid-row: 2;
    font-size: 0.88rem;
    margin-bottom: 7px;
  }

  .wu-bar-trigger {
    grid-column: 1;
    grid-row: 3;
    align-self: start;
    justify-self: start;
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    padding-bottom: 1px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .wu-bar-meta {
    display: none;
  }
}

/* ─── BACKDROP ──────────────────────────────────────────────────────────────── */

#weekly-update-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--wu-z-panel) - 1);
  background: rgba(28, 16, 8, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--wu-transition);
}

#weekly-update-backdrop.wu-visible {
  opacity: 1;
  pointer-events: auto;
}

#weekly-update-panel[hidden],
#weekly-update-backdrop[hidden] {
    display: none;
}

/* ─── PANEL (shared structure for drawer + sheet) ───────────────────────────── */

#weekly-update-panel {
  position: fixed;
  z-index: var(--wu-z-panel);
  background: var(--bg-parchment);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 32px rgba(28, 16, 8, 0.18);

  /* Desktop: right-side drawer */
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--wu-drawer-width);
  transform: translateX(100%);
  transition: transform var(--wu-transition);
  border-left: 1px solid var(--border-subtle);
  border-radius: 0;
}

#weekly-update-panel.wu-open {
  transform: translateX(0);
}

/* Mobile: bottom sheet */
@media (max-width: 768px) {
  #weekly-update-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: var(--wu-sheet-max-height);
    overflow: hidden;
    transform: translateY(100%);
    transition: transform var(--wu-transition);
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 32px rgba(28, 16, 8, 0.18);
  }

  #weekly-update-panel.wu-open {
    transform: translateY(0);
  }
}

/* ─── PANEL HEADER ──────────────────────────────────────────────────────────── */

.wu-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--bg-parchment);
}

/* Mobile sheet drag handle */
@media (max-width: 768px) {
  .wu-panel-header::before {
    content: '';
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
  }

  .wu-panel-header {
    position: relative;
    padding-top: 1.5rem;
  }
}

.wu-panel-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.wu-panel-eyebrow {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand-mahogany);
}

.wu-panel-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  font-weight: 700;
  color: var(--text-dark);
  margin: 0;
  line-height: 1.25;
}

.wu-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.wu-close-btn:hover {
  background: rgba(139, 69, 19, 0.08);
  color: var(--text-dark);
}

.wu-close-btn:focus-visible {
  outline: 2px solid var(--brand-mahogany);
  outline-offset: 2px;
}

/* ─── PANEL BODY ────────────────────────────────────────────────────────────── */

.wu-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem;
  -webkit-overflow-scrolling: touch;
}

/* ─── INTRO ─────────────────────────────────────────────────────────────────── */

.wu-intro {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1.05rem;
  color: var(--text-body);
  line-height: 1.7;
  margin: 0 0 1.5rem;
}

/* ─── IMPROVEMENTS LIST ─────────────────────────────────────────────────────── */

.wu-improvements {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0 0 1.5rem;
}

.wu-improvement {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-subtle);
}

.wu-improvement:last-child {
  border-bottom: none;
}

.wu-improvement-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-dark);
  margin: 0 0 0.3rem;
}

.wu-improvement-detail {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.92rem;
  color: var(--text-body);
  line-height: 1.6;
  margin: 0;
}

/* ─── MISSION NOTE ──────────────────────────────────────────────────────────── */

.wu-mission {
  background: rgba(139, 69, 19, 0.05);
  border-left: 3px solid var(--brand-gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.875rem 1rem;
  margin: 0 0 1.5rem;
}

.wu-mission p {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.9rem;
  color: var(--text-body);
  line-height: 1.65;
  margin: 0;
}

/* ─── THANK YOU ─────────────────────────────────────────────────────────────── */

.wu-thankyou {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 1.5rem;
  font-style: italic;
}

/* ─── PANEL FOOTER / ACTIONS ────────────────────────────────────────────────── */

.wu-panel-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex-shrink: 0;
  background: var(--bg-parchment);
}

/* Primary action — Continue Exploring */
.wu-action-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.875rem 1.5rem;
  background: var(--gradient-brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: 44px;
}

.wu-action-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(139, 69, 19, 0.35);
}

.wu-action-primary:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 3px;
}

.wu-action-primary:active {
  transform: translateY(0);
}

/* ─── BAR DISMISS BUTTON (ALERT-5) ─────────────────────────────────────────── */
/* Explicit version-dismiss control. Distinct from the panel close button. */

.wu-bar-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.wu-bar-dismiss:hover {
  background: rgba(139, 69, 19, 0.08);
  color: var(--text-dark);
}

.wu-bar-dismiss:focus-visible {
  outline: 2px solid var(--brand-mahogany);
  outline-offset: 2px;
}

/* wu-bar-dismiss mobile positioning handled in the .wu-bar-inner grid block above */

/* ─── MOBILE BODY COPY ALIGNMENT ────────────────────────────────────────────── */
/* Section headings stay centered; substantive multi-line body copy left-aligns
   for easier scanning on narrow viewports. */

@media (max-width: 768px) {
  .wu-intro,
  .wu-improvement-detail,
  .wu-mission p,
  .wu-thankyou {
    text-align: left;
  }
}

/* ─── IOS SAFE AREA — footer carries the inset so body scroll ends above it ── */

@media (max-width: 768px) {
  .wu-panel-footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

/* ─── REDUCED MOTION ────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  #weekly-update-panel,
  #weekly-update-backdrop,
  .wu-bar-trigger-arrow,
  .wu-action-primary {
    transition: none;
  }
}
