:root {
  --bg: #0b0f14;
  --card: #121824;
  --text: #e7eefc;
  --muted: #9fb0cc;
  --line: rgba(255,255,255,0.10);
  --primary: #4ea1ff;
  --danger: #ff5a73;

  /* 컨트롤 공통 */
  --ctrl-h: 44px;
  --ctrl-r: 14px;
  --ctrl-pad-x: 16px;

  /* OK 배지 */
  --ok-h: 34px;
  --ok-pad-x: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar{
  position: sticky;
  top: 0;
  background: rgba(11,15,20,0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  z-index: 10;
}
.brand{ font-weight: 700; letter-spacing: -0.2px; }

.container{
  max-width: 820px;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.card{
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.h2{
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--text);
}

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

.field span{
  display:block;
  font-size:12px;
  color: var(--muted);
  margin-bottom: 6px;
}

/* iOS 입력 포커스 자동 확대 방지 */
.field input,
.weightRow select,
.weightRow input,
.weightRowFixed input{
  font-size: 16px;
}

.field input{
  width:100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

/* 공통 row */
.row{
  display:flex;
  gap: 10px;
  margin: 12px 0 8px;
}

.row-space{
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

/* 버튼 */
.btn{
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  cursor:pointer;
}
.btn-primary{ background: var(--primary); color: #06101f; border-color: transparent; }
.btn:disabled{ opacity: 0.5; cursor: not-allowed; }

/* 실행 버튼 높이 통일 */
#runBtn{
  height: var(--ctrl-h);
  padding: 0 var(--ctrl-pad-x);
  border-radius: var(--ctrl-r);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 0 0 auto;
}

/* 실행 버튼 + OK + 에러 */
.run-box{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap; /* ✅ OK가 아래로 떨어지는 것 최대한 방지 */
}

/* OK 배지(작게) */
.ok-badge{
  display: none;
  height: var(--ok-h);
  padding: 0 var(--ok-pad-x);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(46, 204, 113, 0.18);
  color: #d8ffe9;
  white-space: nowrap;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
}

/* 에러 */
.error{
  color: var(--danger);
  font-size: 12px;
  white-space: pre-line;
  line-height: 1.2;
}

/* 리밸런싱 카드(포트폴리오 추천 느낌으로) */
.rebalanceCard{
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
}
.rebalanceTitle{
  font-size: 12px;
  opacity: 0.85;
  margin: 0 0 8px 2px;
}

/* 드롭다운(✅ 여기서 “추가 박스” 느낌 제거: dd는 포지셔닝만) */
.dd{ position:relative; max-width:320px; }

.ddBtn{
  width:100%;
  height: var(--ctrl-h);
  padding: 0 var(--ctrl-pad-x);
  border-radius: var(--ctrl-r);

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;

  border:1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color:#fff;

  cursor:pointer;
  white-space: nowrap;
}
.ddBtn:hover{ background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.22); }
.ddBtn:focus{ outline:none; box-shadow: 0 0 0 3px rgba(80,140,255,0.25); }

.ddText{
  display:inline-block;
  overflow:hidden;
  text-overflow: ellipsis;
  max-width: 260px;
  font-size: 14px;
  opacity: .95;
}

.ddChevron{
  width:10px; height:10px;
  transform: rotate(45deg);
  border-right:2px solid rgba(255,255,255,0.8);
  border-bottom:2px solid rgba(255,255,255,0.8);
  opacity:.9;
  flex: 0 0 auto;
}

/* 메뉴 */
.ddMenu{
  position:absolute;
  left:0; right:0;
  top: calc(var(--ctrl-h) + 10px);
  padding:8px;

  border-radius:14px;
  background: rgba(16,20,28,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 40px rgba(0,0,0,0.45);

  display:none;
  z-index:50;
}
.dd.is-open .ddMenu{ display:block; }

.ddItem{
  width:100%;
  text-align:left;
  padding:10px 12px;
  border-radius:12px;
  border:0;
  background: transparent;
  color: rgba(255,255,255,0.92);
  cursor:pointer;
}
.ddItem:hover{ background: rgba(255,255,255,0.07); }
.ddItem.is-active{
  background: rgba(80,140,255,0.18);
  border: 1px solid rgba(80,140,255,0.35);
}

/* 포트폴리오 추천 */
.pfCard{
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
}
.pfTitle{
  font-size: 12px;
  opacity: 0.85;
  margin: 0 0 8px 2px;
}
.pfBtns{
  display:flex;
  gap: 10px;
  align-items:center;
  flex-wrap: wrap;
}
.pfBtn{
  height: var(--ctrl-h);
  padding: 0 14px;
  border-radius: var(--ctrl-r);
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: #fff;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  white-space: nowrap;
  cursor: pointer;
}
.pfBtn:hover{ background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.22); }
.pfBtn.is-active{
  background: rgba(80,140,255,0.18);
  border-color: rgba(80,140,255,0.45);
  box-shadow: 0 0 0 3px rgba(80,140,255,0.18);
}

/* 비중 영역 */
.weights{
  display:grid;
  gap: 10px;
  margin-top: 10px;
}

.groupBox{
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
}
.groupTitle{
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  display:flex;
  align-items: baseline;
  gap: 8px;
}
.groupHint{
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.group-pp{ background: rgba(255,255,255,0.035); }
.group-risk{ background: rgba(78,161,255,0.06); }

.weightRowFixed{
  display:grid;
  grid-template-columns: 1fr 88px;
  gap: 10px;
  align-items:center;
  margin-top: 8px;
}
.fundName{
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.weightRowFixed input{
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  width: 100%;
}

/* 위험자산 강조 */
.input-danger{
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 2px rgba(255, 90, 115, 0.20);
}

/* 노트 */
.note{
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-line;
}

/* KPI */
.kpis{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.kpi{
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 12px;
}
.kpi .label{ font-size: 12px; color: var(--muted); }
.kpi .val{ margin-top: 6px; font-size: 18px; font-weight: 800; }

/* 표 */
.tableWrap{
  border: 1px solid var(--line);
  border-radius: 14px;
  max-height: 280px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.table{
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td{
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.table th{
  text-align:left;
  color: var(--muted);
  background: rgba(255,255,255,0.03);
}
.table td.right, .table th.right{ text-align:right; }
.table tbody tr:last-child td{ border-bottom: none; }

.hint { font-size: 11px; color: var(--muted); font-weight: 500; }

/* 차트 */
.chartBox{ height: 220px; }
@media (min-width: 768px){ .chartBox{ height: 260px; } }
#chart{ width: 100% !important; height: 100% !important; max-height: none; }

.barBox{
  height: 180px;
  margin-bottom: 10px;
}
@media (min-width: 768px){ .barBox{ height: 210px; } }

/* 패널 */
.panelSummary{
  list-style: none;
  cursor: pointer;
  display:flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 10px;
}
.panelSummary::-webkit-details-marker{ display:none; }
.h2like{ font-size: 15px; font-weight: 800; color: var(--text); }
.panelHint{ font-size: 12px; color: var(--muted); font-weight: 600; }

/* 모드 배지 */
.modeBadge{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-radius:12px;
  margin:10px 0 12px;
  border:1px solid rgba(255,255,255,0.16);
  background:rgba(255,255,255,0.06);
  color:#fff;
  font-size:13px;
}
.modeBadge .left{ opacity:.9; }
.modeBadge .right{ font-weight:700; }

/* 모바일 */
@media (max-width: 520px){
  .container { padding: 10px; }
  .card { padding: 12px; border-radius: 14px; }
  .grid2{ grid-template-columns: 1fr; }
  .kpis{ grid-template-columns: 1fr; }

  .run-box{ flex-wrap: wrap; }
  .error{ white-space: normal; }

  #rebalanceText{ max-width: 200px; }
}

/* =========================
   상태 뱃지(OK/실행중/실행완료) 색상 구분
   ========================= */
.ok-badge{
  display: none;
  height: var(--ok-h, 34px);
  padding: 0 var(--ok-pad-x, 12px);
  border-radius: 999px;

  font-size: 13px;
  font-weight: 800;
  line-height: 1;

  white-space: nowrap;
  align-items: center;
  justify-content: center;

  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
}

/* ✅ 실행가능: 초록 */
.ok-badge.is-ok{
  background: rgba(46, 204, 113, 0.18);
  border-color: rgba(46, 204, 113, 0.45);
  color: #d8ffe9;
}

/* ✅ 실행중: 노랑(주의) */
.ok-badge.is-running{
  background: rgba(255, 200, 0, 0.16);
  border-color: rgba(255, 200, 0, 0.45);
  color: rgba(255,255,255,0.92);
}

/* ✅ 실행완료: 파랑 */
.ok-badge.is-done{
  background: rgba(80, 140, 255, 0.18);
  border-color: rgba(80, 140, 255, 0.55);
  color: #e7f1ff;
}
