/*
 * AgenticFabWorks 투자 계열 공용 토큰.
 * 정본: _shared/afw-ui/src/afw-tokens.css
 * 사이트 사본을 직접 고치지 말고 sync 스크립트를 실행한다.
 */

:root {
  color-scheme: dark;

  /* 간격 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* 표면 */
  --bg: #0b0f14;
  --bg-raised: #111823;
  --bg-sunken: #080b10;
  --surface: #151d29;
  --surface-hover: #1b2532;
  --line: #232f3f;
  --line-strong: #33445a;

  /* 텍스트 */
  --text: #e8eef7;
  --text-muted: #9aa9bd;
  --text-faint: #6d7d92;

  /* 브랜드 accent (화면당 최대 2개) */
  --accent: #4c9aff;
  --accent-strong: #2d7ff0;
  --accent-soft: rgba(76, 154, 255, 0.14);

  /* semantic */
  --up: #ff5b5b;      /* 국내 관행: 상승 적색 */
  --down: #3d8bfd;    /* 하락 청색 */
  --flat: #9aa9bd;
  --ok: #34c77b;
  --warn: #f3b23c;
  --err: #ff6b6b;
  --info: #4c9aff;

  /* 타이포 */
  --fs-caption: 12px;
  --fs-compact: 13px;
  --fs-body-compact: 14px;
  --fs-body: 16px;
  --fs-section: 20px;
  --fs-title: 28px;

  /* 컨트롤 */
  --ctl-compact: 34px;
  --ctl: 40px;
  --ctl-touch: 44px;

  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --font-num: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: light) {
  :root.afw-auto-theme {
    color-scheme: light;
    --bg: #f6f8fb;
    --bg-raised: #ffffff;
    --bg-sunken: #eef2f7;
    --surface: #ffffff;
    --surface-hover: #f2f5fa;
    --line: #dde4ed;
    --line-strong: #c3cede;
    --text: #16202c;
    --text-muted: #55677e;
    --text-faint: #7a8b9f;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body-compact);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.3;
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.afw-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent-strong);
  color: #fff;
  padding: var(--sp-2) var(--sp-4);
  z-index: 100;
}

.afw-skip:focus {
  left: var(--sp-4);
  top: var(--sp-2);
}

/* ---------- 글로벌 헤더 ---------- */

.afw-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: 56px;
  padding: 0 var(--sp-4);
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.afw-header .afw-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.afw-brand-mark {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #7f5bff);
}

.afw-header nav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  overflow-x: auto;
  scrollbar-width: none;
}

.afw-header nav::-webkit-scrollbar {
  display: none;
}

.afw-header nav a {
  display: inline-flex;
  align-items: center;
  height: var(--ctl-compact);
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-body-compact);
  text-decoration: none;
  white-space: nowrap;
}

.afw-header nav a:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.afw-header nav a[aria-current="page"] {
  color: var(--text);
  background: var(--accent-soft);
}

.afw-header .afw-header-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ---------- 버튼 ---------- */

.afw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--ctl);
  padding: 0 var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body-compact);
  cursor: pointer;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}

.afw-btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.afw-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.afw-btn.is-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}

.afw-btn.is-primary:hover:not(:disabled) {
  background: var(--accent);
}

.afw-btn.is-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.afw-btn.is-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.afw-btn.is-danger {
  border-color: color-mix(in srgb, var(--err) 55%, transparent);
  color: var(--err);
  background: transparent;
}

.afw-btn.is-compact {
  min-height: var(--ctl-compact);
  padding: 0 var(--sp-3);
  font-size: var(--fs-compact);
}

.afw-btn.is-icon {
  width: var(--ctl);
  padding: 0;
}

/* ---------- 입력 ---------- */

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

.afw-label {
  font-size: var(--fs-compact);
  color: var(--text-muted);
  font-weight: 600;
}

.afw-input,
.afw-select,
.afw-textarea {
  width: 100%;
  min-height: var(--ctl);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body-compact);
}

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

.afw-input::placeholder,
.afw-textarea::placeholder {
  color: var(--text-faint);
}

.afw-hint {
  font-size: var(--fs-caption);
  color: var(--text-faint);
}

.afw-error-text {
  font-size: var(--fs-caption);
  color: var(--err);
}

/* ---------- 카드·패널 ---------- */

.afw-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-5);
}

.afw-card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.afw-card-head h2,
.afw-card-head h3 {
  font-size: var(--fs-section);
}

.afw-card-head .afw-spacer {
  margin-left: auto;
}

/* ---------- 배지·칩 ---------- */

.afw-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--fs-caption);
  line-height: 18px;
  white-space: nowrap;
}

.afw-badge.is-ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

.afw-badge.is-warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
}

.afw-badge.is-err {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 45%, transparent);
}

.afw-badge.is-info {
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
}

.afw-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: var(--ctl-compact);
  padding: 0 var(--sp-3);
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-compact);
  cursor: pointer;
}

.afw-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

/* ---------- 수치 ---------- */

.afw-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.afw-up {
  color: var(--up);
}

.afw-down {
  color: var(--down);
}

.afw-flat {
  color: var(--flat);
}

/* ---------- 상태 표기 ---------- */

.afw-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}

.afw-state-title {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text);
}

.afw-state-desc {
  font-size: var(--fs-body-compact);
  max-width: 40ch;
}

.afw-skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-hover) 37%,
    var(--surface) 63%
  );
  background-size: 400% 100%;
  animation: afw-shimmer 1.4s ease-in-out infinite;
}

@keyframes afw-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .afw-skeleton {
    animation: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}

.afw-source {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-caption);
  color: var(--text-faint);
}

/* ---------- 표 ---------- */

.afw-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.afw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body-compact);
}

.afw-table th,
.afw-table td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.afw-table th {
  position: sticky;
  top: 0;
  background: var(--bg-raised);
  color: var(--text-muted);
  font-size: var(--fs-compact);
  font-weight: 600;
  z-index: 1;
}

.afw-table td.is-num,
.afw-table th.is-num {
  text-align: right;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.afw-table tbody tr:hover {
  background: var(--surface-hover);
}

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

/* ---------- 다이얼로그 ---------- */

.afw-dialog {
  width: min(560px, calc(100vw - var(--sp-8)));
  max-height: min(80vh, 760px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--bg-raised);
  color: var(--text);
  overflow: hidden;
}

.afw-dialog::backdrop {
  background: rgba(4, 7, 12, 0.62);
  backdrop-filter: blur(2px);
}

.afw-dialog-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
}

.afw-dialog-head h2 {
  font-size: var(--fs-section);
}

.afw-dialog-body {
  padding: var(--sp-5);
  overflow-y: auto;
  max-height: calc(80vh - 128px);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.afw-dialog-foot {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--line);
}

/* ---------- 토스트 ---------- */

.afw-toasts {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.afw-toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 360px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-body-compact);
  pointer-events: auto;
}

.afw-toast.is-ok {
  border-color: color-mix(in srgb, var(--ok) 50%, transparent);
}

.afw-toast.is-err {
  border-color: color-mix(in srgb, var(--err) 50%, transparent);
}

.afw-toast button {
  margin-left: auto;
}

/* ---------- 레이아웃 유틸 ---------- */

.afw-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4) var(--sp-16);
}

.afw-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

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

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

.afw-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.afw-footer {
  border-top: 1px solid var(--line);
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-faint);
  font-size: var(--fs-compact);
}

.afw-footer nav {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .afw-header {
    height: auto;
    flex-wrap: wrap;
    padding: var(--sp-2) var(--sp-3);
    gap: var(--sp-2);
  }

  .afw-header nav {
    order: 3;
    width: 100%;
  }

  .afw-header nav a {
    min-height: var(--ctl-touch);
  }

  .afw-btn {
    min-height: var(--ctl-touch);
  }

  .afw-shell {
    padding: var(--sp-4) var(--sp-3) var(--sp-12);
  }
}
