/* ── Variables — Zaura "Quiet Edge" system, shared with the sibling apps ── */
:root {
  --bg:          #141614;
  --bg2:         #1c1f1d;
  --bg3:         #242724;
  --g-dark:      #1a4a30;
  --g-mid:       #2d7a4f;
  --g-bright:    #4caf7d;
  --g-vivid:     #5fcf90;
  --g-faint:     rgba(45,122,79,0.10);
  --g-glow:      rgba(45,122,79,0.22);
  --g-border:    rgba(45,122,79,0.18);
  --gold:        #c9a227;
  --gold-bright: #f0c040;
  --gold-faint:  rgba(201,162,39,0.12);
  --red:         #c0392b;
  --red-bright:  #e74c3c;
  --red-faint:   rgba(192,57,43,0.12);
  --red-border:  rgba(192,57,43,0.28);
  --text:        #e8e4d8;
  --text-dim:    #7a8a7e;
  --text-mute:   #3a4a3e;
  --font-disp:   "Playfair Display", Georgia, serif;
  --font-mono:   "DM Mono", "Fira Mono", monospace;
  --radius:      8px;
  --radius-lg:   14px;
  --transition:  0.22s ease;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; }
:focus-visible {
  outline: 2px solid var(--g-bright);
  outline-offset: 2px;
}

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--g-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--g-mid); }

/* ── Noise texture ──────────────────────────────────────────────── */
.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 2rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, #2d7a4f 0%, #1a5c38 100%);
  color: #fff;
  font-size: 0.88rem;
  letter-spacing: 0.1em;
  box-shadow: 0 0 24px rgba(45,122,79,0.5), 0 4px 14px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.08);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4caf7d 0%, #2d7a4f 100%);
  box-shadow: 0 0 42px rgba(76,175,125,0.7), 0 6px 20px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transform: translateY(-2px);
}
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(122,138,126,0.25);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  padding: 0.85rem 1.5rem;
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--g-mid);
  background: var(--g-faint);
}

/* ───────────────────────────────────────────────────────────────── */
/*  LOGIN PAGE                                                        */
/* ───────────────────────────────────────────────────────────────── */
.login-page {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e1210;
  padding: 2rem 1rem;
}

.login-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(20,40,28,0.85) 0%, transparent 70%),
    linear-gradient(135deg, #0a100d 0%, #0e1210 50%, #080f0a 100%);
}

.login-stack {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  width: 100%;
  max-width: 420px;
}

.login-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--g-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 0 60px rgba(45,122,79,0.12), 0 24px 48px rgba(0,0,0,0.55);
  animation: fadeUp 0.35s ease both;
  overflow: hidden;
}
/* Signature surface detail: a hairline of light along the top edge of every
   card — the one recurring motif this system uses instead of drop shadows
   to say "this surface matters". */
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(76,175,125,0.55), transparent);
}

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

.login-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo-img {
  height: 96px;
  width: auto;
  pointer-events: none;
  filter: drop-shadow(0 4px 24px rgba(0,0,0,0.5));
}

.login-header { margin-bottom: 1.75rem; }
.login-title {
  font-family: var(--font-disp);
  font-size: 1.65rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.login-sub {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--text-mute);
  text-transform: uppercase;
}

.login-footnote {
  margin-top: 1.5rem;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-mute);
}

/* ── Form elements ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-mute);
  margin-bottom: 0.45rem;
  text-transform: uppercase;
}
.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--g-border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.7rem 1rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
  border-color: var(--g-mid);
  box-shadow: 0 0 0 3px rgba(45,122,79,0.12);
}
.form-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Errors ─────────────────────────────────────────────────────── */
.modal-error {
  background: rgba(200,50,50,0.10);
  border: 1px solid rgba(200,50,50,0.28);
  color: #e88;
  font-size: 0.82rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.modal-error[hidden] { display: none; }

/* ───────────────────────────────────────────────────────────────── */
/*  APP SHELL — mobile-first: every flow here must work one-handed    */
/*  on a phone, so the shell is a single column, top bar first.       */
/* ───────────────────────────────────────────────────────────────── */
.shell {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 70% 40% at 50% 0%, rgba(45,122,79,0.08) 0%, transparent 60%),
    #0d1210;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  padding-top: max(0.85rem, env(safe-area-inset-top));
  background: rgba(20,24,21,0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--g-border);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.topbar-logo { height: 26px; width: auto; flex-shrink: 0; }
.topbar-title {
  font-family: var(--font-disp);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.operator-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--g-faint);
  border: 1px solid var(--g-border);
  border-radius: 20px;
  padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  max-width: 40vw;
}
.operator-email {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* The one moving element in the shell: a slow heartbeat, not a rave —
   signals "this instrument is live and signed in", nothing more. */
.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--g-bright);
  box-shadow: 0 0 6px rgba(76,175,125,0.9);
  flex-shrink: 0;
  animation: pulseDot 2.6s ease-in-out infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(76,175,125,0.9); }
  50%      { opacity: 0.55; box-shadow: 0 0 2px rgba(76,175,125,0.4); }
}

.topbar-signout {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid rgba(122,138,126,0.25);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  transition: all var(--transition);
  white-space: nowrap;
}
.topbar-signout:hover {
  color: var(--text);
  border-color: var(--g-mid);
  background: var(--g-faint);
}

/* ── Console main ───────────────────────────────────────────────── */
.console-main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 2.25rem 1.1rem 3rem;
  display: flex;
  flex-direction: column;
}

.console-kicker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 1.1rem;
}
.kicker-line {
  height: 1px;
  width: 28px;
  background: linear-gradient(90deg, var(--g-mid), transparent);
  flex-shrink: 0;
}

/* ── Price card (Phase 2 — live XAUUSD feed) ──────────────────────── */
.price-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--g-border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.4rem;
  margin-bottom: 1.1rem;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.price-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(76,175,125,0.55), transparent);
}
.price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.price-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.price-symbol {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.price-feed-tag {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--g-bright);
}
.price-value {
  font-family: var(--font-disp);
  font-size: 1.9rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Tick pulse: a quiet fade confirming a fresh fetch landed, played on every
   successful burst tick regardless of whether the price itself moved — see
   BACKLOG.md "Live price does not visibly update every 4s". Without this,
   a run of identical/near-identical vendor prices (a quiet market) looked
   indistinguishable from a dead feed even though `/api/price` was returning
   200s the whole time. */
@keyframes price-tick-flash {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}
.price-value.is-ticking {
  animation: price-tick-flash 450ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .price-value.is-ticking { animation: none; }
}

/* Stale/unreachable feed: this app must never let a dead feed look "live"
   (PLAN.md §3.8 — order entry that depends on price must be blockable). */
.price-card[data-state="stale"] {
  border-color: var(--red-border);
  box-shadow: 0 12px 28px rgba(0,0,0,0.35), 0 0 0 1px rgba(192,57,43,0.12);
}
.price-card[data-state="stale"] .price-feed-tag { color: var(--red-bright); }
.price-card[data-state="stale"] .price-value { color: var(--text-dim); }
.price-card[data-state="loading"] .price-feed-tag { color: var(--text-mute); }
.price-card[data-state="idle"] .price-feed-tag { color: var(--text-mute); }
.price-card[data-state="idle"] .price-value { color: var(--text-dim); }

.price-burst-btn {
  margin-top: 0.9rem;
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--g-border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: all var(--transition);
}
.price-burst-btn:hover {
  border-color: var(--g-mid);
  background: var(--g-faint);
}
.price-burst-note {
  margin-top: 0.6rem;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-mute);
}

.idle-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--g-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.75rem;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 20px 44px rgba(0,0,0,0.4);
}
.idle-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(76,175,125,0.55), transparent);
}

.idle-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--g-faint);
  border: 1px solid var(--g-border);
  color: var(--g-bright);
  margin-bottom: 1.25rem;
}
.idle-icon-wrap svg { width: 28px; height: 28px; }

.idle-title {
  font-family: var(--font-disp);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}
.idle-body {
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--text-dim);
  max-width: 46ch;
  margin: 0 auto;
}

.idle-meta {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(45,122,79,0.14);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.meta-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.meta-value {
  font-size: 0.82rem;
  color: var(--g-bright);
  word-break: break-all;
}

/* ── Trade entry form (Phase 3) ────────────────────────────────── */
.trade-form-card,
.confirm-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--g-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.4rem 1.75rem;
  overflow: hidden;
  box-shadow: 0 20px 44px rgba(0,0,0,0.4);
}
.trade-form-card::before,
.confirm-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(76,175,125,0.55), transparent);
}
.form-title {
  font-family: var(--font-disp);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.1rem;
}

.side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.side-btn {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.9rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--g-border);
  background: var(--bg3);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
.side-buy.side-btn-active {
  background: var(--g-faint);
  border-color: var(--g-mid);
  color: var(--g-vivid);
  box-shadow: inset 0 0 0 1px var(--g-mid);
}
.side-sell.side-btn-active {
  background: var(--red-faint);
  border-color: var(--red-border);
  color: var(--red-bright);
  box-shadow: inset 0 0 0 1px var(--red);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
.field-optional { color: var(--text-mute); text-transform: none; letter-spacing: 0; }
.field-note {
  margin-top: 0.4rem;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-mute);
}
.form-error {
  background: rgba(200,50,50,0.10);
  border: 1px solid rgba(200,50,50,0.28);
  color: #e88;
  font-size: 0.82rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.form-error[hidden] { display: none; }

/* Reuse the idle-card's dl/dt/dd pattern for any "here's the current trade"
   summary — active-trade guard, confirm step, and post-open success all
   render the same shape. */
.active-trade-facts {
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid rgba(45,122,79,0.14);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  text-align: left;
}
.active-trade-facts dt { font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-mute); }
.active-trade-facts dd { font-size: 0.82rem; color: var(--g-bright); word-break: break-all; margin-top: 0.15rem; }

.confirm-warning { margin-bottom: 0.25rem; color: var(--gold-bright); }
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ── Manage-an-open-trade actions (Phase 4) ───────────────────────── */
.manage-actions {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(45,122,79,0.14);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.manage-action-btn { font-size: 0.72rem; padding: 0.7rem 0.5rem; }
.manage-subform {
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid rgba(45,122,79,0.14);
  text-align: left;
}
.manage-field[hidden] { display: none; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--g-mid); width: 16px; height: 16px; }

/* Full close sits alone on its own row — visually set apart as the one
   management action that ends the trade rather than adjusting it. */
.manage-action-danger {
  grid-column: 1 / -1;
  border-color: var(--red-border);
  color: var(--red-bright);
}
.manage-action-danger:hover {
  background: var(--red-faint);
  border-color: var(--red);
}

/* ── Trade history (Phase 5) — read-only audit list ────────────────── */
.history-card { text-align: left; }
.history-card .idle-title,
.history-card .idle-body { text-align: center; }
.history-list {
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid rgba(45,122,79,0.14);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.history-entry {
  background: var(--bg3);
  border: 1px solid var(--g-border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.history-entry summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
  list-style: none;
}
.history-entry summary::-webkit-details-marker { display: none; }
.history-entry summary::before {
  content: "▸ ";
  color: var(--g-bright);
}
.history-entry[open] summary::before { content: "▾ "; }
.history-timeline {
  margin-top: 0.7rem;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-dim);
  word-break: break-word;
}
.history-card .btn-full { margin-top: 1.5rem; }

/* ── Footer ─────────────────────────────────────────────────────── */
.console-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
  font-size: 0.65rem;
  color: var(--text-mute);
}
.footer-divider { opacity: 0.5; }

/* ── Small screens — tighten up further ────────────────────────── */
@media (max-width: 420px) {
  .topbar-title { font-size: 0.95rem; }
  .operator-chip { max-width: 34vw; }
  .idle-card { padding: 2rem 1.25rem; }
}
