* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #4a9eff;
  --green: #4caf50;
  --red: #ef5350;
  --orange: #ff9800;
  --blue: #42a5f5;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: calc(56px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}

/* ─── 탭 바 ─── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px 4px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab.active {
  color: var(--accent);
  font-weight: 600;
}

/* ─── 콘텐츠 ─── */
#content {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 80px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error {
  text-align: center;
  color: var(--red);
  padding: 60px 20px;
}

/* ─── 카드 ─── */
.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

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

.card-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.card-value {
  font-size: 22px;
  font-weight: 700;
}

.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }

/* ─── 섹션 ─── */
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text);
}

/* ─── 테이블 ─── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--text-dim);
  font-weight: 500;
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-blue { color: var(--blue); }
.text-dim { color: var(--text-dim); }

/* ─── 배지 ─── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-signal { background: #1b4332; color: #4caf50; }
.badge-hold { background: #1a3a5c; color: #42a5f5; }
.badge-wait { background: #2a2a3a; color: #888; }
.badge-success { background: #1b4332; color: #4caf50; }
.badge-failure { background: #4a1a1a; color: #ef5350; }

/* ─── 조건 아이콘 ─── */
.cond-ok { color: var(--green); font-weight: 700; }
.cond-fail { color: var(--red); font-weight: 700; }

/* ─── 실행 로그 ─── */
.run-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.run-item:active { border-color: var(--accent); }

.run-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.run-id { font-weight: 600; font-size: 14px; }

.run-time {
  font-size: 12px;
  color: var(--text-dim);
}

.log-box {
  background: #0a0a15;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  color: var(--text-dim);
}

/* ─── 스크리닝 ─── */
.ticker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

/* ─── 인증 화면 ─── */
.auth-container {
  max-width: 340px;
  margin: 60px auto 0;
  padding: 0 20px;
}

.auth-logo {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 32px;
}

.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  color: var(--text);
  background: var(--border);
  font-weight: 600;
}

#authForm input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 14px 16px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

#authForm input:focus {
  border-color: var(--accent);
}

#authForm input::placeholder {
  color: var(--text-dim);
}

.auth-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px;
  margin-top: 4px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.auth-btn:active { opacity: 0.8; }

.auth-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* ─── 환영 바 ─── */
.welcome-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.logout-btn:active { border-color: var(--red); color: var(--red); }

/* ─── 누적 손익 차트 ─── */
.chart-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chart-bar-row:last-child { margin-bottom: 0; }

.chart-date {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 40px;
  text-align: right;
}

.chart-bar-wrap {
  flex: 1;
  height: 14px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.chart-val {
  font-size: 11px;
  font-weight: 600;
  min-width: 55px;
  text-align: right;
}

/* ─── 종목 차트 ─── */
.clickable-row { cursor: pointer; }
.clickable-row:active { background: var(--border); }

.chart-canvas-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 16px;
  height: 280px;
}

#chart-container { margin-bottom: 16px; }

/* ─── 풀다운 새로고침 힌트 ─── */
.refresh-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px;
}
