/* Parametric — PWA app shell (dark, mobile-first) */

:root {
  --bg: #0A0E16;
  --bg-2: #0D1220;
  --surface: #131A2A;
  --surface-2: #182133;
  --raised: #1D2739;
  --border: #232E45;
  --border-soft: rgba(255, 255, 255, .06);

  --text: #E9EDF6;
  --muted: #8A93A8;
  --dim: #5D6577;

  --accent: #7C5CFF;
  --accent-2: #22D3EE;
  --accent-soft: rgba(124, 92, 255, .14);

  --long: #16C784;
  --long-soft: rgba(22, 199, 132, .13);
  --short: #FF5A5F;
  --short-soft: rgba(255, 90, 95, .13);
  --warn: #FFB020;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-2); text-decoration: none; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ---- device frame on desktop ---- */
.device {
  max-width: 440px; margin-inline: auto; min-height: 100dvh;
  background: var(--bg); display: flex; flex-direction: column; position: relative;
}
@media (min-width: 900px) {
  body {
    padding: 26px 0;
    background: radial-gradient(900px 500px at 50% -10%, rgba(124, 92, 255, .16), transparent 70%), #05070C;
  }
  .device {
    height: min(900px, calc(100dvh - 52px));
    min-height: min(900px, calc(100dvh - 52px));
    border-radius: 30px; overflow: hidden;
    box-shadow: 0 40px 90px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .07);
  }
}

/* ---- app bar ---- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: rgba(10, 14, 22, .84);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 12px; min-height: 58px;
}
.appbar__brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.appbar__brand img { width: 30px; height: 30px; border-radius: 9px; }
.appbar__title { display: block; font-size: 1.02rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.appbar__sub { display: block; font-size: .7rem; color: var(--muted); font-weight: 500; line-height: 1.3; }
.appbar__spacer { margin-left: auto; }

.chip-rate {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .68rem; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 5px 11px; cursor: pointer;
}
.chip-rate i { width: 6px; height: 6px; border-radius: 50%; background: var(--long); }
.chip-rate.is-offline i { background: var(--dim); }

/* ---- scroll views ---- */
.view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 22px);
}
.view[hidden] { display: none; }

.sec {
  font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--dim); margin: 24px 0 10px;
}
.sec:first-child { margin-top: 2px; }

/* ---- result hero ---- */
.result {
  background:
    radial-gradient(420px 200px at 100% 0%, rgba(34, 211, 238, .14), transparent 65%),
    linear-gradient(150deg, #1B1740 0%, #121A2C 60%);
  border: 1px solid rgba(124, 92, 255, .26);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 14px;
}
.result__label {
  font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: #A99CFF; font-weight: 700;
}
.result__value {
  font-family: var(--mono); font-size: 2.35rem; font-weight: 600;
  letter-spacing: -.045em; margin: 6px 0 2px; line-height: 1;
}
.result__unit { font-size: 1rem; color: var(--muted); font-weight: 500; margin-left: 6px; }
.result__hint { font-size: .78rem; color: var(--muted); }
.result__row {
  display: flex; gap: 10px; margin-top: 16px; padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .09);
}
.result__cell { flex: 1; min-width: 0; }
.result__cell span {
  display: block; font-size: .62rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.result__cell b { font-family: var(--mono); font-size: .9rem; font-weight: 600; }

/* ---- form ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 14px;
}
.field {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--border-soft);
}
.card .field:last-child { border-bottom: none; }
.field__label { flex: 1; min-width: 0; }
.field__label b { display: block; font-size: .87rem; font-weight: 500; }
.field__label span { font-size: .7rem; color: var(--dim); }

.field input, .field select {
  width: 128px; flex: none; text-align: right;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px;
  font-family: var(--mono); font-size: .92rem; font-variant-numeric: tabular-nums;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
  -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field select { font-family: var(--font); text-align: left; width: 138px; }
.field input:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field--wide input, .field--wide select { width: 160px; }

/* segmented control */
.seg { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.seg button {
  flex: 1; background: none; border: none; cursor: pointer;
  padding: 7px 12px; border-radius: 7px; font-size: .82rem; font-weight: 600; color: var(--muted);
}
.seg button.is-on { background: var(--raised); color: var(--text); }
.seg button.is-on[data-dir="buy"] { background: var(--long-soft); color: var(--long); }
.seg button.is-on[data-dir="sell"] { background: var(--short-soft); color: var(--short); }

/* quick risk presets */
.presets { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.preset {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius-pill); padding: 7px 14px; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.preset.is-on { background: var(--accent-soft); border-color: rgba(124, 92, 255, .5); color: #BFB0FF; }

/* stat grid */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 13px;
}
.stat span { display: block; font-size: .64rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin-bottom: 3px; }
.stat b { font-family: var(--mono); font-size: 1rem; font-weight: 600; }
.stat.is-long b { color: var(--long); }
.stat.is-short b { color: var(--short); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-pill);
  padding: 13px 22px; font-size: .93rem; font-weight: 600; cursor: pointer; width: 100%;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:active { background: #6B4CE8; }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }

/* note */
.note {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: .78rem; color: var(--muted); line-height: 1.55;
}
.note strong { color: var(--text); font-weight: 600; }
.note svg { flex: none; color: var(--accent); margin-top: 1px; }

/* saved list */
.saved { display: grid; gap: 8px; }
.saved__item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px;
  display: flex; align-items: center; gap: 12px;
}
.saved__item .meta { flex: 1; min-width: 0; }
.saved__item .meta b { display: block; font-size: .88rem; }
.saved__item .meta span { font-size: .72rem; color: var(--dim); }
.saved__item .val { text-align: right; font-family: var(--mono); }
.saved__item .val b { display: block; font-size: .9rem; }
.saved__item .val span { font-size: .7rem; color: var(--muted); }
.icon-btn {
  background: none; border: none; color: var(--dim); cursor: pointer; padding: 6px; flex: none;
}
.icon-btn:active { color: var(--short); }

.empty { text-align: center; padding: 54px 24px; color: var(--dim); }
.empty svg { margin: 0 auto 14px; color: var(--border); }
.empty b { display: block; color: var(--muted); font-size: .95rem; margin-bottom: 6px; }
.empty p { font-size: .82rem; margin: 0; }

/* ---- tab bar ---- */
.tabbar {
  position: sticky; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(10, 14, 22, .93);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--border-soft);
  padding-bottom: var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b));
}
.tab {
  background: none; border: none; cursor: pointer;
  display: grid; justify-items: center; align-content: center; gap: 4px;
  font-size: .62rem; font-weight: 600; color: var(--dim); padding: 0;
}
.tab.is-active { color: var(--accent-2); }
.tab svg { width: 20px; height: 20px; }

/* ---- toast & sheet ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  transform: translate(-50%, 12px); z-index: 90;
  background: var(--raised); color: var(--text); font-size: .8rem;
  border: 1px solid var(--border);
  padding: 11px 18px; border-radius: var(--radius-pill);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100% - 40px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.sheet {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: flex-end; justify-content: center; background: rgba(3, 6, 12, .6);
}
.sheet.is-on { display: flex; }
.sheet__card {
  background: var(--bg-2); border-top: 1px solid var(--border);
  width: 100%; max-width: 440px;
  border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + var(--safe-b));
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(16px); opacity: .5 } to { transform: none; opacity: 1 } }
.sheet__card h3 { margin: 0 0 6px; font-size: 1.03rem; }
.sheet__card p { margin: 0 0 16px; font-size: .85rem; color: var(--muted); line-height: 1.55; }

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