/* AI Trading Desk — mobile-first dark UI.
   Layout targets a phone in the hand; it scales up to tablet/desktop. */

:root {
  --bg: #0a0e16;
  --surface: #121826;
  --surface-2: #1a2233;
  --border: #26314a;
  --text: #e8edf7;
  --muted: #8b97b0;
  --green: #22c55e;
  --green-dim: #14532d;
  --red: #ef4444;
  --red-dim: #4c1d1d;
  --blue: #38bdf8;
  --amber: #f59e0b;
  --radius: 14px;
  --tabbar-h: 62px;

  /* Safe areas for notched phones */
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over any component display rule.
   Without this, `.backdrop { display: flex }` keeps the invisible confirm
   overlay on top of the page and swallows every tap. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select { font-family: inherit; font-size: 16px; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: 14px; }

/* ---------------- Login ---------------- */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px calc(16px + env(safe-area-inset-left)) 24px calc(16px + env(safe-area-inset-right));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-logo { border-radius: 14px; margin: 0 auto 10px; display: block; }
.login-card h1 { font-size: 22px; text-align: center; }
.login-card > p { text-align: center; margin: 0 0 14px; font-size: 14px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 13px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--blue); }
.login-card .btn { margin-top: 18px; }

/* ---------------- App bar ---------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--sa-top)) 14px 10px;
  background: rgba(10, 14, 22, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar-logo { border-radius: 8px; flex: none; }
.appbar-title { font-weight: 650; font-size: 15px; }
.appbar-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-sim { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot-idle { background: var(--muted); }
.dot-off { background: var(--red); box-shadow: 0 0 8px var(--red); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
}
.icon-btn:active { background: var(--surface-2); }

.menu {
  position: fixed;
  top: calc(56px + var(--sa-top));
  right: 12px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-width: 232px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  cursor: pointer;
  font-size: 15px;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--surface-2); }
.menu-item.danger { color: var(--red); }

/* ---------------- Layout ---------------- */
main {
  padding: 14px calc(14px + env(safe-area-inset-left)) calc(var(--tabbar-h) + 20px + var(--sa-bottom)) calc(14px + env(safe-area-inset-right));
  max-width: 900px;
  margin: 0 auto;
}
.tab { display: none; }
.tab.active { display: block; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.block { margin-top: 22px; }
.block-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------------- Proposal card ---------------- */
.proposal {
  border-width: 2px;
  position: relative;
  overflow: hidden;
}
.proposal.buy { border-color: rgba(34, 197, 94, 0.55); }
.proposal.sell { border-color: rgba(239, 68, 68, 0.55); }

.prop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.prop-symbol { font-size: 21px; font-weight: 700; letter-spacing: 0.01em; }
.prop-side {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  padding: 4px 10px; border-radius: 999px; text-transform: uppercase;
}
.prop-side.buy { background: var(--green-dim); color: var(--green); }
.prop-side.sell { background: var(--red-dim); color: var(--red); }

.prop-headline { margin: 10px 0 12px; font-size: 15px; }

.prop-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.prop-cell { background: var(--surface-2); border-radius: 10px; padding: 9px 10px; }
.prop-cell .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.prop-cell .v { font-size: 15px; font-weight: 640; font-variant-numeric: tabular-nums; margin-top: 2px; }
.v.stop { color: var(--red); }
.v.target { color: var(--green); }

.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 4px 0 2px; }
.meter > i { display: block; height: 100%; background: var(--blue); border-radius: 999px; }

details.prop-more { margin-bottom: 12px; }
details.prop-more > summary {
  cursor: pointer; color: var(--blue); font-size: 14px; padding: 6px 0; list-style: none;
}
details.prop-more > summary::-webkit-details-marker { display: none; }
details.prop-more > summary::before { content: "▸ "; }
details.prop-more[open] > summary::before { content: "▾ "; }
.prop-detail { font-size: 14px; color: var(--muted); }
.prop-detail p { margin: 8px 0; }
.prop-detail ul { margin: 6px 0; padding-left: 20px; }

.expiry { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.expiry.urgent { color: var(--amber); font-weight: 600; }

/* Big decision buttons — sized for a thumb. */
.decide { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  border: none; border-radius: 12px; padding: 15px 16px;
  font-weight: 700; font-size: 16px; cursor: pointer; color: #fff;
  min-height: 52px; touch-action: manipulation;
  transition: transform 0.06s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-block { width: 100%; }
.btn-yes { background: var(--green); }
.btn-no { background: var(--red); }
.btn-primary { background: var(--blue); color: #04121c; }
.btn-ghost { background: var(--surface-2); color: var(--text); }

/* ---------------- History / rows ---------------- */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.row-main { min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-right { text-align: right; flex: none; font-variant-numeric: tabular-nums; }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.pill-executed { background: var(--green-dim); color: var(--green); }
.pill-approved { background: #0c3a52; color: var(--blue); }
.pill-rejected { background: var(--surface-2); color: var(--muted); }
.pill-expired  { background: var(--surface-2); color: var(--muted); }
.pill-failed   { background: var(--red-dim); color: var(--red); }
.pill-pending  { background: #3f2d06; color: var(--amber); }

.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------------- Chart ---------------- */
.chart-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; flex: 1; min-height: 44px;
}
.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  background: transparent; border: none; color: var(--muted);
  padding: 10px 14px; cursor: pointer; min-height: 44px; font-size: 14px;
}
.seg button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.price-strip { display: flex; gap: 14px; align-items: baseline; margin-bottom: 8px; flex-wrap: wrap; }
.price-strip .px { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-strip .chg { font-size: 14px; font-variant-numeric: tabular-nums; }

.chart-container {
  height: 46vh;
  min-height: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chart-legend, .levels-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 12px; color: var(--muted); margin-top: 8px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.swatch { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---------------- Banner ---------------- */
.banner {
  margin: 10px 14px 0;
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 13px;
  border: 1px solid;
  display: flex; gap: 9px; align-items: flex-start;
}
.banner-warn { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.4); color: #fcd34d; }
.banner-info { background: rgba(56, 189, 248, 0.1); border-color: rgba(56, 189, 248, 0.35); color: #7dd3fc; }

/* ---------------- Tab bar ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(10, 14, 22, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--sa-bottom);
}
.tabbtn {
  position: relative;
  background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 9px 4px; height: var(--tabbar-h); cursor: pointer; font-size: 11px;
}
.tabbtn.active { color: var(--blue); }
.tabicon { font-size: 17px; line-height: 1; }
.badge {
  position: absolute; top: 6px; right: 22%;
  background: var(--red); color: #fff;
  min-width: 18px; height: 18px; border-radius: 999px;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; padding: 0 5px;
}

/* ---------------- Sheet / toast ---------------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 22px 18px calc(22px + var(--sa-bottom));
  width: 100%; max-width: 520px;
}
.sheet h2 { font-size: 18px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 18px + var(--sa-bottom));
  z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px; border-radius: 999px; font-size: 14px;
  max-width: 90vw; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.toast.err { border-color: var(--red); color: #fca5a5; }

/* ---------------- Larger screens ---------------- */
@media (min-width: 720px) {
  .chart-container { height: 52vh; }
  .prop-grid { grid-template-columns: repeat(6, 1fr); }
  main { padding-bottom: 28px; }
  .tabbar {
    position: sticky; top: 0; bottom: auto;
    grid-template-columns: repeat(4, minmax(0, 160px));
    justify-content: center;
    border-top: none; border-bottom: 1px solid var(--border);
  }
  .toast { bottom: 24px; }
}

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