/* Texa app components — flow.rest-faithful. Texa-only blocks (modal, toast, expand)
   are fenced and clearly labelled. */

/* ---------- Edge fades ---------- */
.fade {
  background-image: var(--fade-top-gradient);
  width: 100%;
  height: 300px;
  position: fixed;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-med) var(--ease);
}
.main::after {
  content: "";
  background-image: var(--fade-bottom-gradient);
  width: 100%;
  height: 300px;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px;
  position: relative;
  z-index: 3;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  user-select: none;
}
.logo svg { width: 32px; height: 32px; display: block; }

.header-actions { display: flex; align-items: center; gap: 10px; color: var(--fg); }
.menu-trigger { color: var(--fg); }
.menu-trigger svg { width: 24px; height: 24px; }
.menu-trigger:focus-visible { box-shadow: 0 0 0 2px var(--focus-ring); outline: 0; }
.logo, .header-actions { transition: transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease); }
.header[data-flow-mode="true"] .logo { transform: translateX(-64px) scale(0.9); opacity: 0; }
.header[data-flow-mode="true"] .header-actions { transform: translateX(64px); opacity: 0; }

/* ---------- Connection-status dot (green=direct, amber=relayed, gray=offline) ---------- */
.conn-status {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; cursor: help;
}
.conn-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--status-offline);
  transition: background var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease);
}
.conn-status[data-state="direct"] .conn-dot { background: var(--status-direct); box-shadow: 0 0 6px var(--status-direct); }
.conn-status[data-state="relayed"] .conn-dot { background: var(--status-relayed); animation: conn-pulse 2s var(--ease) infinite; }
.conn-status[data-state="offline"] .conn-dot { background: var(--status-offline); }
.conn-status[data-pulsing="true"] .conn-dot { animation: conn-pulse 1.4s var(--ease) infinite; }
@keyframes conn-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Dropdown menu ---------- */
.menu {
  position: fixed;
  z-index: 30;
  background: var(--menu-bg);
  min-width: 160px;
  padding: 4px;
  border-radius: 4px;
  box-shadow: var(--shadow-small);
  transform-origin: top right;
  animation: menu-in 0.1s var(--ease);
}
.menu[hidden] { display: none; }
.menu[data-closing] { animation: menu-out 0.1s var(--ease) forwards; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--gray6);
  cursor: default;
  user-select: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--gray1); color: var(--gray7); outline: 0; }
.menu-item:hover kbd, .menu-item:focus-visible kbd { background: var(--gray2); color: var(--gray7); }
:root[data-theme="light"] .menu-item { color: var(--gray7); } /* light gray6 ≈ 3.3:1 on #fff — bump for AA */
.menu-keybinds { display: flex; align-items: center; margin-left: 16px; }
.menu-keybinds > * + * { margin-left: 4px; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes menu-out { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.9); } }

/* ---------- Main column ---------- */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 120px 32px;
  min-height: 100vh;
}

/* ---------- Compose (root textarea inside Today article) ---------- */
.field { position: relative; }
#root-textarea {
  width: 100%;
  display: block;
  font-size: 16px;
  line-height: 24px;
  color: var(--writing);
  caret-color: var(--fg);
  padding: 0 4px;            /* same 4px bleed as committed thoughts so the */
  margin: 24px -4px 0;       /* active highlight pill is identical width on both */
  border-radius: 4px;
  overflow: hidden;
}
#root-textarea::placeholder { color: var(--muted); }

/* ---------- Divider + sync shimmer ---------- */
.root-divider {
  width: 100%;
  height: 1px;
  background: var(--hairline);
  border: 0;
  margin: 16px 0 0;
  position: relative;
}
.root-divider::after {
  content: "";
  width: 50%;
  height: 1px;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  --loader-color: var(--gray4);
  background: linear-gradient(90deg, transparent 0, var(--loader-color) 50%, transparent 100%);
}
.root-divider[data-loading]::after { animation: divider 1.5s ease infinite; }
@keyframes divider {
  0% { opacity: 1; transform: translateX(0); }
  50% { opacity: 1; transform: translateX(100%); }
  100% { opacity: 1; transform: translateX(0); }
}

/* ---------- Timeline / thoughts ---------- */
article { position: relative; }
article:not(:first-of-type) { margin-top: 48px; }
.day-head { color: var(--fg); }   /* UA-default <h2> size, just ensure color */

.thoughts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.thought { position: relative; }

.thought textarea {
  width: 100%;
  display: block;
  font-size: 16px;
  line-height: 24px;
  color: var(--writing);
  caret-color: var(--fg);
  padding: 0 4px;
  margin: 24px -4px 0;
  border-radius: 4px;
  overflow: hidden;
  transition: filter 2s ease;   /* SLOW re-blur is the resting default */
}
.thought textarea::placeholder { color: var(--muted); }

/* Manual global unblur (Toggle Blur / B) and search-unblur win over inline filter */
.unblur { -webkit-filter: blur(0) !important; filter: blur(0) !important; }

.thought .timestamp {
  position: absolute;
  left: -72px;
  top: 26px;
  color: var(--muted);
  font-size: 12px;
  opacity: 0;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
  transition: opacity var(--t-med) var(--ease);
}
.unblur ~ .timestamp,
.thought textarea[data-active="true"] ~ .timestamp { opacity: 1; }

/* The moving active-thought highlight pill (portaled to <body>) */
.highlight {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  background: var(--highlight);
  z-index: -1;
  opacity: 0;
  pointer-events: none;
  will-change: transform, height, opacity;
  /* flow.rest transitions ONLY height + opacity — the transform (position) is applied instantly,
     so the pill snaps to the active thought while its size/opacity ease. Match that exactly. */
  transition: height var(--t-med) var(--ease), opacity var(--t-med) var(--ease);
}

/* Suppress the filter transition while settling initial blur on load */
.no-anim { transition: none !important; }

/* === Texa-only: per-thought "expand to editor" affordance === */
.thought__expand {
  position: absolute;
  top: 22px;
  right: -2px;
  width: 28px;
  height: 28px;
  min-width: 28px;
  margin: 0;
  border-radius: 6px;
  color: var(--muted);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.thought:hover .thought__expand,
.thought:focus-within .thought__expand { opacity: 1; }
.thought__expand:hover { background: var(--gray1); color: var(--fg); }
.thought__expand svg { width: 15px; height: 15px; }

/* ---------- Omnibar (search) ---------- */
.omnibar {
  width: 296px;
  height: 48px;
  position: fixed;
  top: 48px;
  left: 50%;
  transform: translate(-50%, -50%) translateY(-64px);
  opacity: 0;
  z-index: 32; /* above the header (z 3) so the pill is clickable */
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--menu-bg);
  border: 1px solid var(--gray1);
  border-radius: 8px;
  box-shadow: var(--shadow-small);
  pointer-events: none;
  transition: transform var(--t-med) var(--ease), opacity var(--t-med) var(--ease);
}
.omnibar[data-open="true"] {
  transform: translate(-50%, -50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.omnibar[data-open="true"] ~ .fade { opacity: 1; }
.omnibar .search { width: 160px; height: 40px; font-size: 14px; padding: 0 8px 0 16px; color: var(--fg); }
.omnibar .search::placeholder { color: var(--muted); }
.omnibar .count { font-size: 13px; color: var(--gray7); white-space: nowrap; }
.omnibar .vr { width: 1px; height: 20px; background: #333; margin: 0 12px; flex: none; }
:root[data-theme="light"] .omnibar .vr { background: var(--hairline); }
.omnibar .actions { display: flex; align-items: center; padding-right: 16px; }
.omnibar .actions > * + * { margin-left: 4px; }
.omnibar .actions button { width: 32px; height: 32px; min-width: 32px; margin: 0; color: var(--gray5); }
.omnibar .actions button:hover { background: var(--gray1); }
.omnibar .actions button:focus-visible { background: var(--gray1); outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }
.omnibar .actions button svg { width: 18px; height: 18px; }
:root[data-theme="light"] .omnibar .actions button { color: var(--gray7); } /* light gray5 ≈ 1.9:1 on #fff */

/* ============================================================
   TEXA-ONLY: Cryptee-style note modal + toasts (Flow lacks these)
   ============================================================ */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  margin: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--gray1); color: var(--fg); }
.icon-btn[data-active="true"] { color: var(--fg); }
.icon-btn:focus-visible { box-shadow: 0 0 0 2px var(--focus-ring); outline: 0; }
.icon-btn svg { width: 16px; height: 16px; }

/* Invisible outside-click catcher — Flow never dims the canvas behind a popup;
   the page stays pure --bg while a dialog floats above it. */
.modal-scrim {
  position: fixed; inset: 0; z-index: 40;
  background: transparent;
  pointer-events: none;
}
.modal-scrim[data-open="true"] { pointer-events: auto; }
.modal {
  position: fixed; z-index: 41; top: 50%; left: 50%;
  transform: translate(-50%, -48%) scale(0.98);
  width: min(720px, 92vw);
  max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease);
}
.modal[data-open="true"] { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; }
.modal__date { font-size: 12px; color: var(--muted); }
.modal__tools { display: flex; align-items: center; gap: 2px; }
.modal__editor { flex: 1; overflow-y: auto; padding: var(--s-6) var(--s-6) var(--s-7); }
.modal__editor textarea { width: 100%; min-height: 40vh; font-size: 16px; line-height: 24px; color: var(--fg-strong); display: block; }
.modal__editor textarea::placeholder { color: var(--muted); }
.modal__foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; font-size: 12px; color: var(--muted); }
/* Status whispers "Saving…/Saved" only while writing, then fades (no permanent badge) */
#modalStatus { opacity: 0; transition: opacity var(--t-med) var(--ease); }
#modalStatus.is-shown, #modalStatus[data-saving] { opacity: 1; }

.toast-wrap { position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--surface); border: 1px solid var(--surface-border); box-shadow: var(--shadow-small); color: var(--fg); font-size: 13px; padding: 10px 16px; border-radius: 999px; animation: toast-in var(--t-med) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .main { padding-top: 60px; padding-bottom: 60px; }
  .header { padding: 24px; }
  .thought .timestamp {
    left: auto; right: 44px; top: 26px;   /* clear the 28px expand button */
    backdrop-filter: blur(8px);
    border-radius: 8px;
    padding: 8px; margin: -8px;            /* Flow's symmetric chip bleed */
  }
  .thought__expand { right: 4px; }
  .omnibar { width: min(340px, 90vw); }
  .omnibar .search { font-size: 16px; flex: 1; width: auto; }
}

/* ============================================================
   TEXA-ONLY: Settings panel (flow.rest language; reuses modal surface)
   ============================================================ */
.menu-sep { height: 1px; background: var(--hairline); margin: 6px 8px; }

.settings {
  position: fixed; z-index: 41; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(320px, 92vw);
  display: flex; flex-direction: column;
  background: var(--menu-bg);
  border-radius: 8px;
  box-shadow: var(--shadow-small);
  padding: 6px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.settings[data-open="true"] { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.settings__head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; }
.settings__title { font-size: 13px; color: var(--gray7); }
.settings__body { display: flex; flex-direction: column; }
.settings__foot { display: flex; align-items: center; justify-content: space-between; padding: 8px; font-size: 12px; color: var(--muted); }

/* Flat rows — no dividers, no boxes (flow.rest popup language) */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 32px; padding: 0 8px; border-radius: 4px; }
.set-label { font-size: 13px; color: var(--gray6); }

/* Typing choice — text only, hierarchy via color/opacity (no boxy segmented control) */
.set-choice { display: inline-flex; align-items: center; gap: 14px; }
.set-opt { width: auto; height: auto; min-width: 0; margin: 0; padding: 0; border-radius: 4px; background: transparent; font-size: 13px; color: var(--muted); }
.set-opt:hover { background: transparent; color: var(--gray7); }
.set-opt[aria-pressed="true"] { color: var(--fg); }
.set-opt:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }

/* Pair — quiet ghost action (never a heavy/bold button) */
.set-action { width: auto; height: 26px; min-width: 0; margin: 0; padding: 0 10px; border-radius: 4px; background: transparent; font-size: 13px; color: var(--gray6); }
.set-action:hover { background: var(--highlight); color: var(--fg); }
.set-action:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }

@media (max-width: 640px) {
  .settings { width: min(340px, 94vw); }
}

/* Devices — flat rows inside Settings (roster members; quiet, no boxes) */
.set-device { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 32px; padding: 0 8px; border-radius: 4px; }
.set-device__name { font-size: 13px; color: var(--gray6); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-device__name[data-self="true"] { color: var(--fg); }
.set-device__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--status-offline); flex: none; }
.set-device__dot[data-live="true"] { background: var(--status-direct); }
.set-device__empty { font-size: 13px; color: var(--muted); padding: 0 8px; height: 32px; display: flex; align-items: center; }

/* ============================================================
   TEXA-ONLY: Pairing dialog — Flow surface card (menu-bg, 8px radius,
   small shadow, thin gray1 border like the omnibar; NO scrim dim)
   ============================================================ */
.pair {
  position: fixed; z-index: 41; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(360px, 92vw);
  display: flex; flex-direction: column;
  background: var(--menu-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
  padding: 6px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.pair[data-open="true"] { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.pair__head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; }
.pair__title { font-size: 13px; color: var(--gray7); }
.pair__body { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px; }
.pair__status { min-height: 20px; font-size: 13px; color: var(--muted); text-align: center; padding: 0 8px; }
.pair__foot { display: flex; align-items: center; justify-content: space-between; padding: 8px; font-size: 12px; color: var(--muted); }

/* The QR card stays dark-on-light in BOTH themes — a code must scan off the screen */
.pair__qr { width: 192px; height: 192px; border-radius: 8px; overflow: hidden; background: #fff; }
.pair__qr svg { display: block; width: 100%; height: 100%; }

.pair__code {
  font-size: 14px; letter-spacing: 0.04em; line-height: 20px;
  color: var(--fg); text-align: center; word-break: break-all;
  user-select: all; cursor: text; padding: 0 8px;
}
.pair__hint { font-size: 12px; line-height: 18px; color: var(--muted); text-align: center; padding: 0 8px; }
.pair__error { font-size: 12px; line-height: 18px; color: var(--gray7); text-align: center; min-height: 0; }

.pair__input {
  width: 100%; min-height: 44px; text-align: center; font-size: 14px;
  color: var(--writing); caret-color: var(--fg);
  background: var(--bg); border: 1px solid var(--hairline); border-radius: var(--radius-sm); padding: 0 12px;
  letter-spacing: 0.04em;
}
.pair__input::placeholder { color: var(--muted); letter-spacing: 0; }
.pair__input:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }

.pair__actions { display: flex; align-items: center; justify-content: center; gap: 10px; }
.pair__btn {
  width: auto; min-height: 32px; min-width: 0; margin: 0; padding: 0 12px;
  border-radius: var(--radius-sm); background: transparent; font-size: 13px; color: var(--gray6);
}
.pair__btn:hover { background: var(--highlight); color: var(--fg); }
.pair__btn:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }
.pair__switch {
  width: auto; height: auto; min-width: 0; margin: 4px 0 0; padding: 4px 8px;
  border-radius: var(--radius-sm); background: transparent; font-size: 12px; color: var(--muted);
}
.pair__switch:hover { background: transparent; color: var(--gray7); }
.pair__switch:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }

/* light gray6/muted ≈ 3.1–3.5:1 on #fff — bump the quiet small text to gray7 for AA (same as .menu-item) */
:root[data-theme="light"] .pair__btn,
:root[data-theme="light"] .set-action,
:root[data-theme="light"] .set-device__name,
:root[data-theme="light"] .pair__hint,
:root[data-theme="light"] .pair__status,
:root[data-theme="light"] .pair__foot,
:root[data-theme="light"] .set-device__empty { color: var(--gray7); }

@media (max-width: 640px) {
  .pair { width: min(360px, 94vw); }
}

/* ============================================================
   TEXA-ONLY: Lock screen (passphrase unlock / setup) — calm full canvas
   ============================================================ */
.lock {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  animation: lock-in var(--t-med) var(--ease);
}
.lock[hidden] { display: none; }
.lock [hidden] { display: none; }  /* author `button{display:flex}` would otherwise beat UA [hidden] */
.lock__form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.lock__title { font-size: 16px; font-weight: 500; color: var(--fg); }
.lock__sub { font-size: 13px; line-height: 20px; color: var(--muted); margin-bottom: 4px; }
.lock__input {
  width: 100%; height: 44px; text-align: center; font-size: 16px;
  color: var(--writing); caret-color: var(--fg);
  background: var(--menu-bg); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 0 14px;
}
.lock__input::placeholder { color: var(--muted); }
.lock__input:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }
.lock__hint { min-height: 18px; font-size: 12px; color: var(--muted); }
.lock__actions { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 2px; }
.lock__submit {
  width: auto; min-height: 44px; min-width: 0; margin: 0; padding: 0 16px;
  border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--menu-bg); color: var(--fg); font-size: 13px;
}
.lock__submit:hover { background: var(--highlight); }
.lock__submit:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }
.lock__cancel {
  width: auto; min-height: 44px; min-width: 0; margin: 0; padding: 0 12px;
  border-radius: var(--radius); background: transparent; color: var(--muted); font-size: 13px;
}
.lock__cancel:hover { background: var(--highlight); color: var(--fg); }
.lock__cancel:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--focus-ring); }
@keyframes lock-in { from { opacity: 0; } to { opacity: 1; } }
.lock__form--shake { animation: lock-shake 0.3s var(--ease); }
@keyframes lock-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
  .thought textarea { transition: none; }
  .root-divider[data-loading]::after { animation: none; }
  .menu, .menu[data-closing], .toast { animation: none; }
  .highlight, .omnibar, .modal, .modal-scrim, #modalStatus,
  .logo, .menu-trigger, .header-actions,
  .settings, .pair { transition: none; }
  .lock, .lock__form--shake { animation: none; }
  .conn-dot { animation: none; transition: none; }
  button:active { transform: none; }
}
