/* 서버 작업 대시보드 — 다크 테마, transform/opacity 위주의 가벼운 모션 */
@property --p {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

:root {
  color-scheme: dark;
  --bg: #0b0d14;
  --surface: rgba(22, 25, 38, 0.72);
  --surface-solid: #161926;
  --surface-2: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.08);
  --ink: #eceef6;
  --ink-2: #b4b9cc;
  --muted: #8a90a6;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --good: #0ca30c;
  --good-ink: #4ade80;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #ff8a8a;
  --radius: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h2 { font-size: 0.95rem; margin: 0; letter-spacing: .01em; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.error { color: var(--critical-ink); min-height: 1.2em; margin: .5rem 0 0; font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 6px; }

/* ---------- 배경 오로라 (transform 만 애니메이션) ---------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aurora span {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  opacity: .35; will-change: transform;
  animation: drift 26s var(--ease) infinite alternate;
}
.aurora span:nth-child(1) { background: radial-gradient(closest-side, rgba(124,92,255,.55), transparent); top: -30vmax; left: -20vmax; }
.aurora span:nth-child(2) { background: radial-gradient(closest-side, rgba(34,211,238,.35), transparent); bottom: -35vmax; right: -25vmax; animation-duration: 32s; animation-delay: -8s; }
.aurora span:nth-child(3) { background: radial-gradient(closest-side, rgba(236,72,153,.22), transparent); top: 30%; left: 40%; width: 50vmax; height: 50vmax; animation-duration: 38s; animation-delay: -16s; }
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(6vmax, 4vmax, 0) scale(1.08); }
  100% { transform: translate3d(-4vmax, 7vmax, 0) scale(.95); }
}

/* ---------- 공통 카드 / 버튼 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 30px -18px rgba(0,0,0,.8);
  animation: rise .5s var(--ease) both;
  min-width: 0;
}
.grid > .card:nth-child(2) { animation-delay: .06s; }
.grid > .card:nth-child(3) { animation-delay: .12s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 600; padding: .6rem 1rem; border-radius: 12px; cursor: pointer;
  transition: transform .15s var(--ease), background-color .2s, border-color .2s, opacity .2s;
  touch-action: manipulation;
}
.btn:hover { border-color: rgba(255,255,255,.2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, var(--accent), #5b8cff 60%, var(--accent-2));
  background-size: 200% 100%; background-position: 0% 0;
  transition: background-position .5s var(--ease), transform .15s var(--ease), opacity .2s;
}
.btn.primary:hover:not(:disabled) { background-position: 100% 0; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(208,59,59,.5); color: var(--critical-ink); background: rgba(208,59,59,.08); }
.btn.small { padding: .35rem .7rem; font-size: .8rem; border-radius: 10px; }

input[type="password"], input[type="text"], textarea {
  width: 100%; background: rgba(0,0,0,.25); border: 1px solid var(--line); color: var(--ink);
  border-radius: 12px; padding: .7rem .85rem; font: inherit; resize: vertical;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.25); }

/* ---------- 로그인 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); display: grid; gap: .6rem; padding: 28px; }
.login-card .brand { font-size: 1.15rem; }
.login-card label { font-size: .85rem; color: var(--ink-2); margin-top: .4rem; }

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 750; letter-spacing: -.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), #ec4899, var(--accent));
  animation: spin 9s linear infinite;
  box-shadow: 0 0 18px rgba(124,92,255,.55);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 상단바 / 탭 ---------- */
.app { max-width: 1320px; margin: 0 auto; padding: 14px 18px 40px; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 6px 0 16px; position: sticky; top: 0; z-index: 5;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tabs {
  display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.tab {
  appearance: none; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 600;
  padding: .45rem .9rem; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: .4rem;
  position: relative; transition: color .2s, background-color .25s var(--ease);
}
.tab[aria-selected="true"] { color: #fff; background: linear-gradient(135deg, rgba(124,92,255,.45), rgba(34,211,238,.25)); }
.tab-ico { font-size: .95rem; }
.tab-badge {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(34,211,238,.6); animation: ping 1.6s infinite;
}
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(34,211,238,0); } 100% { box-shadow: 0 0 0 0 rgba(34,211,238,0); } }
.tab-panel { animation: fade .35s var(--ease) both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 개요 그리드 ---------- */
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.services { grid-template-columns: 1fr 1fr 1.2fr; align-items: start; }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.tile-body { display: flex; align-items: center; gap: 18px; }

.gauge {
  --p: 0; --c: var(--accent-2);
  width: 104px; height: 104px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background:
    radial-gradient(closest-side, var(--surface-solid) 76%, transparent 77% 100%),
    conic-gradient(var(--c) calc(var(--p) * 1%), rgba(255,255,255,.07) 0);
  transition: --p .9s var(--ease);
}
.gauge span { font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.gauge[data-level="warning"] { --c: var(--warning); }
.gauge[data-level="critical"] { --c: var(--critical); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .875rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--ink); }

.spark { position: relative; height: 46px; margin-top: 12px; }
.spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.spark .line { fill: none; stroke: var(--accent-2); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark .area { opacity: .5; }
.spark .cursor { stroke: rgba(255,255,255,.35); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .dot { fill: var(--accent-2); stroke: var(--surface-solid); stroke-width: 2; }
.spark-tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%); pointer-events: none;
  background: var(--surface-solid); border: 1px solid var(--line); border-radius: 8px;
  padding: 2px 8px; font-size: .75rem; white-space: nowrap; color: var(--ink);
}
.spark-empty { font-size: .75rem; color: var(--muted); padding-top: 14px; }

.disks { display: grid; gap: 12px; margin-bottom: 12px; }
.disk-row .disk-label { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 6px; gap: 8px; }
.bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.07); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 999px; transform-origin: left center;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform: scaleX(var(--s, 0)); transition: transform .9s var(--ease);
}
.bar[data-level="warning"] > i { background: var(--warning); }
.bar[data-level="critical"] > i { background: var(--critical); }

/* 상태 배지: 색 + 아이콘 + 글자 */
.pill {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 650;
  padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap;
}
.pill::before { content: attr(data-icon); font-size: .8rem; }
.pill.good { color: var(--good-ink); border-color: rgba(12,163,12,.45); }
.pill.warning { color: var(--warning); border-color: rgba(250,178,25,.45); }
.pill.serious { color: var(--serious); border-color: rgba(236,131,90,.45); }
.pill.critical { color: var(--critical-ink); border-color: rgba(208,59,59,.55); }
.pill.neutral { color: var(--ink-2); }
.pill.live { position: relative; }
.pill.live::after {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: .2; } }

.svc-rows { display: grid; gap: 8px; font-size: .875rem; }
.svc-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.svc-row .k { color: var(--ink-2); }
.svc-row .v { text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.note { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
.note code, .msg code { font-family: var(--mono); font-size: .85em; background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 5px; }
.exec-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; font-size: .8rem; }
.exec-list li { display: flex; justify-content: space-between; gap: 8px; }

.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.job-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .85rem; cursor: pointer;
  transition: background-color .2s, transform .15s var(--ease);
}
.job-list li:hover { background: rgba(255,255,255,.07); transform: translateX(2px); }
.job-list .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-size: .85rem; padding: 6px 2px; }

/* ---------- 에이전트 화면 ---------- */
.agent-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; height: calc(100vh - 110px); min-height: 520px; }
.conv-list-card { display: flex; flex-direction: column; min-height: 0; }
.conv-list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; display: grid; gap: 6px; align-content: start; }
.conv-list button {
  width: 100%; text-align: left; appearance: none; border: 1px solid transparent; background: var(--surface-2);
  color: var(--ink); font: inherit; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  display: grid; gap: 2px; transition: border-color .2s, background-color .2s, transform .15s var(--ease);
}
.conv-list button:hover { background: rgba(255,255,255,.07); }
.conv-list button[aria-current="true"] { border-color: rgba(124,92,255,.6); background: rgba(124,92,255,.12); }
.conv-list .c-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list .c-meta { font-size: .75rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.chat-card { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-title { min-width: 0; display: grid; }
.chat-title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg {
  max-width: min(760px, 92%); padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
  animation: pop .3s var(--ease) both; font-size: .925rem;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, rgba(124,92,255,.35), rgba(91,140,255,.25)); border: 1px solid rgba(124,92,255,.35); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); }
.msg.system { align-self: center; color: var(--muted); font-size: .8rem; background: transparent; }
.msg-meta { font-size: .7rem; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }

.job-card {
  align-self: stretch; border-radius: 14px; padding: 12px 14px; position: relative;
  background: rgba(10,12,20,.6); border: 1px solid var(--line); animation: pop .3s var(--ease) both;
}
.job-card.running { border-color: transparent; }
.job-card.running::before {
  content: ""; position: absolute; inset: -1px; border-radius: 15px; padding: 1px; pointer-events: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), #ec4899, var(--accent));
  background-size: 300% 100%;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  animation: flow 3s linear infinite;
}
@keyframes flow { to { background-position: 300% 0; } }
.job-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.job-head .left { display: flex; align-items: center; gap: 8px; }
.elapsed { font-variant-numeric: tabular-nums; font-size: .8rem; color: var(--ink-2); }
.timeline { list-style: none; margin: 10px 0 0; padding: 0 0 0 4px; display: grid; gap: 4px; max-height: 220px; overflow-y: auto; }
.timeline li {
  font-size: .78rem; font-family: var(--mono); color: var(--ink-2); padding-left: 16px; position: relative;
  overflow-wrap: anywhere; animation: fade .25s var(--ease) both;
}
.timeline li::before { content: "•"; position: absolute; left: 2px; color: var(--muted); }
.timeline li.tool::before { content: "⚙"; color: var(--accent-2); }
.timeline li.tool_done::before { content: "✓"; color: var(--good-ink); }
.timeline li.tool_error::before, .timeline li.error::before { content: "✕"; color: var(--critical-ink); }
.timeline li.denied::before { content: "⛔"; }
.timeline li.denied { color: var(--warning); }
.partial { margin-top: 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }
.partial:empty { display: none; }
.typing { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2); animation: bounce 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
.job-error { color: var(--critical-ink); font-size: .8rem; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

.composer { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 40vh; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--surface-solid); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop .25s var(--ease) both; max-width: 90vw;
}
.toast.error { border-color: rgba(208,59,59,.6); color: var(--critical-ink); }

/* ---------- 반응형 ---------- */
@media (max-width: 1080px) {
  .services { grid-template-columns: 1fr 1fr; }
  #card-jobs { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .app { padding: 10px 12px calc(84px + env(safe-area-inset-bottom)); }
  .metrics, .services { grid-template-columns: 1fr; }
  .topbar { padding-bottom: 10px; background: linear-gradient(var(--bg) 70%, transparent); }
  .tabs {
    position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); top: auto;
    justify-content: space-around; z-index: 20; padding: 6px; border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,.6);
  }
  .tab { flex: 1; flex-direction: column; gap: 0; font-size: .72rem; padding: .4rem .2rem; }
  .tab-ico { font-size: 1.15rem; }
  .tab-badge { position: absolute; top: 6px; right: calc(50% - 22px); }
  .agent-layout { grid-template-columns: 1fr; height: calc(100vh - 160px); min-height: 420px; }
  .agent-layout.show-chat .conv-list-card { display: none; }
  .agent-layout:not(.show-chat) .chat-card { display: none; }
  .back-btn { display: inline-flex; }
  .gauge { width: 88px; height: 88px; }
  #refresh-state { display: none; }
}

/* ---------- 모션 줄이기 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .aurora span, .brand-mark, .job-card.running::before, .pill.live::after, .tab-badge, .typing i { animation: none !important; }
}
@media (forced-colors: active) {
  .gauge { forced-color-adjust: none; }
  .pill { border: 1px solid CanvasText; }
}

/* ---- 보안 경고 ---- */
.warn-banner { margin: 0 0 14px; padding: 10px 14px; border-radius: 12px; font-size: .84rem; line-height: 1.5;
  color: var(--ink); background: rgba(250, 178, 25, .08); border: 1px solid rgba(250, 178, 25, .45); }
.warn-banner strong { color: var(--warning); }
.warn-banner.critical { background: rgba(208, 59, 59, .12); border-color: rgba(208, 59, 59, .6); }
.warn-banner.critical strong { color: var(--critical-ink); }
.warn-banner code { font-family: var(--mono); font-size: .85em; background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 5px; }
.priv-strip { margin: 0; padding: 8px 16px; font-size: .78rem; line-height: 1.45; color: var(--ink-2);
  background: rgba(250, 178, 25, .07); border-bottom: 1px solid rgba(250, 178, 25, .35); }
.priv-strip strong { color: var(--warning); }
.priv-strip.critical { background: rgba(208, 59, 59, .12); border-bottom-color: rgba(208, 59, 59, .6); }
.secret-note { margin: 0; padding: 6px 12px 0; font-size: .76rem; color: var(--muted); }
.secret-alert { margin: 0; padding: 6px 12px 0; font-size: .8rem; color: var(--critical-ink); font-weight: 600; }
.secret-alert[hidden] { display: none; }
