:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f2f4f6;
  --surface-pressed: #e5e8eb;
  --text: #191f28;
  --text-soft: #4e5968;
  --muted: #8b95a1;
  --line: #e5e8eb;
  --blue: #3182f6;
  --blue-soft: #e8f2ff;
  --positive: #f04452;
  --negative: #3182f6;
  --warning: #f59f00;
  --shadow: 0 18px 44px rgba(25, 31, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

a {
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
  padding: 28px 24px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.auth-panel h1 {
  font-size: 28px;
  line-height: 1.16;
}

.lead {
  margin-top: 14px;
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.55;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 15px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 800;
  text-decoration: none;
}

.secondary-action {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--blue);
  font-size: 13px;
  font-weight: 900;
}

.notice {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 15px;
  background: #fff7e8;
  color: #b56a00;
  font-size: 13px;
}

.notice.error {
  background: #fff0f1;
  color: var(--positive);
}

.dashboard-shell {
  width: min(100%, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 12px 36px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 74px 1fr 74px;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 8px 0 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
}

.app-logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #0b5cff, #4dabff);
  box-shadow: 0 10px 26px rgba(49, 130, 246, 0.22);
}

.app-logo::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 999px 999px 999px 3px;
  background: #ffffff;
  opacity: 0.82;
  transform: rotate(-35deg);
}

.app-tabs {
  display: flex;
  justify-content: center;
  justify-self: center;
  width: fit-content;
  max-width: 100%;
  gap: 6px;
  min-width: 0;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-pressed);
  overflow-x: auto;
  scrollbar-width: none;
}

.app-tabs::-webkit-scrollbar {
  display: none;
}

.app-tab,
.logout-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.app-tab {
  flex: 0 0 auto;
  min-width: 58px;
  padding: 0 12px;
  background: transparent;
  white-space: nowrap;
}

.app-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(25, 31, 40, 0.08);
}

.logout-link {
  width: 74px;
  background: var(--surface);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.account-picker {
  min-width: 0;
  min-height: 46px;
  padding: 0 12px 0 4px;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font-size: 23px;
  font-weight: 900;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-picker::after {
  content: "⌄";
  margin-left: 5px;
  color: var(--text-soft);
  font-size: 18px;
}

.segmented-control {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  border-radius: 15px;
  background: var(--surface-pressed);
}

.segmented-control button {
  min-width: 42px;
  min-height: 36px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.segmented-control button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 8px rgba(25, 31, 40, 0.08);
}

.segmented-control.small button {
  min-width: 54px;
  min-height: 32px;
  font-size: 13px;
}

.cash-card,
.portfolio-card,
.holdings-section,
.account-drawer,
.market-lookup-panel,
.order-ticket,
.candidate-summary,
.candidate-card,
.strategy-card,
.trade-journal-panel,
.trade-journal-card {
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(25, 31, 40, 0.05);
}

.cash-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  margin-top: 12px;
  overflow: hidden;
  background: var(--line);
}

.cash-card div {
  min-width: 0;
  padding: 18px;
  background: var(--surface);
}

.cash-card span,
.profit-stack span,
.page-title span,
.candidate-summary span,
.strategy-card > span,
.trade-journal-head span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.cash-card strong {
  display: block;
  margin-top: 7px;
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.portfolio-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  margin-top: 12px;
  padding: 14px;
}

.allocation-bars {
  min-width: 0;
  min-height: 176px;
  display: grid;
  align-items: center;
}

.allocation-chart {
  min-width: 0;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.allocation-donut {
  position: relative;
  width: min(100%, 160px);
  max-width: 160px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--blue) 0% 100%);
}

.allocation-donut::after {
  content: "";
  position: absolute;
  width: 64%;
  aspect-ratio: 1;
  border-radius: inherit;
  background: var(--surface);
}

.allocation-donut-center {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 3px;
  justify-items: center;
  max-width: 74%;
  text-align: center;
}

.allocation-donut-center strong {
  max-width: 100%;
  color: var(--text);
  font-size: 15px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.allocation-donut-center span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.allocation-legend {
  width: 100%;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.allocation-legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.allocation-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.allocation-label {
  min-width: 0;
}

.allocation-label strong,
.allocation-label span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.allocation-label strong {
  font-size: 13px;
}

.allocation-label span,
.allocation-empty {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.allocation-percent {
  color: var(--text-soft);
  font-size: 12px;
}

.profit-stack {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.profit-stack article {
  min-width: 0;
  display: grid;
  align-content: center;
  padding: 16px;
  border-radius: 20px;
  background: var(--surface-soft);
}

.profit-stack strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.profit-stack small {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  font-weight: 900;
}

[data-tone="up"] {
  color: var(--positive) !important;
}

[data-tone="down"] {
  color: var(--negative) !important;
}

.holdings-section,
.account-drawer,
.trade-journal-panel {
  margin-top: 14px;
  padding: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-title.compact h1 {
  font-size: 23px;
  line-height: 1.15;
}

.section-title.compact h2 {
  font-size: 18px;
  line-height: 1.2;
}

.section-title p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.section-title strong {
  color: var(--text-soft);
  font-size: 15px;
}

.state {
  min-height: 21px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.state[data-kind="ok"] {
  color: #20a67a;
}

.state[data-kind="error"] {
  color: var(--positive);
}

.state[data-kind="empty"] {
  color: var(--warning);
}

.holdings-list,
.account-list,
.order-risk-list,
.candidate-list,
.trade-journal-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.holding-card {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.holding-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.holding-info,
.holding-value {
  min-width: 0;
}

.holding-info strong,
.holding-value strong {
  display: block;
  overflow-wrap: anywhere;
}

.holding-info strong {
  font-size: 22px;
  line-height: 1.05;
}

.holding-info span,
.holding-info small,
.holding-value span,
.candidate-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.holding-value {
  text-align: right;
}

.holding-value strong {
  font-size: 22px;
  line-height: 1.05;
}

.account-button {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 13px 14px;
  border-radius: 17px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
}

.account-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.account-button strong {
  color: var(--blue);
  font-size: 12px;
}

.account-button[aria-pressed="true"] {
  background: var(--blue-soft);
}

.page-title {
  margin: 18px 0 12px;
}

.page-title.action-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.page-title.action-title .secondary-action {
  flex: 0 0 auto;
  margin-top: 0;
}

.page-title h1 {
  margin-top: 4px;
  font-size: 27px;
  line-height: 1.16;
}

.backtest-view-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.backtest-view-tabs button {
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 900;
}

.backtest-view-tabs button.is-active { background: var(--surface); color: var(--text); }
.backtest-view-tabs button:focus-visible { outline: 3px solid rgba(49, 130, 246, 0.25); }
.backtest-view-panel { min-width: 0; }
.backtest-view-panel[hidden] { display: none; }

.paper-runtime-role,
.paper-activation-state {
  display: inline-flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: 5px;
  background: #edf3fa;
  color: #365b7d;
  font-size: 11px;
  font-weight: 900;
}

.paper-runtime-role[data-runtime-role="ENTRY_ALLOWED"],
.paper-activation-state[data-activation-state="ACTIVE"] { background: #e8f6f0; color: #087a5b; }
.paper-runtime-role[data-runtime-role="LIQUIDATION_ONLY"] { background: #fff7e8; color: #a35f00; }
.paper-runtime-role[data-runtime-role="BLOCKED_HISTORY"] { background: #f0f2f5; color: var(--muted); }
.paper-activation-state[data-activation-state="DRAINING"] { background: #fff4e5; color: #9b5a00; }
.paper-activation-state[data-activation-state="RETIRED"] { background: #eceff3; color: #59636e; }

@media (max-width: 430px) {
  .backtest-view-tabs button {
    min-height: 44px;
    padding: 0 3px;
    font-size: 11px;
  }
}
