:root {
  --bg: #0b1220;
  --bg-card: #121a2b;
  --bg-elevated: #1a2438;
  --text: #e8edf7;
  --muted: #8b9bb8;
  --accent: #22d3a6;
  --accent-dim: #148f6d;
  --danger: #f87171;
  --warn: #fbbf24;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(24px + var(--safe-b));
}

body.has-tabbar {
  padding-bottom: calc(72px + var(--safe-b));
}

.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(34, 211, 166, 0.15), transparent),
    var(--bg);
}

.shell {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 16px;
}

.app-shell {
  padding-top: 8px;
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  color: #041018;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.muted.small {
  font-size: 0.82rem;
  line-height: 1.45;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.hero-card {
  background: linear-gradient(160deg, var(--bg-elevated), var(--bg-card));
}

.card-accent {
  border-color: rgba(34, 211, 166, 0.25);
  background: linear-gradient(165deg, rgba(34, 211, 166, 0.06), var(--bg-card));
}

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.label {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 4px;
}

.balance {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.balance.account-email {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
}

.auth-grid {
  display: grid;
  gap: 12px;
}

.auth-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.auth-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.auth-head strong {
  flex: 1;
  font-size: 0.92rem;
}

.auth-icon {
  font-size: 1.1rem;
}

.kv.compact div {
  padding: 6px 0;
  font-size: 0.82rem;
}

@media (min-width: 520px) {
  .auth-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.section-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
}

.topbar .muted {
  font-size: 0.72rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

input, textarea, .select-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 14px;
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 12px;
}

.select-input {
  font-family: var(--font);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b9bb8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

input:focus, textarea:focus {
  outline: 2px solid rgba(34, 211, 166, 0.45);
  border-color: var(--accent-dim);
}

textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.35;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2dd4bf);
  color: #042f23;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  width: auto;
}

.btn-sm {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.85rem;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 400px) {
  .btn-row {
    grid-template-columns: 1fr 1fr;
  }
}

.btn-row.three-col {
  grid-template-columns: 1fr;
}

@media (min-width: 520px) {
  .btn-row.three-col {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.btn-row .btn {
  width: 100%;
}

.kv {
  margin: 0 0 14px;
  display: grid;
  gap: 8px;
}

.kv div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.kv dt, .kv dd {
  margin: 0;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  text-align: right;
  font-weight: 500;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-ok {
  background: rgba(34, 211, 166, 0.15);
  color: var(--accent);
}

.badge-warn {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
}

.badge-err {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.toast {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.toast.ok {
  background: rgba(34, 211, 166, 0.12);
  color: var(--accent);
}

.toast.err {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.hidden {
  display: none !important;
}

.muted-box {
  background: rgba(255, 255, 255, 0.02);
}

.tips {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

@media (min-width: 480px) {
  .shell {
    padding: 20px;
  }
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: rgba(11, 18, 32, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.tabbar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 6px 8px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.tabbar-btn.active {
  color: var(--accent);
  background: rgba(34, 211, 166, 0.1);
}

.tabbar-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 10px;
}

.stats-grid-4 {
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 400px) {
  .stats-grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.session-card {
  margin-bottom: 12px;
}

.session-card summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 4px 0;
}

.session-card summary::-webkit-details-marker {
  display: none;
}

.session-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0 10px;
}

.kind-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-right: 6px;
}

.kind-marathon {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.kind-single {
  background: rgba(34, 211, 166, 0.15);
  color: var(--accent);
}

.market-card {
  border-color: rgba(59, 130, 246, 0.25);
  background: linear-gradient(165deg, rgba(59, 130, 246, 0.08), var(--bg-card));
}

.market-score-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 12px 0;
}

.market-gauge {
  flex-shrink: 0;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 4px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.market-gauge.score-high {
  border-color: var(--accent);
  box-shadow: 0 0 24px rgba(34, 211, 166, 0.2);
}

.market-gauge.score-mid {
  border-color: var(--warn);
}

.market-gauge.score-low {
  border-color: var(--danger);
}

.market-score-num {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
}

.market-score-of {
  font-size: 0.7rem;
  color: var(--muted);
}

.market-label {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 4px;
}

.factor-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
}

.factor-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.market-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

.market-timeline li.timeline-good {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.market-timeline li.timeline-mid {
  border-left: 3px solid var(--warn);
  padding-left: 10px;
}

.market-timeline li.timeline-bad {
  border-left: 3px solid var(--danger);
  padding-left: 10px;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.stat-value {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.stat-value.positive {
  color: var(--accent);
}

.stat-value.negative {
  color: var(--danger);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.check-row input {
  width: auto;
  margin: 0;
}

.trade-list,
.feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.trade-list li,
.feed-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.4;
}

.trade-list li.win {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.trade-list li.loss {
  border-left: 3px solid var(--danger);
  padding-left: 10px;
}

.feed-list li .feed-time {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.feed-list li.feed-trade_start {
  color: var(--warn);
}

.feed-list li.feed-trade_result {
  font-weight: 600;
}

.services-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.service-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg);
}

.service-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.service-card-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.service-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.service-meta + .service-meta {
  margin-top: 4px;
}

.service-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.service-actions .btn {
  flex: 1;
  min-width: 72px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.health-healthy { color: var(--accent); }
.health-degraded { color: var(--warn); }
.health-unhealthy { color: var(--danger); }
.health-idle, .health-stopped { color: var(--muted); }

.badge-health-healthy { background: rgba(34, 211, 166, 0.15); color: var(--accent); }
.badge-health-degraded { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-health-unhealthy { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.badge-health-idle,
.badge-health-stopped { background: rgba(139, 155, 184, 0.12); color: var(--muted); }

.panel-load-wrap {
  position: relative;
}

.market-journal-stack .panel-load-body > .card + .card {
  margin-top: 12px;
}

.panel-load-wrap.is-loading > .panel-load-body {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}

.panel-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  background: rgba(11, 18, 32, 0.72);
  border-radius: 12px;
  text-align: center;
}

.panel-loading-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
