/* RankFinder 보조 스타일 — Untitled UI + shadcn 톤 + Pretendard */

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', sans-serif;
  letter-spacing: -0.01em;
}

/* === 60대 가독성 강화 — 회색 톤 모두 진하게, 옅은 톤 제거 === */
.text-gray-300 { color: #1D2939 !important; }   /* 원래 옅은 회색 → 거의 검정 */
.text-gray-400 { color: #1D2939 !important; }
.text-gray-500 { color: #101828 !important; }
.text-gray-600 { color: #101828 !important; }
.text-gray-700 { color: #000000 !important; }
.text-gray-800 { color: #000000 !important; }
.text-gray-900 { color: #000000 !important; }

/* slate 도 동일 처리 */
.text-slate-300 { color: #1D2939 !important; }
.text-slate-400 { color: #1D2939 !important; }
.text-slate-500 { color: #101828 !important; }
.text-slate-600 { color: #101828 !important; }
.text-slate-700 { color: #000000 !important; }
.text-slate-800 { color: #000000 !important; }
.text-slate-900 { color: #000000 !important; }

/* placeholder */
input::placeholder, textarea::placeholder { color: #475467 !important; font-weight: 500; }

/* 한글 굵은 weight 강화 — 60대 가독성: 제목 사이즈도 키움 */
h1 { font-size: 32px !important; font-weight: 900 !important; letter-spacing: -0.025em; }
h2 { font-size: 24px !important; font-weight: 900 !important; letter-spacing: -0.025em; }
h3 { font-size: 18px !important; font-weight: 800 !important; letter-spacing: -0.02em; }
.text-2xl { font-size: 26px !important; font-weight: 800; }
.text-3xl { font-size: 32px !important; font-weight: 900; }
.text-4xl { font-size: 40px !important; font-weight: 900; }
.text-xl { font-size: 20px !important; }
.text-lg { font-size: 18px !important; }
.text-base { font-size: 16px !important; }
.text-sm { font-size: 14.5px !important; }
.text-xs { font-size: 13px !important; }

/* 매우 작은 인라인 폰트도 살짝 키움 (60대 시력 보조) */
.text-\[9px\] { font-size: 11px !important; }
.text-\[9\.5px\] { font-size: 11.5px !important; }
.text-\[10px\] { font-size: 12px !important; }
.text-\[10\.5px\] { font-size: 12px !important; }
.text-\[11px\] { font-size: 12.5px !important; }
.text-\[11\.5px\] { font-size: 13px !important; }
.text-\[12px\] { font-size: 13.5px !important; }
.text-\[12\.5px\] { font-size: 14px !important; }
.text-\[13px\] { font-size: 14.5px !important; }
.text-\[13\.5px\] { font-size: 15px !important; }
.text-\[14px\] { font-size: 15px !important; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-black, [data-kpi] { font-weight: 900; letter-spacing: -0.025em; }
/* body 기본 폰트도 살짝 키움 */
body { font-size: 15px; line-height: 1.6; }

/* ===== 매트릭스 표 ===== */
.matrix-table { border-collapse: separate; border-spacing: 0; }
.matrix-table th,
.matrix-table td { border-bottom: 1px solid #F2F4F7; }
.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky; left: 0; background: #fff; z-index: 1;
  min-width: 150px; max-width: 220px;
}
.matrix-table thead th {
  background: #F9FAFB; font-weight: 700; color: #1D2939;
  font-size: 12px; padding: 9px 12px; white-space: nowrap;
  border-bottom: 1px solid #EAECF0;
  letter-spacing: 0;
}
.matrix-table thead th.today { background: #EFF6FF; color: #1D4ED8; }
.matrix-table tbody td { padding: 7px 12px; font-size: 13px; vertical-align: middle; }
.matrix-table tbody tr:nth-child(even) td { background: #FCFCFD; }
.matrix-table tbody tr:nth-child(even) td:first-child { background: #FCFCFD; }
.matrix-table tbody td.today { background: #F5F8FF !important; }
.matrix-table tbody tr:hover td { background: #EFF6FF !important; cursor: pointer; }
.matrix-table tbody tr:hover td.today { background: #DBEAFE !important; }
.matrix-table tbody tr.kw-main td { background: #F5F8FF !important; }
.matrix-table tbody tr.kw-main td:first-child { box-shadow: 3px 0 0 0 #2563EB inset, 1px 0 0 0 #F2F4F7; }

/* ===== 랭크 셀 — 컴팩트 (PC/M 한 줄에) ===== */
.rank-cell { display: flex; flex-direction: column; gap: 2px; align-items: center; line-height: 1; }
.rank-line { display: inline-flex; align-items: center; gap: 5px; line-height: 1.1; position: relative; }
.rank-line .label {
  font-size: 10px; color: #667085; width: 14px; font-weight: 800;
  letter-spacing: 0.04em;
}
.rank-line .num {
  font-weight: 700; min-width: 22px; text-align: right; color: #101828;
  font-variant-numeric: tabular-nums; font-size: 13px;
}
.rank-line.mo .num { color: #344054; font-weight: 600; }
.rank-line .delta { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: #12B76A; }
.delta.down { color: #F04438; }
.dim { color: #D0D5DD; font-weight: 400; }

.ad-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 9999px; background: #2563EB; margin-left: 2px;
}

/* sticky 컬럼 미세 그림자 */
.matrix-table tbody td:first-child { box-shadow: 1px 0 0 0 #F2F4F7; }
.matrix-table thead th:first-child { box-shadow: 1px 0 0 0 #EAECF0; }

/* ===== 모바일 반응형 ===== */
@media (max-width: 640px) {
  .matrix-table th:first-child,
  .matrix-table td:first-child { min-width: 120px; max-width: 160px; }
  .matrix-table thead th { padding: 6px 8px; font-size: 10px; }
  .matrix-table tbody td { padding: 6px 8px; font-size: 11px; }
  .rank-line .label { display: none; }
  .rank-line .num { min-width: 18px; }
}

/* ===== 확장 수집 중 회전 스피너 ===== */
.rf-spin { animation: rf-spin 0.8s linear infinite; }
@keyframes rf-spin { to { transform: rotate(360deg); } }

/* ===== 추출된 키워드 그리드 칩 hover ===== */
#kwExtractedGrid label { transition: all 0.12s; }
#kwExtractedGrid label:hover { border-color: #93C5FD; background: #EFF6FF; }

/* ===== 셀렉트 화살표 일관화 ===== */
select { appearance: none; -webkit-appearance: none; padding-right: 2rem;
  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='%23667085' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.5rem center;
}

/* ===== 스크롤바 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D0D5DD; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #98A2B3; }

/* ====================================================== */
/* ===== 🎨 Doya Design Tokens — 시맨틱 변수 (★5 Phase 1) ===== */
/* ====================================================== */
/*
  All tokens are scoped to `:root` (light) and overridden in `html.dark`.
  Naming pattern: --color-{purpose}-{level} | --space-{size} | --motion-{speed}
  Single source of truth — Tailwind config 색은 보조용.
*/

:root {
  /* ─── Motion ─── */
  --motion-fast: 150ms;
  --motion-normal: 250ms;
  --motion-slow: 400ms;
  --easing: cubic-bezier(0.4, 0, 0.2, 1);
  --easing-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* ─── Surfaces (배경 — 라이트) ─── */
  --color-bg-page: #FAFBFF;             /* body */
  --color-bg-surface: #FFFFFF;          /* 카드 기본 */
  --color-bg-elevated: #FFFFFF;         /* 모달/팝오버 */
  --color-bg-sunken: #F9FAFB;           /* 입력칸/info 배경 */
  --color-bg-strong: #F2F4F7;           /* 호버/액티브 강조 */

  /* ─── Text (라이트) ─── */
  --color-text-primary: #0F1419;        /* WCAG AAA 본문 */
  --color-text-secondary: #344054;
  --color-text-tertiary: #475467;
  --color-text-disabled: #98A2B3;
  --color-text-inverse: #FFFFFF;

  /* ─── Borders ─── */
  --color-border-subtle: #F2F4F7;
  --color-border-default: #EAECF0;
  --color-border-strong: #D0D5DD;

  /* ─── Brand (의미 컬러) ─── */
  --color-brand-default: #2563EB;
  --color-brand-hover: #1D4ED8;
  --color-brand-subtle: rgba(37, 99, 235, 0.08);
  --color-brand-text: #1D4ED8;
  --color-brand-border: #93C5FD;

  --color-success: #10B981;
  --color-success-subtle: rgba(16, 185, 129, 0.10);
  --color-success-text: #047857;
  --color-success-border: #6EE7B7;

  --color-error: #EF4444;
  --color-error-subtle: rgba(239, 68, 68, 0.10);
  --color-error-text: #B42318;
  --color-error-border: #FCA5A5;

  --color-warning: #F59E0B;
  --color-warning-subtle: rgba(245, 158, 11, 0.10);
  --color-warning-text: #B45309;
  --color-warning-border: #FCD34D;

  --color-shopping: #F97316;             /* 쇼핑/주황 */
  --color-shopping-subtle: rgba(249, 115, 22, 0.10);
  --color-shopping-text: #C2410C;
  --color-shopping-border: #FDBA74;

  --color-analysis: #A855F7;             /* 분석/보라 */
  --color-analysis-subtle: rgba(168, 85, 247, 0.10);
  --color-analysis-text: #7E22CE;
  --color-analysis-border: #D8B4FE;

  --color-focus: #2563EB;
  --color-focus-ring: rgba(37, 99, 235, 0.20);

  /* ─── Shadow ─── */
  --shadow-xs: 0 1px 2px 0 rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(16, 24, 40, 0.10), 0 1px 2px 0 rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, 0.10), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.03);

  /* ─── Radius ─── */
  --radius-sm: 0.375rem;     /* 6px */
  --radius-md: 0.5rem;       /* 8px */
  --radius-lg: 0.75rem;      /* 12px */
  --radius-xl: 1rem;          /* 16px */
  --radius-2xl: 1.25rem;      /* 20px */
}

/* ─── 다크모드 토큰 override ─── */
html.dark {
  --color-bg-page: #0B1220;
  --color-bg-surface: #0F172A;
  --color-bg-elevated: #0F172A;
  --color-bg-sunken: #1E293B;
  --color-bg-strong: #334155;

  --color-text-primary: #F8FAFC;       /* WCAG AAA on dark */
  --color-text-secondary: #E2E8F0;
  --color-text-tertiary: #CBD5E1;
  --color-text-disabled: #64748B;
  --color-text-inverse: #0F172A;

  --color-border-subtle: #1E293B;
  --color-border-default: #334155;
  --color-border-strong: #475569;

  --color-brand-default: #3B82F6;
  --color-brand-hover: #60A5FA;
  --color-brand-subtle: rgba(96, 165, 250, 0.12);
  --color-brand-text: #93C5FD;
  --color-brand-border: rgba(96, 165, 250, 0.40);

  --color-success: #34D399;
  --color-success-subtle: rgba(52, 211, 153, 0.12);
  --color-success-text: #6EE7B7;
  --color-success-border: rgba(74, 222, 128, 0.35);

  --color-error: #F87171;
  --color-error-subtle: rgba(248, 113, 113, 0.12);
  --color-error-text: #FCA5A5;
  --color-error-border: rgba(248, 113, 113, 0.35);

  --color-warning: #FBBF24;
  --color-warning-subtle: rgba(251, 191, 36, 0.12);
  --color-warning-text: #FDE68A;
  --color-warning-border: rgba(252, 211, 77, 0.40);

  --color-shopping: #FB923C;
  --color-shopping-subtle: rgba(251, 146, 60, 0.12);
  --color-shopping-text: #FED7AA;
  --color-shopping-border: rgba(251, 146, 60, 0.40);

  --color-analysis: #C084FC;
  --color-analysis-subtle: rgba(192, 132, 252, 0.12);
  --color-analysis-text: #D8B4FE;
  --color-analysis-border: rgba(192, 132, 252, 0.40);

  --color-focus: #60A5FA;
  --color-focus-ring: rgba(96, 165, 250, 0.30);

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.30);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.40), 0 1px 2px 0 rgba(0, 0, 0, 0.30);
  --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.40), 0 2px 4px -2px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 12px 16px -4px rgba(0, 0, 0, 0.40), 0 4px 6px -2px rgba(0, 0, 0, 0.30);
}

/* ─── 토큰 기반 유틸 클래스 (신규 코드에서 사용) ─── */
.surface { background: var(--color-bg-surface); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl); box-shadow: var(--shadow-xs); }
.surface-elevated { background: var(--color-bg-elevated); box-shadow: var(--shadow-lg); }
.surface-sunken { background: var(--color-bg-sunken); }
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }
.border-default { border-color: var(--color-border-default); }

/* ====================================================== */
/* ===== Accessibility + Motion 글로벌 (전문가 평가 반영) ===== */
/* ====================================================== */

/* 키보드 포커스 — 글로벌 outline */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: 0.5rem;
}
button:focus-visible,
a:focus-visible {
  box-shadow: 0 0 0 4px rgb(37 99 235 / 0.20);
  outline-offset: 2px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline-offset: 0;
}

/* 모션 줄이기 — 글로벌 적용 (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* transition 시간 통일 — utility 클래스 */
.transition-fast { transition-duration: var(--motion-fast) !important; transition-timing-function: var(--easing); }
.transition-normal { transition-duration: var(--motion-normal) !important; transition-timing-function: var(--easing); }
.transition-slow { transition-duration: var(--motion-slow) !important; transition-timing-function: var(--easing); }

/* card-interactive 시간 통일 */
.card-interactive { transition: background var(--motion-normal) var(--easing),
                                 transform var(--motion-normal) var(--easing),
                                 box-shadow var(--motion-normal) var(--easing),
                                 border-color var(--motion-normal) var(--easing); }

/* input-glow 시간 통일 */
.input-glow { transition: all var(--motion-fast) var(--easing); }

/* 매트릭스 셀 hover */
table.matrix-table tbody td { transition: background-color var(--motion-fast) var(--easing); }

/* text-gradient 접근성 — 24px 이상에만 적용 (작은 사이즈는 단색 fallback) */
@media (max-width: 100px) { /* never matches — 자리표시 */ }
.text-gradient-brand, .text-gradient-success,
.text-gradient-error, .text-gradient-orange {
  /* 작은 사이즈는 그라데이션 안 보여서 fallback */
  text-shadow: none;
}
/* sr-only 단순화 */
.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;
}

/* WCAG AA 대비 보강 — 옅은 그라데이션 카드 위 텍스트 진하게 */
.card-hero-mesh .text-gray-500,
.card-hero-mesh-orange .text-gray-500,
[class*="from-orange-50"] .text-gray-500,
[class*="from-brand-50"] .text-gray-500 { color: #1D2939 !important; }

/* B2B SaaS 패딩 축소 — 헤더 컴팩트 */
#mainHeader { padding-top: 0; padding-bottom: 0; }

/* 키워드 조회 모드 — 헤더 sticky 해제 (검색 박스 내부에 자체 제목 있음, 중복 방지) */
body.view-keyword-search #mainHeader { position: static !important; }
body.view-keyword-search #mainHeader { display: none !important; }

/* 키워드 조회 — 검색 후 상단 검색 박스 자동 압축 (공간 절약) */
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child {
  padding: 0.75rem 1rem !important;
  margin-bottom: 0.5rem !important;
}
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child h3,
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child p {
  font-size: 0.75rem !important;
}
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child > div:first-child {
  margin-bottom: 0.25rem !important;
}
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child > p {
  display: none !important;
}
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child > div:nth-of-type(2) input,
body.view-keyword-search.kw-has-result #keywordSearchMode > section:first-child > div:nth-of-type(2) button {
  padding-top: 0.4rem !important;
  padding-bottom: 0.4rem !important;
  font-size: 0.8rem !important;
  min-height: 32px !important;
}

/* Loading skeleton */
@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, #F2F4F7 0%, #EAECF0 50%, #F2F4F7 100%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: 0.5rem;
  color: transparent !important;
  user-select: none;
}
.skeleton-text { height: 0.875rem; }
.skeleton-text--lg { height: 1.5rem; }
.skeleton-block { width: 100%; height: 8rem; }

/* ===== 모바일 사이드바 ===== */
@media (max-width: 1023px) {
  .main-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0;
    width: 240px !important;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--motion-normal) var(--easing);
    box-shadow: 8px 0 24px rgba(0,0,0,0.12);
    height: 100vh !important;
  }
  .main-sidebar.open {
    transform: translateX(0);
  }
}
@media (min-width: 1024px) {
  #mobileNavBtn, #mobileNavBackdrop { display: none !important; }
}

/* ===== ⌘K Command Palette ===== */
#cmdkModal { animation: cmdk-fade-in var(--motion-fast) var(--easing); }
@keyframes cmdk-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
#cmdkModal > div { animation: cmdk-slide-in var(--motion-normal) var(--easing); }
@keyframes cmdk-slide-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.cmdk-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 1rem;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--motion-fast), border-color var(--motion-fast);
}
.cmdk-item:hover, .cmdk-item.active {
  background: rgb(239 246 255);
  border-left-color: var(--color-focus);
}
.cmdk-item .cmdk-icon {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #F2F4F7; color: #475467;
  border-radius: 6px; font-size: 12px;
}
.cmdk-item.active .cmdk-icon { background: #DBEAFE; color: #1D4ED8; }
.cmdk-section-title {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 10px; font-weight: 800;
  color: #98A2B3; text-transform: uppercase; letter-spacing: 0.05em;
}

/* ====================================================== */
/* ===== 🌙 다크모드 (`.dark` 클래스 토글) ===== */
/* ====================================================== */
html.dark {
  color-scheme: dark;
  --color-focus: #60A5FA;
}
html.dark body { color: #E5E7EB; }

/* body mesh — 다크 톤 */
html.dark body.gradient-mesh {
  background-color: #0B1220;
  background-image:
    radial-gradient(at 8% 0%, rgba(59, 130, 246, 0.18) 0%, transparent 45%),
    radial-gradient(at 92% 12%, rgba(251, 146, 60, 0.10) 0%, transparent 50%),
    radial-gradient(at 50% 100%, rgba(168, 85, 247, 0.12) 0%, transparent 55%),
    radial-gradient(at 0% 60%, rgba(34, 211, 238, 0.08) 0%, transparent 50%);
}

/* 회색 텍스트 override (light에서 진하게 됐던 걸 다크에서는 밝게) */
html.dark .text-gray-400,
html.dark .text-slate-400 { color: #94A3B8 !important; }
html.dark .text-gray-500,
html.dark .text-slate-500 { color: #CBD5E1 !important; }
html.dark .text-gray-600,
html.dark .text-slate-600 { color: #E2E8F0 !important; }
html.dark .text-gray-700,
html.dark .text-slate-700 { color: #F1F5F9 !important; }
html.dark .text-gray-800,
html.dark .text-gray-900,
html.dark .text-slate-800,
html.dark .text-slate-900 { color: #FFFFFF !important; }
html.dark .border-slate-200 { border-color: #334155 !important; }
html.dark .bg-slate-50 { background-color: #1E293B !important; }
html.dark .bg-slate-100 { background-color: #334155 !important; }
html.dark input::placeholder, html.dark textarea::placeholder { color: #94A3B8 !important; }

/* 카드 배경 — 흰색 → 다크 surface */
html.dark .bg-white { background-color: #0F172A !important; }
html.dark [class*="from-white"] { background-image: none !important; background-color: #0F172A !important; }

/* 테두리 */
html.dark .border-gray-100 { border-color: #1E293B !important; }
html.dark .border-gray-200 { border-color: #334155 !important; }
html.dark .border-gray-300 { border-color: #475569 !important; }
html.dark .border-brand-200 { border-color: rgba(96, 165, 250, 0.4) !important; }
html.dark .border-brand-300 { border-color: rgba(96, 165, 250, 0.5) !important; }
html.dark .border-success-200 { border-color: rgba(74, 222, 128, 0.35) !important; }
html.dark .border-error-200 { border-color: rgba(248, 113, 113, 0.35) !important; }
html.dark .border-orange-200 { border-color: rgba(251, 146, 60, 0.4) !important; }
html.dark .border-orange-300 { border-color: rgba(251, 146, 60, 0.55) !important; }
html.dark .border-purple-200 { border-color: rgba(192, 132, 252, 0.4) !important; }
html.dark .border-amber-200 { border-color: rgba(252, 211, 77, 0.4) !important; }

/* 사이드바 */
html.dark .main-sidebar {
  background: linear-gradient(180deg, #0F172A 0%, #0F172A 60%, rgba(30, 41, 59, 0.6) 100%) !important;
  border-right-color: #1E293B !important;
}

/* 글래스 헤더 */
html.dark header.glass-header {
  background: linear-gradient(90deg,
    rgba(15, 23, 42, 0.85),
    rgba(30, 58, 138, 0.45),
    rgba(15, 23, 42, 0.85)) !important;
  border-bottom-color: #1E293B !important;
}

/* KPI 카드 mesh */
html.dark .card-hero-mesh {
  background:
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.20) 0%, transparent 50%),
    radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.15) 0%, transparent 50%),
    radial-gradient(at 100% 100%, rgba(34, 211, 238, 0.12) 0%, transparent 50%),
    #0F172A !important;
}
html.dark .card-hero-mesh-orange {
  background:
    radial-gradient(at 0% 0%, rgba(251, 146, 60, 0.20) 0%, transparent 50%),
    radial-gradient(at 100% 0%, rgba(252, 211, 77, 0.15) 0%, transparent 50%),
    radial-gradient(at 100% 100%, rgba(251, 146, 60, 0.12) 0%, transparent 55%),
    #1A1410 !important;
}

/* 카드 그라데이션 (KPI 등) — 다크 톤으로 자동 변환 */
html.dark [class*="from-brand-50"] {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.10), rgba(15, 23, 42, 1), rgba(59, 130, 246, 0.04)) !important;
}
html.dark [class*="from-success-50"] {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.10), rgba(15, 23, 42, 1), rgba(16, 185, 129, 0.04)) !important;
}
html.dark [class*="from-error-50"] {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.10), rgba(15, 23, 42, 1), rgba(244, 63, 94, 0.04)) !important;
}
html.dark [class*="from-orange-50"] {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.12), rgba(20, 14, 8, 1), rgba(252, 211, 77, 0.06)) !important;
}
html.dark [class*="from-purple-50"] {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.10), rgba(15, 23, 42, 1), rgba(96, 165, 250, 0.06)) !important;
}
html.dark [class*="from-amber-50"] {
  background: linear-gradient(135deg, rgba(252, 211, 77, 0.10), rgba(20, 14, 8, 1), rgba(251, 146, 60, 0.06)) !important;
}
html.dark [class*="from-slate-50"] {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.06), rgba(15, 23, 42, 1), rgba(71, 85, 105, 0.04)) !important;
}

/* 회색 배경 (gray-50/100/etc) */
html.dark .bg-gray-50 { background-color: #1E293B !important; }
html.dark .bg-gray-100 { background-color: #334155 !important; }
html.dark .bg-gray-200 { background-color: #475569 !important; }

/* 컬러 배지 배경 */
html.dark .bg-brand-50 { background-color: rgba(59, 130, 246, 0.15) !important; }
html.dark .bg-brand-100 { background-color: rgba(59, 130, 246, 0.25) !important; }
html.dark .bg-success-50 { background-color: rgba(34, 197, 94, 0.15) !important; }
html.dark .bg-success-100 { background-color: rgba(34, 197, 94, 0.25) !important; }
html.dark .bg-error-50 { background-color: rgba(239, 68, 68, 0.15) !important; }
html.dark .bg-error-100 { background-color: rgba(239, 68, 68, 0.25) !important; }
html.dark .bg-warning-50 { background-color: rgba(245, 158, 11, 0.15) !important; }
html.dark .bg-orange-50 { background-color: rgba(251, 146, 60, 0.15) !important; }
html.dark .bg-amber-50 { background-color: rgba(252, 211, 77, 0.15) !important; }
html.dark .bg-purple-50 { background-color: rgba(168, 85, 247, 0.15) !important; }

/* 컬러 텍스트 — 다크에서 더 밝게 */
html.dark .text-brand-600, html.dark .text-brand-700 { color: #93C5FD !important; }
html.dark .text-success-700, html.dark .text-up { color: #6EE7B7 !important; }
html.dark .text-error-700, html.dark .text-down { color: #FCA5A5 !important; }
html.dark .text-orange-700, html.dark .text-orange-800 { color: #FED7AA !important; }
html.dark .text-amber-700, html.dark .text-amber-800 { color: #FDE68A !important; }
html.dark .text-purple-600, html.dark .text-purple-700 { color: #D8B4FE !important; }
html.dark .text-cyan-700 { color: #67E8F9 !important; }

/* 매트릭스 표 */
html.dark .matrix-table th:first-child,
html.dark .matrix-table td:first-child { background: #0F172A !important; color: #F1F5F9 !important; }
html.dark .matrix-table thead th { background: #1E293B !important; color: #F1F5F9 !important; border-bottom-color: #334155 !important; }
html.dark .matrix-table th,
html.dark .matrix-table td { border-bottom-color: #1E293B !important; }
html.dark table.matrix-table tbody tr:hover td:not(:first-child) { background-color: rgba(59, 130, 246, 0.10) !important; }
html.dark table.matrix-table tbody td:hover:not(:first-child) { background-color: rgba(59, 130, 246, 0.18) !important; }

/* 입력칸 */
html.dark input, html.dark textarea, html.dark select {
  background-color: #1E293B !important;
  border-color: #334155 !important;
  color: #F1F5F9 !important;
}

/* ⌘K 팔레트 */
html.dark #cmdkModal { background: rgba(0, 0, 0, 0.65) !important; }
html.dark #cmdkModal > div { background: #0F172A !important; border-color: #334155 !important; }
html.dark .cmdk-item:hover, html.dark .cmdk-item.active {
  background: rgba(59, 130, 246, 0.15) !important;
  border-left-color: #60A5FA !important;
}
html.dark .cmdk-item .cmdk-icon { background: #1E293B !important; color: #94A3B8 !important; }
html.dark .cmdk-item.active .cmdk-icon { background: rgba(59, 130, 246, 0.25) !important; color: #93C5FD !important; }
html.dark .cmdk-section-title { color: #64748B !important; }

/* Skeleton 다크 */
html.dark .skeleton {
  background: linear-gradient(90deg, #1E293B 0%, #334155 50%, #1E293B 100%) !important;
  background-size: 200% 100% !important;
}

/* 사이드바 strip */
html.dark aside.with-strip::before {
  background: linear-gradient(180deg, #60A5FA 0%, #C084FC 50%, #FB923C 100%) !important;
}

/* 셀렉트 화살표 (다크 배경에 맞춰 밝게) */
html.dark select {
  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='%2394A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
}

/* 스크롤바 다크 */
html.dark ::-webkit-scrollbar-thumb { background: #475569 !important; }
html.dark ::-webkit-scrollbar-thumb:hover { background: #64748B !important; }

/* 모바일 nav 햄버거 (다크 시 톤 보정) */
html.dark #mobileNavBtn { background: #0F172A !important; color: #E2E8F0 !important; }
html.dark #mobileNavBackdrop { background-color: rgba(0,0,0,0.6) !important; }

/* 모달 다크 (.bg-white 위에서 강제 override 안되는 케이스 보강) */
html.dark .fixed.inset-0 > div.bg-white,
html.dark [role="dialog"] .bg-white { background-color: #0F172A !important; }

/* amber 알림바 (매트릭스 상단 안내 등) */
html.dark .bg-amber-50\/60 { background-color: rgba(245, 158, 11, 0.12) !important; }
html.dark .bg-amber-50\/40 { background-color: rgba(245, 158, 11, 0.10) !important; }
html.dark .border-amber-100 { border-color: rgba(245, 158, 11, 0.25) !important; }
html.dark .text-amber-800 { color: #FDE68A !important; }

/* 카탈로그 묶임 알림 카드 등 */
html.dark .bg-blue-50, html.dark .bg-blue-50\/40 { background-color: rgba(59, 130, 246, 0.12) !important; }
html.dark .text-blue-700, html.dark .text-blue-800 { color: #93C5FD !important; }
html.dark .border-blue-100, html.dark .border-blue-200 { border-color: rgba(59, 130, 246, 0.3) !important; }

/* 빈 상태 카드 다크 */
html.dark .empty-state {
  background: linear-gradient(135deg, rgba(59,130,246,0.10), #0F172A, rgba(168,85,247,0.08)) !important;
  border-color: rgba(96, 165, 250, 0.3) !important;
}
html.dark .empty-state .empty-icon {
  background: linear-gradient(135deg, rgba(59,130,246,0.25), rgba(99,102,241,0.20)) !important;
  color: #93C5FD !important;
  box-shadow: 0 8px 16px -4px rgba(59, 130, 246, 0.30) !important;
}

/* purple 톤 카드 (광고 컨설팅 등) */
html.dark .bg-purple-50\/60, html.dark .bg-purple-50\/40 { background-color: rgba(168, 85, 247, 0.12) !important; }

/* success-50 / emerald-50 (filter card 등) */
html.dark .bg-success-50\/50, html.dark .bg-success-50\/40 { background-color: rgba(34, 197, 94, 0.10) !important; }
html.dark .bg-emerald-50\/20, html.dark .bg-emerald-50\/30 { background-color: rgba(16, 185, 129, 0.08) !important; }

/* gradient 카드 — 키워드 조회 selfCard 등 from-orange-50 톤 강제 보강 */
html.dark .from-orange-50,
html.dark .via-white,
html.dark .to-amber-50 { /* via-white이 light에서 강제로 들어가는 경우 */
  /* gradient 자체는 .from-* 셀렉터로 위에서 처리됨 — 여기는 다층 안전망 */
}

/* matrix table 본문 td 텍스트 */
html.dark .matrix-table td .text-gray-600,
html.dark .matrix-table td .text-gray-500 { color: #E2E8F0 !important; }

/* 키워드 조회 결과 카드 — 진단/테이블 영역 */
html.dark [data-seo-guide-card] {
  background:
    radial-gradient(at 0% 0%, rgba(251, 146, 60, 0.12) 0%, transparent 50%),
    radial-gradient(at 100% 0%, rgba(252, 211, 77, 0.08) 0%, transparent 50%),
    #1A1410 !important;
}

/* 키워드 카테고리 셀 텍스트 */
html.dark [data-kw-category] .text-gray-800 { color: #F1F5F9 !important; }
html.dark [data-kw-category] .text-gray-300 { color: #64748B !important; }

/* 광고 컨설팅 진단의 cyan 톤 카드 */
html.dark .border-cyan-200 { border-color: rgba(34, 211, 238, 0.35) !important; }
html.dark .bg-cyan-50 { background-color: rgba(34, 211, 238, 0.12) !important; }

/* 추천 키워드 행 (success 톤 뱃지 등) */
html.dark .ring-success-200 { box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.35) !important; }
html.dark .ring-gray-200 { box-shadow: inset 0 0 0 1px #334155 !important; }
html.dark .ring-gray-300 { box-shadow: inset 0 0 0 1px #475569 !important; }

/* 키워드 검색 토글 버튼 (필터 켰을 때 등) */
html.dark .bg-brand-600 { background-color: #2563EB !important; }
html.dark .bg-brand-600:hover { background-color: #1D4ED8 !important; }

/* 그라데이션 버튼 다크 (변경 없음 - 가시성 OK) */

/* kbd (단축키 표시) */
html.dark kbd { background-color: #1E293B !important; color: #94A3B8 !important; border-color: #334155 !important; }

/* ===== Number Rolling 애니메이션 ===== */
@keyframes number-pop {
  0% { transform: translateY(8px); opacity: 0; }
  60% { transform: translateY(-2px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}
.number-roll {
  display: inline-block;
  animation: number-pop 600ms cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: both;
}

/* ===== Success/Error micro-animations ===== */
@keyframes success-pop {
  0% { transform: scale(0.6); opacity: 0; }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.animate-success { animation: success-pop 400ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.animate-error { animation: error-shake 400ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }

/* ===== View transition (페이지 전환) ===== */
@supports (view-transition-name: none) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 250ms;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  }
  ::view-transition-old(root) { animation-name: fade-out; }
  ::view-transition-new(root) { animation-name: fade-in; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ====================================================== */
/* ===== ♿ WCAG AAA 강화 + 터치 타겟 44px ===== */
/* ====================================================== */
/* 모바일 터치 타겟 — 작은 버튼/링크 최소 36px (sidebar 등) / 핵심 44px */
@media (pointer: coarse) {
  button:not(.text-\[9px\]):not(.text-\[10px\]):not(.cmdk-item):not([data-tier-filter]),
  a:not(.text-\[9px\]):not(.text-\[10px\]):not(.text-\[11px\]),
  select { min-height: 36px; }
  /* 메인 액션 버튼은 44px */
  #addProductTopBtn, #kwSearchBtn, #addProductEmptyBtn, .btn-gradient-brand { min-height: 44px; }
}

/* 매트릭스 모바일 — 가로 스크롤 최적화 */
@media (max-width: 640px) {
  .matrix-table { font-size: 11px; }
  .matrix-table th:first-child,
  .matrix-table td:first-child { min-width: 110px; max-width: 130px; }
  .matrix-table th, .matrix-table td { padding: 5px 6px; }
}

/* WCAG AAA — 본문 텍스트 컬러 강화 (4.5:1 → 7:1) */
body { color: #0F1419; }
html.dark body { color: #F8FAFC; }

/* aria-disabled 시각 표현 */
[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed !important; }

/* ===== Success Toast 강조 (성공 시 부드러운 위로 pop) ===== */
#toast.animate-success {
  border: 2px solid #10B981;
  background: linear-gradient(135deg, #ECFDF3, #ffffff);
  color: #047857;
}
html.dark #toast.animate-success {
  background: linear-gradient(135deg, rgba(16,185,129,0.20), #0F172A);
  border-color: #10B981;
  color: #6EE7B7;
}
#toast.animate-error {
  border: 2px solid #F04438;
  background: linear-gradient(135deg, #FEF2F2, #ffffff);
  color: #B42318;
}
html.dark #toast.animate-error {
  background: linear-gradient(135deg, rgba(239,68,68,0.20), #0F172A);
  border-color: #F04438;
  color: #FCA5A5;
}

/* ===== Empty state — 친절 카드 ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: linear-gradient(135deg, rgba(239,246,255,0.5), white, rgba(243,232,255,0.3));
  border: 1px dashed #BFDBFE;
  border-radius: 1rem;
}
.empty-state .empty-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #DBEAFE, #E0E7FF);
  color: #2563EB;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin-bottom: 0.75rem;
  box-shadow: 0 8px 16px -4px rgba(37,99,235,0.18);
}
