/* ── 레이아웃 유틸 ──────────────────────────────────────── */
.section-stack, .stack { display: flex; flex-direction: column; gap: var(--space-md); }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-md); }

/* ── 카드 (토스: 흰색, 그림자, 테두리 없음) ─────────────── */
.card,
.section-card,
.metric-card,
.entity-card,
.table-card,
.control-panel,
.health-card {
  border-radius: var(--radius-lg);
  border: none;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.section-card { display: flex; flex-direction: column; gap: 12px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}
.section-title { font-size: var(--font-lg); font-weight: 800; line-height: var(--leading-tight); }
.section-note  { color: var(--text-tertiary); font-size: var(--font-xs); font-weight: 600; letter-spacing: 0.04em; }

.muted, .kpi-subtext, .table-note { color: var(--text-tertiary); font-size: var(--font-sm); line-height: var(--leading-body); }

/* ── 대시보드 그리드 ────────────────────────────────────── */
.dashboard-shell,
.metric-grid,
.overview-grid,
.health-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-md);
}
.dashboard-shell-clean { gap: 14px; }
.dashboard-shell > .section-card,
.dashboard-shell > .table-card,
.dashboard-shell > .card { grid-column: 1 / -1; min-width: 0; }
.section-card-header, .metric-grid-clean, .split-layout-clean { grid-column: 1 / -1; }

/* ── 페이지 헤더 ────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title  { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.page-subtitle { margin-top: 4px; color: var(--text-secondary); font-size: var(--font-sm); }
.meta-inline  { color: var(--text-tertiary); font-size: var(--font-xs); font-weight: 600; }

/* ── 메트릭 카드 ────────────────────────────────────────── */
.metric-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.metric-card.danger { background: var(--danger-100); }

.metric-card.span-4 { grid-column: span 4; }
.metric-card.span-3 { grid-column: span 3; }
.metric-card.span-2 { grid-column: span 2; }
.metric-grid-clean  { gap: 12px; }

.metric-label {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  word-break: keep-all;
}
.metric-value {
  font-size: clamp(20px, 1.6vw, 30px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.03em;
  word-break: keep-all;
}
.metric-footnote { color: var(--text-tertiary); font-size: var(--font-xs); }

/* ── 필 / 배지 (토스 스타일) ───────────────────────────── */
.status-chip, .inline-pill, .status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  border: none;
}
.status-chip.green,  .inline-pill.green,  .status-pill.green  { background: var(--success-100); color: var(--success-500); }
.status-chip.yellow, .inline-pill.yellow, .status-pill.yellow { background: var(--warning-100); color: var(--warning-500); }
.status-chip.red,    .inline-pill.red,    .status-pill.red    { background: var(--danger-100);  color: var(--danger-500); }
.status-chip.gray,   .inline-pill.gray,   .status-pill.gray   { background: var(--neutral-100); color: var(--text-secondary); }

/* ── 빈 상태 ─────────────────────────────────────────── */
.empty-state {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--neutral-100);
  color: var(--text-tertiary);
  font-size: var(--font-sm);
  text-align: center;
}

/* ── 버튼 (토스 스타일 — 굵고 둥글게) ──────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--brand-500);
  color: var(--text-inverse);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-600); box-shadow: 0 4px 12px rgba(49, 130, 246, 0.30); }
.btn:active { transform: scale(0.98); }

.btn.secondary {
  background: var(--neutral-100);
  color: var(--text-primary);
  border: 1.5px solid var(--border-default);
}
.btn.secondary:hover { background: var(--neutral-150); box-shadow: none; }

.btn.warn  { background: var(--warning-500); color: #fff; }
.btn.warn:hover  { background: #e0a020; box-shadow: 0 4px 12px rgba(247, 183, 49, 0.30); }

.btn.danger { background: var(--danger-500); color: #fff; }
.btn.danger:hover { background: var(--danger-700); box-shadow: 0 4px 12px rgba(240, 68, 82, 0.30); }

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

/* ── 위험 구역 ──────────────────────────────────────────── */
.danger-zone  { border: none; background: var(--bg-card); box-shadow: inset 4px 0 0 var(--danger-500), var(--shadow-sm); }
.danger-title { color: var(--danger-500); }

/* ── 알림 목록 ──────────────────────────────────────────── */
.alert-list, .detail-list { display: flex; flex-direction: column; gap: 10px; }

.alert-row, .detail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--neutral-100);
  font-size: var(--font-sm);
}

/* ── 헬스 카드 ──────────────────────────────────────────── */
.health-card { grid-column: span 3; display: flex; flex-direction: column; gap: 12px; }
.health-card-header { display: flex; justify-content: space-between; gap: var(--space-sm); align-items: center; }
.health-title { margin: 0; font-size: var(--font-md); font-weight: 800; }
.health-meta  { display: flex; flex-direction: column; gap: 6px; }
.health-line  { display: flex; justify-content: space-between; gap: 10px; font-size: var(--font-sm); color: var(--text-secondary); }

/* ── 엔티티 카드 ──────────────────────────────────────── */
.entity-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.entity-card { display: flex; flex-direction: column; gap: 12px; }
.entity-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-md); }
.entity-head h3 { margin: 0; font-size: var(--font-lg); line-height: var(--leading-tight); }
.entity-head p  { margin: 4px 0 0; color: var(--text-tertiary); font-size: var(--font-sm); }

.entity-metrics,
.entity-meta,
.control-actions,
.cluster,
.actions { display: flex; align-items: center; gap: var(--space-xs); flex-wrap: wrap; }

/* ── 토스트 ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 9999;
  min-width: 260px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  color: #fff;
  font-size: var(--font-sm);
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  letter-spacing: -0.01em;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast-info    { background: #333d4b; }
.toast-success { background: var(--success-500); }
.toast-warning { background: var(--warning-500); }
.toast-error   { background: var(--danger-500); }

/* ── 모달 ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(25, 31, 40, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  width: min(440px, 100%);
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-title   { font-size: 20px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.03em; }
.modal-body    { font-size: var(--font-md); line-height: 1.6; color: var(--text-secondary); white-space: pre-wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ── 폼 ──────────────────────────────────────────────────── */
label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.form-grid,
.form-grid-integrations {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
}
.integration-field { min-width: 0; }
.integration-input {
  min-height: 46px;
  width: 100%;
  padding-inline: 14px;
  font-size: var(--font-md);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.integration-input:focus-visible {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── 테이블 (토스 느낌 — 깔끔, 최소 선) ──────────────── */
.table-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.table-wrap {
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

table { width: 100%; border-collapse: collapse; font-size: var(--font-sm); }

th, td {
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: var(--neutral-100);
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-subtle);
}

tr:not(:last-child) td { border-bottom: 1px solid var(--border-subtle); }
tr:hover td { background: var(--neutral-50); }

.right { text-align: right; }

/* 손익 색상 — 한국 주식 관례 (빨강=상승, 파랑=하락) */
.positive { color: var(--danger-500); font-weight: 700; }
.negative { color: #2060b8; font-weight: 700; }

/* ── 구조화 알림 카드 (왜/어디서/조치) ─────────────────── */
.alert-structured {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-card-muted);
  border: 1px solid var(--border-subtle);
}
.alert-structured.critical {
  background: color-mix(in srgb, var(--danger-100) 60%, var(--bg-card));
  border-color: rgba(240, 68, 82, 0.18);
  border-left: 4px solid var(--danger-500);
}
.alert-structured.warn {
  background: color-mix(in srgb, var(--warning-100) 60%, var(--bg-card));
  border-color: rgba(247, 183, 49, 0.18);
  border-left: 4px solid var(--warning-500);
}
.alert-structured-icon { font-size: 20px; line-height: 1.5; flex-shrink: 0; }
.alert-structured-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.alert-structured-title { font-size: var(--font-md); font-weight: 700; color: var(--text-primary); }
.alert-structured-meta { display: flex; flex-direction: column; gap: 3px; font-size: var(--font-sm); color: var(--text-secondary); }
.alert-structured-meta span { line-height: 1.5; }
.alert-structured-meta strong { color: var(--text-primary); font-weight: 700; }
.alert-structured-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* ── 초기 설정 오버레이 ─────────────────────────────────── */
.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(25, 31, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.setup-overlay.hidden { display: none; }

.setup-modal {
  width: min(520px, 100%);
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-height: 92vh;
  overflow-y: auto;
}
.setup-header  { display: flex; flex-direction: column; gap: 6px; }
.setup-logo    { font-size: 12px; font-weight: 800; color: var(--brand-500); letter-spacing: 0.08em; text-transform: uppercase; }
.setup-title   { margin: 0; font-size: 26px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.03em; }
.setup-desc    { margin: 0; font-size: var(--font-sm); color: var(--text-secondary); line-height: 1.6; }

.setup-step-bar { display: flex; align-items: center; gap: 6px; }
.setup-step-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--neutral-200);
  flex-shrink: 0;
  transition: all 0.2s;
}
.setup-step-dot.active { background: var(--brand-500); width: 20px; border-radius: 4px; }
.setup-step-dot.done   { background: var(--success-500); }

.setup-content { display: flex; flex-direction: column; gap: 18px; }
.setup-field   { display: flex; flex-direction: column; gap: 6px; }
.setup-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.setup-field input {
  min-height: 48px;
  width: 100%;
  padding-inline: 16px;
  font-size: var(--font-md);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-default);
  background: var(--bg-input);
}
.setup-field input:focus-visible {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.setup-actions { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.setup-actions .btn { flex: 1; min-width: 110px; }

.setup-optional-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--neutral-100);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  margin-left: 6px;
  letter-spacing: 0;
  text-transform: none;
}
.setup-complete-icon { font-size: 52px; text-align: center; }
.setup-complete-msg  { text-align: center; font-size: var(--font-md); color: var(--text-secondary); line-height: 1.7; }

/* ── 운영 전략 폼 ──────────────────────────────────────── */
.strategy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
}
.strategy-field { display: flex; flex-direction: column; gap: 4px; }
.strategy-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 0;
}
.strategy-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.strategy-input {
  min-height: 46px;
  width: 100%;
  padding-inline: 14px;
  font-size: var(--font-md);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-default);
  background: var(--bg-input);
  margin-top: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.strategy-input:focus-visible {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── 자산 요약 바 ───────────────────────────────────────── */
.asset-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.asset-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}
.asset-cell-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.asset-cell-value {
  font-size: clamp(17px, 1.5vw, 24px);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
.asset-cell-value.positive { color: var(--danger-500); }
.asset-cell-value.negative { color: #2060b8; }

/* ── 거래 서브탭 ────────────────────────────────────────── */
.trade-subtabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: var(--radius-pill);
  background: var(--neutral-100);
  flex-wrap: wrap;
}
.trade-subtab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  min-height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.trade-subtab:hover { background: var(--neutral-200); color: var(--text-primary); }
.trade-subtab.active {
  background: var(--bg-card);
  color: var(--brand-500);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}
.trade-panel { display: none; }
.trade-panel.active { display: block; }

/* ── 설정 섹션 구분 ─────────────────────────────────────── */
.settings-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 0 2px;
  margin-top: 6px;
}

/* ── 기타 유틸 ──────────────────────────────────────────── */
.content-grid {
  grid-column: span 12;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: var(--space-md);
}
.control-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: var(--space-md);
}
.system-section { display: none; grid-column: 1 / -1; }
.system-section.active { display: block; }

/* ── 반응형 ─────────────────────────────────────────────── */
@media (max-width: 767px) {
  .asset-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strategy-grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid-integrations { grid-template-columns: 1fr; }
  .setup-modal { padding: 24px 18px; }
  .setup-title { font-size: 22px; }
  .trade-subtabs { width: 100%; }
  .trade-subtab { flex: 1; text-align: center; }
  .card, .metric-card, .entity-card, .control-panel, .table-card, .health-card { padding: 14px; }
  .section-header { flex-direction: column; align-items: flex-start; }
  .dashboard-shell, .metric-grid, .grid { gap: 10px; }
}

@media (max-width: 1023px) {
  .content-grid, .control-layout { grid-template-columns: 1fr; }
  .health-card { grid-column: span 6; }
}

@media (max-width: 1279px) {
  .metric-card.span-4 { grid-column: span 6; }
  .metric-card.span-3 { grid-column: span 4; }
  .metric-card.span-2 { grid-column: span 3; }
}
