/* =========================================================
   AUTO TRED AI — Theme, frame, and component styles
   ========================================================= */

:root[data-theme="dark"] {
  --bg: #020712;
  --bg-secondary: #061426;
  --card: #071a31;
  --card-secondary: #09213b;
  --primary: #087cf0;
  --bright: #00a8ff;
  --green: #20d65a;
  --red: #f04444;
  --gold: #ffc928;
  --text: #ffffff;
  --text-secondary: #91a4bd;
  --border: rgba(8, 124, 240, 0.28);
  --border-soft: rgba(145, 164, 189, 0.12);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --input-bg: #061426;
  --overlay: rgba(1, 4, 10, 0.72);
  --nav-bg: #06101e;
  --glow: rgba(8, 124, 240, 0.18);
  --success-bg: rgba(32, 214, 90, 0.12);
  --danger-bg: rgba(240, 68, 68, 0.12);
  --gold-bg: rgba(255, 201, 40, 0.12);
  --chart-grid: rgba(145, 164, 189, 0.1);
  --focus: #00a8ff;
  --desktop-bg: #010409;
}

:root[data-theme="light"] {
  --bg: #f3f6fb;
  --bg-secondary: #ffffff;
  --card: #ffffff;
  --card-secondary: #eef3f9;
  --primary: #087cf0;
  --bright: #0077cc;
  --green: #0ea548;
  --red: #d92d20;
  --gold: #c99000;
  --text: #0b1220;
  --text-secondary: #5b6b80;
  --border: rgba(8, 124, 240, 0.18);
  --border-soft: rgba(11, 18, 32, 0.08);
  --shadow: 0 10px 24px rgba(15, 35, 70, 0.08);
  --input-bg: #f7f9fc;
  --overlay: rgba(11, 18, 32, 0.45);
  --nav-bg: #ffffff;
  --glow: rgba(8, 124, 240, 0.08);
  --success-bg: rgba(14, 165, 72, 0.1);
  --danger-bg: rgba(217, 45, 32, 0.08);
  --gold-bg: rgba(201, 144, 0, 0.1);
  --chart-grid: rgba(91, 107, 128, 0.12);
  --focus: #087cf0;
  --desktop-bg: #0b1220;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}

body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  background: var(--desktop-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Desktop: centered mobile frame */
.app-shell {
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100%;
  min-height: 100vh;
  overflow: hidden;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: var(--desktop-bg);
}

.app-frame {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 481px) {
  .app-shell {
    padding: 16px 0;
    align-items: center;
  }

  .app-frame {
    min-height: calc(100vh - 32px);
    min-height: calc(100dvh - 32px);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(8, 124, 240, 0.15);
  }
}

@media (max-width: 480px) {
  .app-shell {
    height: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    padding: 0;
  }
  .app-frame {
    max-width: 100%;
    box-shadow: none;
    border-radius: 0;
    height: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
  }
}

.page {
  display: flex;
  flex: 1 1 0%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.screen-scroll {
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

.screen-scroll.auth-scroll {
  padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: transparent;
  transition: background 0.2s ease, color 0.2s ease;
}

.icon-btn:hover {
  background: var(--card-secondary);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.card-soft {
  background: var(--card-secondary);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
}

.balance-card {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(0, 168, 255, 0.22), transparent 46%),
    linear-gradient(135deg, #0a2a52 0%, #071a31 58%, #061426 100%);
  border: 1px solid rgba(0, 168, 255, 0.28);
}

[data-theme="light"] .balance-card {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(8, 124, 240, 0.16), transparent 48%),
    linear-gradient(135deg, #e8f3ff 0%, #ffffff 55%, #f3f8ff 100%);
}

.muted {
  color: var(--text-secondary);
}

.profit {
  color: var(--green);
}

.loss {
  color: var(--red);
}

.gold {
  color: var(--gold);
}

.field {
  position: relative;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.field-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.field-control:focus-within {
  border-color: var(--bright);
  box-shadow: 0 0 0 3px var(--glow);
}

.field-control input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 12px 0;
  outline: none;
}

#ap1, #ap2, #ap3 {
  flex: 1;
  display: flex;
  width: 100%;
}

.field-control input[type="checkbox"] {
  flex: 0 0 auto;
  width: auto;
  cursor: pointer;
  margin-right: 8px;
}

.field-control svg {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.field-error {
  min-height: 18px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--red);
}

.btn {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s ease;
}

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

.btn-primary {
  width: 100%;
  color: #fff;
  background: linear-gradient(180deg, #1a93ff 0%, #087cf0 100%);
  box-shadow: 0 8px 18px rgba(8, 124, 240, 0.28);
}

.btn-outline {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--primary);
  background: transparent;
}

.btn-danger {
  color: #fff;
  background: var(--red);
}

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

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 64px;
  background: none;
  text-decoration: none;
}

a.list-row {
  width: 100%;
  text-decoration: none;
  color: inherit;
}

.quick-action .quick-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.quick-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.quick-icon svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
  fill: none;
}

.progress-ring svg {
  width: 22px;
  height: 22px;
}

.progress-ring > svg {
  width: 100%;
  height: 100%;
}

.tabs {
  display: flex;
  padding: 4px;
  background: var(--card-secondary);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 6px;
}

.tab-btn.is-active {
  background: linear-gradient(180deg, #1a93ff 0%, #087cf0 100%);
  color: #fff;
}

.bottom-nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--nav-bg);
  border-top: 1px solid var(--border-soft);
  z-index: 30;
}

.nav-item {
  flex: 1;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

.nav-item.is-active {
  color: var(--bright);
}

.side-menu {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(82%, 300px);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 50;
  transform: translateX(-105%);
  transition: transform 0.28s ease, visibility 0.28s ease;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(20px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  visibility: hidden;
  pointer-events: none;
}

.side-menu.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.drawer-group {
  border-bottom: 1px solid var(--border-soft);
}

.drawer-parent {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 0;
}

.drawer-parent .chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.drawer-group.is-open .drawer-parent .chevron {
  transform: rotate(90deg);
}

.drawer-sub {
  display: none;
  padding: 0 0 10px 8px;
}

.drawer-group.is-open .drawer-sub {
  display: block;
}

.drawer-sub a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.drawer-sub a.is-active,
.drawer-sub a:hover {
  color: var(--bright);
  background: var(--card);
}

.list-row svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 40;
}

.backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-root {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.modal-root.is-open {
  display: flex;
}

.modal-card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: modal-up 0.24s ease;
}

@keyframes modal-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top, 0px));
  z-index: 90;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: none;
}

.toast.is-visible {
  display: block;
  animation: modal-up 0.2s ease;
}

.chart-box {
  width: 100%;
  height: 120px;
  position: relative;
}

.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

.candle-box {
  width: 100%;
  height: 230px;
}

.progress-ring {
  width: 84px;
  height: 84px;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}

.list-row:last-child {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.status-pill.success {
  background: var(--success-bg);
  color: var(--green);
}

.status-pill.danger {
  background: var(--danger-bg);
  color: var(--red);
}

.status-pill.live {
  background: var(--danger-bg);
  color: var(--red);
}

.timeframe-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tf-btn {
  min-width: 44px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--card-secondary);
}

.tf-btn.is-active {
  background: var(--primary);
  color: #fff;
}

.hero-visual {
  position: relative;
  height: auto;
  border-radius: 20px;
  overflow: hidden;
  background: transparent;
  border: 0;
}

.hero-visual img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.logo-wrap img {
  width: 112px;
  height: 112px;
  object-fit: contain;
  border-radius: 50%;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
