/* ── CSS 변수 ─────────────────────────────────────────────────── */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --orange: #f97316;
  --purple: #8b5cf6;
  --cyan: #06b6d4;

  /* TEE 컴포넌트 색상 */
  --hr-color: #3b82f6;
  --stee-color: #f97316;
  --ctee-color: #f59e0b;
  --db-color: #8b5cf6;
}

/* ── 리셋 & 기본 ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── 헤더 ─────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
}

.header-inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  height: 40px;
  width: auto;
  display: block;
}

.header-title h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.header-title p {
  font-size: 12px;
  color: var(--text-dim);
}

.header-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green {
  background: rgba(34, 197, 94, .15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, .3);
}

.badge-blue {
  background: rgba(59, 130, 246, .15);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, .3);
}

/* ── 레이아웃 ─────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* ── 패널 공통 ────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  overflow-y: auto;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.panel-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* ── 쿼리 패널 ────────────────────────────────────────────────── */
.query-category {
  margin-bottom: 14px;
}

.query-category-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.query-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  margin-bottom: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .18s;
}

.query-btn:hover {
  border-color: var(--blue);
  background: rgba(59, 130, 246, .1);
}

.query-btn.active {
  border-color: var(--blue);
  background: rgba(59, 130, 246, .15);
  box-shadow: 0 0 0 1px var(--blue);
}

.query-btn.blocked-btn {
  border-color: rgba(239, 68, 68, .3);
  color: #fca5a5;
}

.query-btn.blocked-btn:hover {
  background: rgba(239, 68, 68, .1);
  border-color: var(--red);
}

.loading-spinner {
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 0;
}

/* ── 중앙 패널 ────────────────────────────────────────────────── */
.center-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

/* ── 플랫폼 레이블 ────────────────────────────────────────────── */
.platform-labels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.platform-label {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.client-platform {
  background: rgba(59, 130, 246, .08);
  border: 1px dashed rgba(59, 130, 246, .4);
  color: var(--blue);
}

.server-platform {
  background: rgba(245, 158, 11, .08);
  border: 1px dashed rgba(245, 158, 11, .4);
  color: var(--yellow);
}

/* ── TEE 흐름 다이어그램 ──────────────────────────────────────── */
.tee-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 16px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* 컴포넌트 박스 */
.component {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100px;
  min-height: 90px;
  border-radius: 10px;
  border: 2px solid var(--border);
  padding: 10px 6px;
  text-align: center;
  transition: all .25s ease;
  position: relative;
  flex-shrink: 0;
}

.comp-icon {
  font-size: 22px;
  margin-bottom: 4px;
}

.comp-name {
  font-size: 13px;
  font-weight: 700;
}

.comp-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.comp-owner {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
  font-style: italic;
}

/* 컴포넌트 기본 색상 */
.comp-hr {
  border-color: rgba(59, 130, 246, .4);
  background: rgba(59, 130, 246, .06);
}

.comp-stee {
  border-color: rgba(249, 115, 22, .4);
  background: rgba(249, 115, 22, .06);
}

.comp-ctee {
  border-color: rgba(245, 158, 11, .4);
  background: rgba(245, 158, 11, .06);
}

.comp-db {
  border-color: rgba(139, 92, 246, .4);
  background: rgba(139, 92, 246, .06);
}

/* 활성화 상태 */
.component.active {
  transform: translateY(-3px);
  box-shadow: 0 0 20px rgba(59, 130, 246, .5);
  border-color: var(--blue);
  background: rgba(59, 130, 246, .12);
}

.comp-stee.active {
  box-shadow: 0 0 20px rgba(249, 115, 22, .5);
  border-color: var(--orange);
  background: rgba(249, 115, 22, .15);
}

.comp-ctee.active {
  box-shadow: 0 0 20px rgba(245, 158, 11, .5);
  border-color: var(--yellow);
  background: rgba(245, 158, 11, .15);
}

.comp-db.active {
  box-shadow: 0 0 20px rgba(139, 92, 246, .5);
  border-color: var(--purple);
  background: rgba(139, 92, 246, .15);
}

/* 차단 상태 */
.component.blocked {
  border-color: var(--red) !important;
  background: rgba(239, 68, 68, .15) !important;
  box-shadow: 0 0 20px rgba(239, 68, 68, .5) !important;
}

/* 허용 완료 상태 */
.component.success {
  border-color: var(--green) !important;
  background: rgba(34, 197, 94, .12) !important;
  box-shadow: 0 0 16px rgba(34, 197, 94, .4) !important;
}

/* ── 화살표 ──────────────────────────────────────────────────── */
.arrow-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 70px;
  flex-shrink: 0;
  position: relative;
}

.arrow-line {
  width: 100%;
  height: 2px;
  background: var(--border);
  position: relative;
  transition: background .25s;
}

.arrow-line::after {
  content: '▶';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--border);
  transition: color .25s;
}

.arrow-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
  white-space: nowrap;
}

/* 암호화 채널 (점선) */
.encrypted .arrow-line {
  background: repeating-linear-gradient(90deg,
      var(--cyan) 0, var(--cyan) 6px,
      transparent 6px, transparent 10px);
  height: 2px;
}

.encrypted .arrow-label {
  color: var(--cyan);
}

/* 화살표 활성화 */
.arrow-wrap.active .arrow-line {
  background: var(--blue);
  box-shadow: 0 0 8px rgba(59, 130, 246, .6);
  animation: flow-right 0.5s ease;
}

.arrow-wrap.active .arrow-line::after {
  color: var(--blue);
}

.arrow-wrap.active.encrypted .arrow-line {
  background: repeating-linear-gradient(90deg,
      var(--cyan) 0, var(--cyan) 6px,
      transparent 6px, transparent 10px);
  box-shadow: 0 0 8px rgba(6, 182, 212, .6);
  animation: flow-right 0.5s ease;
}

.arrow-wrap.blocked .arrow-line {
  background: var(--red);
  box-shadow: 0 0 8px rgba(239, 68, 68, .6);
}

.arrow-wrap.blocked .arrow-line::after {
  color: var(--red);
}

@keyframes flow-right {
  0% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 1;
  }
}

/* ── 단계 로그 ────────────────────────────────────────────────── */
.step-log-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.step-log-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.step-log {
  flex: 1;
  overflow-y: auto;
  background: #0a1628;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
}

.log-placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 16px 0;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  animation: fade-in .3s ease;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.log-step {
  background: var(--surface2);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.log-actor {
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 52px;
}

.log-actor.hr {
  color: var(--blue);
}

.log-actor.stee {
  color: var(--orange);
}

.log-actor.ctee {
  color: var(--yellow);
}

.log-actor.channel {
  color: var(--cyan);
}

.log-msg {
  color: var(--text);
  flex: 1;
}

.log-msg.allow {
  color: #86efac;
}

.log-msg.block {
  color: #fca5a5;
}

.log-msg.info {
  color: var(--text-dim);
}

/* ── 결과 패널 ────────────────────────────────────────────────── */
.result-placeholder {
  text-align: center;
  padding: 24px 0;
  color: var(--text-dim);
}

.result-placeholder .result-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.result-card {
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid;
  animation: fade-in .4s ease;
}

.result-card.allowed {
  background: rgba(34, 197, 94, .08);
  border-color: rgba(34, 197, 94, .4);
}

.result-card.blocked {
  background: rgba(239, 68, 68, .08);
  border-color: rgba(239, 68, 68, .4);
}

.result-status {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
}

.result-status.allowed {
  color: var(--green);
}

.result-status.blocked {
  color: var(--red);
}

.result-query-name {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.result-json {
  background: #0a1628;
  border-radius: 6px;
  padding: 10px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  color: #a5f3fc;
  overflow-x: auto;
  white-space: pre;
  max-height: 200px;
  overflow-y: auto;
}

.result-message {
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
}

/* ── 정책 요약 ────────────────────────────────────────────────── */
.policy-info {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.policy-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.policy-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.policy-list li {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── 스크롤바 ─────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #475569;
}