/*
 * 경험스택 V2 — 기본 요소 · 앱 셸 · 공용 컴포넌트 (화면별 스타일은 views.css)
 * 기존 경험스택 브랜드 규칙을 따른다: 강조색은 brand 하나, 경계선은 border 1px, 그라데이션 없음,
 * 주요 버튼은 shadow-block, 보조 버튼은 테두리 없는 sunken 면, 종류 구분은 색 대신 모양·아이콘·글자.
 */

/* ── 기본 ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
dd,
figure,
blockquote,
fieldset {
  margin: 0;
  padding: 0;
}

fieldset {
  min-width: 0;
  border: 0;
}

legend {
  padding: 0;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--brand-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

code,
pre,
.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

pre {
  margin: 0;
}

strong {
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

::selection {
  background: var(--brand-soft);
  color: var(--brand-text);
}

/* ── 유틸리티 ─────────────────────────────────────────────────────────── */
.muted {
  color: var(--muted);
}

.small {
  font-size: var(--fs-sm);
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.pad {
  padding: var(--sp-4);
}

.spacer {
  flex: 1 1 auto;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.center {
  justify-content: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.grid {
  display: grid;
  gap: var(--sp-4);
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.align-start {
  align-items: start;
}

.span-2 {
  grid-column: 1 / -1;
}

.offscreen {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

.icon {
  flex: none;
  vertical-align: -0.18em;
}

.plain-list {
  padding-left: 1.2em;
  list-style: disc;
}

.plain-list li {
  margin: 2px 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 200;
  padding: 10px 16px;
  transform: translateY(-160%);
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  font-weight: 700;
}

.skip-link:focus {
  transform: none;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ground);
  text-align: center;
}

/* ── 앱 셸 ────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 0;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px 8px;
  color: var(--ink);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark-bg {
  fill: var(--sky);
}

.brand-mark-top {
  fill: var(--brand);
}

.brand-mark-line {
  fill: var(--sun);
}

.brand-mark-eye {
  fill: var(--ink);
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 800;
  line-height: 1.2;
}

.brand-tag {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--muted);
  font-size: var(--fs-tag);
  font-weight: 700;
}

.nav {
  flex: 1 1 auto;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: background-color 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--ground);
  color: var(--ink);
  text-decoration: none;
}

.nav-item.is-active {
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 700;
}

.nav-item:focus-visible {
  outline-color: var(--focus);
}

.nav-label {
  flex: 1 1 auto;
  min-width: 0;
}

.nav-count {
  min-width: 24px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--muted);
  font-size: var(--fs-tag);
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

.nav-flag {
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: var(--fs-tag);
  font-weight: 700;
  line-height: 22px;
}

.nav-item.is-active .nav-count,
.nav-item.is-active .nav-flag {
  background: var(--surface);
  color: var(--brand-text);
}

.sidebar-foot {
  margin-top: auto;
}

.ws-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--sunken);
  color: var(--ink);
  transition: background-color 0.15s;
}

.ws-card:hover {
  background: var(--border);
  text-decoration: none;
}

.ws-mode {
  color: var(--muted);
  font-size: var(--fs-tag);
  font-weight: 700;
}

.ws-mode.is-real {
  color: var(--muted);
}

.ws-mode.is-demo {
  color: var(--brand-text);
}

.ws-name {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.ws-facts {
  color: var(--muted);
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar .topbar-menu {
  display: none;
}

.topbar-title {
  flex: none;
  font-size: var(--fs-md);
  font-weight: 700;
  white-space: nowrap;
}

.topbar-search {
  position: relative;
  flex: 0 1 360px;
  min-width: 140px;
}

.topbar-search-icon {
  position: absolute;
  top: 50%;
  left: 11px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.topbar-search-input {
  height: 40px;
  min-height: 40px;
  padding-left: 36px;
  border-radius: var(--radius-full);
  background: var(--ground);
  font-size: var(--fs-sm);
}

body[data-view='search'] .topbar-search {
  visibility: hidden;
}

.topbar-chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

.topbar-chip:hover {
  background: var(--border);
  text-decoration: none;
}

.topbar-chip.is-external {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.topbar-chip.is-busy {
  background: var(--brand-soft);
  color: var(--brand-text);
  animation: soft-pulse 1.6s ease-in-out infinite;
}

.topbar-demo {
  display: inline-flex;
  flex: 0 1 auto;
  min-width: 0;
}

.topbar-demo .btn {
  max-width: 100%;
}

.banner-root {
  flex: none;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: 8px var(--sp-5);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}

.banner-text {
  flex: 1 1 320px;
  min-width: 0;
}

.banner-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.banner-mock {
  background: var(--sunken);
  color: var(--ink);
}

.banner-demo {
  border-bottom-color: var(--brand-soft);
  background: var(--brand-soft);
  color: var(--ink);
}

.banner-warn {
  border-bottom-color: var(--danger-soft);
  background: var(--danger-soft);
  color: var(--danger);
}

.app-body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  background: var(--scrim);
}

/* ── 화면 공통 ────────────────────────────────────────────────────────── */
.view {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) 56px;
}

.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
}

.view-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  line-height: 1.3;
}

.view-sub {
  max-width: 68ch;
  margin-top: 4px;
  color: var(--muted);
}

.section-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--fs-lg);
  font-weight: 700;
}

.eyebrow {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.boot-view {
  max-width: 560px;
  padding-top: 12vh;
}

.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--space-8) var(--space-6);
  text-align: center;
}

.boot-card .skeleton {
  width: min(280px, 100%);
}

.boot-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 800;
}

/* ── 카드 ─────────────────────────────────────────────────────────────── */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.4;
}

.card-title .icon {
  color: var(--muted);
}

.card-danger {
  border-color: var(--danger-soft);
}

.card-danger .card-title .icon {
  color: var(--danger);
}

/* ── 버튼 ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--border);
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: var(--fs-xs);
  font-weight: 700;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
  box-shadow: var(--shadow-block);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand);
  filter: brightness(0.96);
}

/* 블록을 누르는 느낌: 그림자가 사라지고 4px 내려간다 */
.btn-primary:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: none;
}

.btn-primary:disabled {
  box-shadow: none;
}

.btn-soft {
  border-color: var(--brand-soft);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 700;
}

.btn-soft:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* 흰 면이 아닌 바탕(ground·sunken·색 면) 위의 보조 버튼은 흰 면으로 띄운다 */
.btn-outline,
.banner .btn:not(.btn-primary):not(.btn-ghost),
.notice .btn:not(.btn-primary):not(.btn-ghost),
.view-header .btn:not(.btn-primary):not(.btn-ghost) {
  border-color: var(--border);
  background: var(--surface);
}

.btn-outline:hover:not(:disabled),
.banner .btn:not(.btn-primary):not(.btn-ghost):hover:not(:disabled),
.notice .btn:not(.btn-primary):not(.btn-ghost):hover:not(:disabled),
.view-header .btn:not(.btn-primary):not(.btn-ghost):hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink);
}

.btn-ghost:hover:not(:disabled) {
  border-color: transparent;
  background: var(--sunken);
}

.btn-danger {
  border-color: var(--danger-fill);
  background: var(--danger-fill);
  color: var(--on-danger);
  font-weight: 700;
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger);
}

.btn-danger-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  border-color: transparent;
  background: var(--danger-soft);
}

.btn-demo {
  border-color: var(--brand-soft);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 700;
}

.btn-demo:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.btn-icon {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
}

.btn-icon:hover {
  background: var(--sunken);
  color: var(--ink);
}

.btn-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-text);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-link:hover {
  text-decoration-thickness: 2px;
}

/* ── 폼 ───────────────────────────────────────────────────────────────── */
.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.4;
  transition: border-color 0.15s;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--focus);
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.textarea {
  min-height: 84px;
  line-height: 1.6;
  resize: vertical;
}

.input-sm,
.select-sm {
  width: auto;
  min-height: 34px;
  padding: 4px 10px;
  font-size: var(--fs-xs);
}

.input-lg {
  min-height: 52px;
  font-size: var(--fs-md);
}

.input.mono {
  font-size: 0.86rem;
}

.select {
  padding-right: 28px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.field-inline .field-label {
  flex: none;
  white-space: nowrap;
}

.field-hint {
  display: block;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 400;
  line-height: 1.5;
}

.field-error {
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.req {
  color: var(--danger);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3) var(--sp-4);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-2);
}

.input-group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.input-group .input {
  flex: 1 1 auto;
  min-width: 0;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  cursor: pointer;
}

.check input[type='checkbox'],
.check input[type='radio'] {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--brand);
  cursor: pointer;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.check-card {
  align-items: center;
  min-height: 36px;
  padding: 6px 14px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: var(--fs-xs);
  font-weight: 600;
}

.check-card input[type='checkbox'] {
  margin: 0;
}

.check-card:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-text);
}

/* ── 칩 · 세그먼트 · 탭 ───────────────────────────────────────────────── */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--border-strong);
}

.chip.is-active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-text);
}

.chip-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--muted);
  font-size: var(--fs-tag);
  line-height: 20px;
  text-align: center;
}

.chip.is-active .chip-count {
  background: var(--surface);
  color: var(--brand-text);
}

.chip-sm {
  min-height: 28px;
  padding: 0 10px;
  font-size: var(--fs-tag);
}

.seg {
  display: inline-flex;
  padding: 4px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
}

.seg-btn {
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-active {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--ink);
}

.seg-sm .seg-btn {
  min-height: 26px;
  padding: 0 10px;
  font-size: var(--fs-tag);
}

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: none;
  min-height: 44px;
  margin-bottom: -1px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  border-bottom-color: var(--brand);
  color: var(--ink);
  font-weight: 700;
}

.tab-panel {
  min-width: 0;
  padding-top: var(--sp-2);
}

/* ── 배지 ─────────────────────────────────────────────────────────────── */
.badge-row {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.badge {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font-size: var(--fs-tag);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

/*
 * 확실성: 테두리 모양 + 표식 모양으로 구분한다(색은 ink·muted·brand 범위 안).
 * 직접 진술 = 실선·꽉 찬 원 / AI 추론 = 점선·빈 고리 / 예정 = 점점선·빈 사각 / AI 제안 = 점선·마름모(brand-soft)
 */
.c-stated {
  --c: var(--ink);
  --c-bg: var(--surface);
  --c-line: var(--border);
  --c-border: solid;
}

.c-inferred {
  --c: var(--muted);
  --c-bg: var(--sunken);
  --c-line: var(--border-strong);
  --c-border: dashed;
}

.c-planned {
  --c: var(--muted);
  --c-bg: var(--surface);
  --c-line: var(--border-strong);
  --c-border: dotted;
}

.c-ai_suggested {
  --c: var(--brand-text);
  --c-bg: var(--brand-soft);
  --c-line: var(--brand);
  --c-border: dashed;
}

.badge-certainty {
  border: 1px var(--c-border, solid) var(--c-line, var(--border));
  background: var(--c-bg, var(--sunken));
  color: var(--c, var(--muted));
}

.badge-mark,
.chip-mark {
  flex: none;
  width: 8px;
  height: 8px;
  border: 2px solid var(--c, var(--a, currentColor));
  border-radius: 50%;
  background: var(--c, var(--a, currentColor));
}

/* 직접 진술: 꽉 찬 원 / AI 추론: 빈 고리 / 예정: 빈 사각 / AI 제안: 꽉 찬 마름모 */
.c-inferred > .badge-mark,
.c-inferred > .chip-mark {
  background: transparent;
}

.c-planned > .badge-mark,
.c-planned > .chip-mark {
  border-radius: 1px;
  background: transparent;
}

.c-ai_suggested > .badge-mark,
.c-ai_suggested > .chip-mark {
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  border-radius: 1px;
}

/* 행위자: sunken 면 + 아이콘(종류는 아이콘 모양과 글자로 구분) */
.a-user {
  --a: var(--ink);
}

.a-ai {
  --a: var(--ink);
}

.a-calendar_plan {
  --a: var(--ink);
}

.a-external {
  --a: var(--ink);
}

.badge-actor {
  background: var(--sunken);
  color: var(--ink);
}

.chip[class*=' a-'] > .chip-mark {
  border-radius: 2px;
}

/* 노드 유형 */
.t-activity {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-decision {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-action {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-outcome {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-observation {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-learning {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-artifact {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.t-event {
  --t: var(--ink);
  --t-bg: var(--sunken);
}

.badge-type {
  border-radius: 8px;
  background: var(--t-bg, var(--sunken));
  color: var(--t, var(--ink));
}

/* 출처 */
.s-local {
  --s: var(--muted);
  --s-bg: var(--sunken);
}

.s-drive {
  --s: var(--muted);
  --s-bg: var(--sunken);
}

.s-ai {
  --s: var(--muted);
  --s-bg: var(--sunken);
}

.s-calendar {
  --s: var(--muted);
  --s-bg: var(--sunken);
}

.badge-source {
  background: var(--sunken);
  color: var(--ink);
}

.badge-source .icon {
  color: var(--s, var(--muted));
}

/* 처리 상태 */
.badge-state {
  background: var(--sunken);
  color: var(--ink);
}

.st-pending,
.job-partial {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.st-structured,
.job-succeeded {
  background: var(--success-soft);
  color: var(--success);
}

.st-failed,
.st-deleted,
.job-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.st-skipped,
.st-tombstone,
.job-queued,
.job-cancelled {
  background: var(--sunken);
  color: var(--muted);
}

.job-running {
  background: var(--sunken);
  color: var(--ink);
  animation: soft-pulse 1.6s ease-in-out infinite;
}

.badge-plain {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink);
}

.badge-focus {
  background: var(--brand);
  color: var(--on-brand);
}

.count-pill {
  display: inline-block;
  min-width: 24px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--muted);
  font-size: var(--fs-tag);
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

/* 묶음: 색으로 나누지 않고 이름 글자로 구분한다 */
.k-0 {
  --k: var(--border-strong);
}

.k-1 {
  --k: var(--border-strong);
}

.k-2 {
  --k: var(--border-strong);
}

.k-3 {
  --k: var(--border-strong);
}

.k-4 {
  --k: var(--border-strong);
}

.k-5 {
  --k: var(--border-strong);
}

.k-6 {
  --k: var(--border-strong);
}

.k-7 {
  --k: var(--border-strong);
}

.k-none {
  --k: var(--border-strong);
}

/* ── 안내 · 빈 상태 · 스켈레톤 ────────────────────────────────────────── */
.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--fs-sm);
}

.notice > .icon {
  margin-top: 3px;
  color: var(--muted);
}

.notice > span,
.notice > div {
  flex: 1 1 200px;
  min-width: 0;
}

.notice-info {
  background: var(--sunken);
}

.notice-success {
  background: var(--success-soft);
}

.notice-warn {
  background: var(--brand-soft);
}

.notice-danger {
  background: var(--danger-soft);
}

.notice-success > .icon {
  color: var(--success);
}

.notice-warn > .icon {
  color: var(--brand-text);
}

.notice-danger > .icon {
  color: var(--danger);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-4);
  color: var(--muted);
  text-align: center;
}

.empty-lg {
  padding: 56px var(--sp-5);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: var(--sp-1);
  padding: 16px;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--muted);
}

/* 빈 화면·온보딩·로딩에는 스태키가 나온다 */
.stacky {
  flex: none;
  width: 96px;
  height: 120px;
  margin-bottom: var(--sp-1);
  user-select: none;
  -webkit-user-drag: none;
}

.stacky-sm {
  width: 64px;
  height: 80px;
}

.stacky-lg {
  width: 136px;
  height: 170px;
}

/* 수줍은 스태키는 블록이 한 단이라 위쪽 빈 곳을 잘라 낸다 */
.stacky-shy {
  height: 68px;
  object-fit: cover;
  object-position: 50% 100%;
}

.empty-title {
  color: var(--ink);
  font-size: var(--fs-lg);
  font-weight: 700;
}

.empty .muted {
  max-width: 54ch;
}

.empty .cluster,
.empty > .btn {
  margin-top: var(--sp-2);
}

.skeleton {
  border-radius: var(--radius-sm);
  background: var(--sunken);
  animation: soft-pulse 1.4s ease-in-out infinite;
}

.sk-title {
  width: 55%;
  height: 24px;
}

.sk-line {
  width: 85%;
  height: 14px;
}

.sk-block {
  width: 100%;
  height: 88px;
}

/* ── 표 · 진행 막대 · 사실 목록 ───────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.table th {
  background: var(--ground);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tr.is-revoked td {
  color: var(--muted);
}

.progress {
  display: block;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--sunken);
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.25s ease;
}

.is-indeterminate {
  animation: soft-pulse 1.4s ease-in-out infinite;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--sp-3) var(--sp-4);
}

.fact dt,
.record-facts dt {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 650;
}

.fact dd,
.record-facts dd {
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  font-weight: 600;
}

.secret-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.secret {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--ground);
  font-size: 0.84rem;
  white-space: nowrap;
  user-select: all;
}

.code-block {
  position: relative;
}

.code-block > .btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

.code {
  max-height: 340px;
  padding: 12px 14px;
  overflow: auto;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--fs-xs);
  line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

.code-block > .code {
  padding-right: 120px;
}

/* 검색어 · 근거 인용 강조 */
mark.hit {
  padding: 0 1px;
  border-radius: 3px;
  background: var(--brand-soft);
  color: inherit;
}

mark.quote-hit {
  padding: 1px 2px;
  border-bottom: 2px solid var(--brand);
  border-radius: 3px;
  background: var(--brand-soft);
  color: var(--ink);
  font-weight: 700;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid var(--brand-soft);
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-family: var(--font-mono);
  font-size: var(--fs-tag);
  font-weight: 700;
  vertical-align: 1px;
  white-space: nowrap;
}

.ref-chip:hover {
  border-color: var(--brand);
}

.node-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 28px;
  padding: 2px 10px 2px 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-sm);
  text-align: left;
}

.node-chip:hover {
  border-color: var(--border-strong);
  background: var(--ground);
}

.node-chip.is-active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.node-chip-title {
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 대화상자 · 토스트 ────────────────────────────────────────────────── */
.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  color: var(--ink);
}

.dialog::backdrop {
  background: var(--scrim);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--space-6);
}

.dialog-title {
  font-size: var(--fs-lg);
  font-weight: 700;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}

.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toast-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.16s, transform 0.16s;
}

.toast-icon {
  flex: none;
  margin-top: 2px;
  color: var(--muted);
}

.toast-body {
  flex: 1 1 auto;
  min-width: 0;
}

.toast-msg {
  font-size: var(--fs-sm);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.toast-detail {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.toast-action {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-text);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toast-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.toast-close:hover {
  background: var(--sunken);
  color: var(--ink);
}



.toast.t-success .toast-icon {
  color: var(--success);
}


.toast.t-warn .toast-icon {
  color: var(--brand-text);
}


.toast.t-error .toast-icon {
  color: var(--danger);
}


.toast.t-progress .toast-icon {
  color: var(--brand-text);
  animation: spin 1.1s linear infinite;
}

/* ── 애니메이션 ───────────────────────────────────────────────────────── */
@keyframes shimmer {
  from {
    background-position: 100% 0;
  }

  to {
    background-position: -100% 0;
  }
}

@keyframes soft-pulse {
  50% {
    opacity: 0.55;
  }
}

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

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ── 반응형 ───────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .topbar-chip:not(.is-busy) {
    display: none;
  }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: min(280px, 84vw);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }

  body.nav-open .sidebar {
    transform: none;
    box-shadow: var(--shadow-pop);
  }

  body.nav-open .scrim {
    display: block;
    z-index: 55;
  }

  .topbar {
    padding: 0 var(--sp-3);
  }

  .topbar .topbar-menu {
    display: inline-grid;
  }

  .topbar-title {
    display: none;
  }

  .view {
    padding: var(--sp-4) var(--sp-4) 48px;
  }

  .grid-2,
  .form-grid,
  .field-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .banner {
    padding: 8px var(--sp-3);
  }
}

@media (max-width: 640px) {
  .topbar-search {
    flex: 1 1 96px;
    min-width: 96px;
  }

  .topbar-demo {
    max-width: 46vw;
  }

  .toast-root {
    right: 12px;
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .sidebar,
  .topbar,
  .banner-root,
  .toast-root,
  .drawer,
  .scrim {
    display: none !important;
  }

  .app,
  .app-main {
    display: block;
    height: auto;
  }

  .main {
    overflow: visible;
  }
}
