/* 공통 스타일: 서비스 A(발급소)와 B(검증소)가 같은 파일을 쓴다.
   서비스별 색은 body[data-service] 에서 --accent 계열만 바꾼다. */

@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");
@import url("https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@400;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  /* primitives — 보안 인쇄 용지, 증권 녹, 인주, 계산 노트 잉크 */
  --paper-0: oklch(0.99 0.003 150);
  --paper-1: oklch(0.965 0.012 150);
  --paper-2: oklch(0.93 0.03 150);
  --ink-900: oklch(0.23 0.02 160);
  --ink-600: oklch(0.45 0.015 160);
  --ink-400: oklch(0.62 0.012 160);
  --line: oklch(0.88 0.012 160);
  --line-strong: oklch(0.78 0.015 160);
  --bond-green: oklch(0.44 0.09 160);
  --bond-green-strong: oklch(0.36 0.08 160);
  --bond-green-tint: oklch(0.95 0.03 160);
  --seal-red: oklch(0.52 0.19 28);
  --seal-red-tint: oklch(0.95 0.03 28);
  --notebook-ink: oklch(0.42 0.13 258);
  --notebook-ink-strong: oklch(0.34 0.12 258);
  --notebook-tint: oklch(0.955 0.025 250);
  --notebook-grid: oklch(0.93 0.025 245);
  --ok-green: oklch(0.5 0.13 150);
  --ok-tint: oklch(0.95 0.04 150);

  /* semantic */
  --bg: var(--paper-0);
  --surface: oklch(1 0 0);
  --fg: var(--ink-900);
  --fg-muted: var(--ink-600);
  --fg-faint: var(--ink-400);
  --border: var(--line);
  --border-strong: var(--line-strong);
  --danger: var(--seal-red);
  --danger-bg: var(--seal-red-tint);
  --success: var(--ok-green);
  --success-bg: var(--ok-tint);
  --focus-ring: 0 0 0 3px oklch(0.7 0.12 250 / 0.45);

  /* service accent (A 기본값, B는 아래에서 덮어씀) */
  --accent: var(--bond-green);
  --accent-strong: var(--bond-green-strong);
  --accent-tint: var(--bond-green-tint);
  --on-accent: oklch(1 0 0);

  /* type */
  --font-ui: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --font-doc: "Nanum Myeongjo", "AppleMyungjo", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;

  /* space (4px base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* radius by role */
  --r-control: 6px;
  --r-panel: 10px;
  --r-paper: 2px;

  /* motion */
  --dur-fast: 120ms;
  --dur-base: 220ms;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
}

body[data-service="B"] {
  --accent: var(--notebook-ink);
  --accent-strong: var(--notebook-ink-strong);
  --accent-tint: var(--notebook-tint);
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.55;
  font-feature-settings: "tnum" 0;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: var(--text-lg); font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: var(--text-md); font-weight: 650; }

a { color: var(--accent); text-underline-offset: 3px; }

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- app shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.brand-mark {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-doc);
  font-weight: 700;
  font-size: 15px;
}
.brand-name { font-size: var(--text-lg); font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.brand-sub { font-size: var(--text-xs); color: var(--fg-muted); white-space: nowrap; }

.topbar-spacer { flex: 1; }

.peer-link {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  text-decoration: none;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-control);
  white-space: nowrap;
}
.peer-link:hover { background: var(--paper-1); color: var(--fg); }

/* SSO identity chip — 두 서비스에서 똑같이 생겼다. 같은 신원을 공유한다는 표시 */
.identity {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-1) var(--s-1) var(--s-1) var(--s-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper-1);
}
.identity-text { display: flex; flex-direction: column; line-height: 1.2; }
.identity-name { font-size: var(--text-sm); font-weight: 600; }
.identity-meta { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); }
.identity form { margin: 0; }

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--s-8) var(--s-6) var(--s-12);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: var(--s-6);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.panel-head p { font-size: var(--text-sm); color: var(--fg-muted); }

.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: var(--s-2);
}

/* ---------- controls ---------- */

.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 38px;
  padding: 0 var(--s-4);
  border-radius: var(--r-control);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:hover { background: var(--paper-1); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .input:focus-visible, .peer-link:focus-visible, .row-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--paper-2); color: var(--fg); }

.btn-sm { min-height: 30px; padding: 0 var(--s-3); font-size: var(--text-xs); }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-4); }
.field label { font-size: var(--text-sm); font-weight: 600; }
.field .hint { font-size: var(--text-xs); color: var(--fg-muted); }
.field .error { font-size: var(--text-xs); color: var(--danger); min-height: 0; }

.input {
  width: 100%;
  min-height: 40px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: var(--text-md);
}
.input::placeholder { color: var(--fg-faint); }
.input[aria-invalid="true"] { border-color: var(--danger); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%), linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: var(--s-8); }

/* ---------- key/value list ---------- */

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-2) var(--s-4); font-size: var(--text-sm); margin: 0; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dd.mono { font-size: 12px; }

.hex { font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; word-break: break-all; font-variant-numeric: tabular-nums; }

/* ---------- SSO 세션 증거 패널 ---------- */

.session-strip {
  margin-top: var(--s-8);
  border-top: 1px solid var(--border);
  padding-top: var(--s-6);
  display: grid;
  grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
  gap: var(--s-6);
}
.session-strip h2 { font-size: var(--text-md); }
.session-strip .lead { font-size: var(--text-sm); color: var(--fg-muted); margin-top: var(--s-2); }
.session-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-4); }
.session-cell { border: 1px solid var(--border); border-radius: var(--r-control); padding: var(--s-3) var(--s-4); background: var(--surface); }
.session-cell .label { font-size: var(--text-xs); color: var(--fg-muted); }
.session-cell .value { font-family: var(--font-mono); font-size: var(--text-sm); margin-top: 2px; overflow-wrap: anywhere; }
.session-cell.is-key { border-color: var(--accent); background: var(--accent-tint); }
.session-cell.is-key .label { color: var(--accent-strong); font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--paper-2); color: var(--ink-900);
}
.badge-ok { background: var(--success-bg); color: oklch(0.36 0.1 150); }
.badge-bad { background: var(--danger-bg); color: oklch(0.42 0.16 28); }
.badge-accent { background: var(--accent-tint); color: var(--accent-strong); }

/* ---------- gate screens (로딩 / 로그아웃 / 오류) ---------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-6);
}
.gate-card { max-width: 440px; width: 100%; text-align: left; }
.gate-card .brand { margin-bottom: var(--s-8); }
.gate-card h1 { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.02em; margin-bottom: var(--s-2); }
.gate-card p { color: var(--fg-muted); margin-bottom: var(--s-6); }
.gate-card .actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  display: inline-block; vertical-align: -3px; margin-right: var(--s-2);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: var(--s-6);
  transform: translate(-50%, 8px);
  background: var(--ink-900); color: var(--paper-0);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-control);
  font-size: var(--text-sm);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
  max-width: calc(100vw - 32px);
  z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--seal-red); }

[hidden] { display: none !important; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: var(--s-3) var(--s-4); gap: var(--s-2) var(--s-3); }
  .topbar-spacer { display: none; }
  .identity { order: 3; width: 100%; justify-content: space-between; border-radius: var(--r-panel); }
  .page { padding: var(--s-6) var(--s-4) var(--s-10); }
  .panel { padding: var(--s-4); }
  .session-strip { grid-template-columns: minmax(0, 1fr); }
}

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