/* 컴포넌트. 클래스 하나가 한 역할. 상태는 data-* 나 modifier로. */

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border-radius: var(--r-control);
  border: 1px solid var(--line-strong);
  background: var(--bg-surface); color: var(--ink);
  font-size: var(--t-13); font-weight: 600; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { background: var(--tint); border-color: var(--border-strong); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--tint); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--t-12); border-radius: 8px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: var(--t-14); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  color: var(--muted); animation: spin .7s linear infinite;
}
.btn-primary.is-busy::after { color: var(--on-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 배지·칩 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: var(--r-chip);
  font-size: var(--t-12); font-weight: 600; line-height: 1;
  background: var(--bg-subtle); color: var(--ink-soft);
  border: 1px solid transparent;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-navy { background: var(--navy); color: #fff; }
.badge-outline { background: transparent; border-color: var(--line-strong); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-chip);
  font-size: var(--t-11); font-weight: 700; background: var(--bg-subtle); color: var(--ink-soft);
}
.count-danger { background: var(--danger); color: #fff; }
.count-primary { background: var(--primary); color: #fff; }

/* ---------- 카드·패널 ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--s-5);
}
.card-tight { padding: var(--s-4); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-head .h2, .card-head .h3 { margin-top: 2px; }
.card-foot { margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.callout {
  border-radius: var(--r-control); padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line); background: var(--tint);
}
.callout-ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.callout-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.callout-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.callout-primary { background: var(--primary-bg); border-color: var(--primary-line); }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--s-4) 0; }

/* ---------- KPI ---------- */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: var(--t-12); color: var(--muted); font-weight: 500; }
.kpi-value { font-size: var(--t-24); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-value small { font-size: var(--t-14); font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi-note { font-size: var(--t-12); color: var(--muted); }

/* ---------- 진행 바 ---------- */
.bar { height: 6px; border-radius: 3px; background: var(--tint-deep); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 3px; transition: width 400ms var(--ease); }
.bar-thin { height: 4px; }
.bar[data-tone="ok"] > i { background: var(--ok); }
.bar[data-tone="warn"] > i { background: var(--warn); }
.bar[data-tone="danger"] > i { background: var(--danger); }
/* 판정 분포 3분할 바: 적합 / 보완 / 미확인 */
.split { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--tint-deep); }
.split > i { display: block; height: 100%; }
.split .fit { background: var(--primary); }
.split .gap { background: var(--warn); }
.split .unknown { background: var(--border); }
.split .na { background: var(--tint-deep); }

/* ---------- 링 게이지 ---------- */
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring .track { stroke: var(--tint-deep); }
.ring .value { stroke: var(--primary); transition: stroke-dashoffset 700ms var(--ease); }
.ring .value[data-band="mid"] { stroke: var(--warn); }
.ring .value[data-band="low"] { stroke: var(--danger); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.score-value { font-size: var(--t-40); font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.score-of { font-size: var(--t-12); color: var(--muted); margin-top: 2px; }

/* ---------- 탭 ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-strong); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 12px; margin-bottom: -1px;
  border-bottom: 2px solid transparent; color: var(--muted);
  font-size: var(--t-13); font-weight: 600; white-space: nowrap;
  transition: color var(--dur) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }
.subtabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-subtle); border-radius: var(--r-control); }
.subtab { height: 30px; padding: 0 12px; border-radius: 8px; font-size: var(--t-13); font-weight: 600; color: var(--muted); }
.subtab[aria-pressed="true"] { background: var(--bg-surface); color: var(--ink); box-shadow: 0 1px 2px rgba(23,33,29,.08); }

/* ---------- 폼 ---------- */
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-control);
  background: var(--bg-surface); color: var(--ink); font-size: var(--t-13);
}
.textarea { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--primary); }
.select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23636b79' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.select-sm { height: 30px; font-size: var(--t-12); padding: 0 26px 0 8px; border-radius: 8px; }
.input-sm { height: 30px; font-size: var(--t-12); border-radius: 8px; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--muted); }
.search .input { padding-left: 30px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--t-12); font-weight: 600; color: var(--ink-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--t-13); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-control); overflow: hidden; }
.seg button { height: 34px; padding: 0 12px; font-size: var(--t-13); font-weight: 600; color: var(--muted); border-right: 1px solid var(--line-strong); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--primary-bg); color: var(--primary); }

/* ---------- 표 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-13); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: var(--t-12); font-weight: 600; color: var(--muted); white-space: nowrap; }
.table td.n, .table th.n { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---------- 리스트 행 ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .idx { flex: 0 0 auto; width: 28px; font-family: var(--font-mono); font-size: var(--t-12); color: var(--muted); padding-top: 2px; }
.list-row .body { flex: 1 1 auto; min-width: 0; }
.list-row .body strong { display: block; font-size: var(--t-13); }
.list-row .body p { font-size: var(--t-12); color: var(--muted); margin-top: 2px; }
.list-row .aside { flex: 0 0 auto; }

/* ---------- 모달·토스트·패널 ---------- */
.scrim { position: fixed; inset: 0; background: rgba(11, 35, 71, .28); z-index: 60; opacity: 0; transition: opacity var(--dur) var(--ease); }
.scrim.is-open { opacity: 1; }
.modal {
  position: fixed; z-index: 61; left: 50%; top: 50%; transform: translate(-50%, -48%) scale(.98);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--bg-surface); border-radius: var(--r-card); box-shadow: var(--shadow-lift);
  padding: var(--s-6); opacity: 0; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.modal.is-open { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal-wide { width: min(760px, calc(100vw - 32px)); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px;
  padding: 10px 14px; border-radius: var(--r-control);
  background: var(--navy); color: #fff; font-size: var(--t-13); box-shadow: var(--shadow-card);
  animation: toast-in var(--dur) var(--ease);
}
.toast[data-kind="danger"] { background: var(--danger); }
.toast[data-kind="ok"] { background: var(--ok); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 마크다운 라이트 ---------- */
.prose { font-size: var(--t-14); line-height: 1.7; color: var(--ink-soft); }
.prose h1, .prose h2, .prose h3 { color: var(--ink); margin: 1.2em 0 .4em; line-height: 1.3; }
.prose h1 { font-size: var(--t-20); } .prose h2 { font-size: var(--t-16); } .prose h3 { font-size: var(--t-14); }
.prose p { margin: .5em 0; }
.prose ul, .prose ol { padding-left: 1.2em; margin: .5em 0; }
.prose ul { list-style: disc; } .prose ol { list-style: decimal; }
.prose li { margin: .2em 0; }
.prose strong { color: var(--ink); }
.prose > :first-child { margin-top: 0; }
.cite {
  display: inline-block; font-family: var(--font-mono); font-size: 11px; padding: 0 5px;
  border-radius: 4px; background: var(--primary-bg); color: var(--primary); text-decoration: none; margin: 0 1px;
}
.cite:hover { background: color-mix(in srgb, var(--primary) 16%, transparent); text-decoration: none; }

/* ---------- 빈 상태 ---------- */
.empty { padding: var(--s-8) var(--s-4); text-align: center; color: var(--muted); font-size: var(--t-13); }
.empty strong { display: block; color: var(--ink-soft); margin-bottom: 4px; }

/* ---------- 스트리밍 커서 ---------- */
.cursor::after { content: "▍"; color: var(--primary); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
