/* ============ AI Project Manager — 다크 테마 ============ */
:root {
  --bg: #0b0f17;
  --panel: #121926;
  --panel-2: #0e1520;
  --border: #223047;
  --border-soft: #1a2537;
  --text: #e2e8f0;
  --text-dim: #8ea0b8;
  --text-faint: #5b6b82;
  --accent: #6366f1;
  --accent-hover: #7c7ff7;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --violet: #a78bfa;
  --gray: #64748b;
  --mono: 'Cascadia Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- 버튼/폼 공통 ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: #1a2436; border-color: #31425f; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: #fda4af; border-color: #5b2530; }
.btn.danger:hover { background: #2f1418; border-color: #7f2d3a; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; margin-bottom: 5px; color: var(--text-dim); font-size: 12.5px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--text-dim); cursor: pointer; }
label.check input { width: auto; }
.hint { color: var(--text-faint); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.form-error { color: var(--red); font-size: 12.5px; min-height: 16px; margin: 6px 0; white-space: pre-wrap; }

/* ---------- 인증 화면 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px 400px at 20% 10%, rgba(99,102,241,.14), transparent),
    radial-gradient(500px 350px at 85% 90%, rgba(34,197,94,.08), transparent),
    var(--bg);
}
.auth-card {
  width: 400px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  text-align: center;
}
.auth-card h1 { font-size: 20px; margin: 14px 0 4px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 22px; }
.auth-card form { text-align: left; }
.auth-urls { color: var(--text-faint); font-size: 11.5px; margin-top: 18px; line-height: 1.6; word-break: break-all; }

/* ---------- 상단 바 ---------- */
.app-shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; }
.topbar-center { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 260px; }
#search { max-width: 240px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #31425f; }
.chip.active { background: rgba(99,102,241,.18); border-color: var(--accent); color: #c7cbff; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-box { display: flex; align-items: center; gap: 8px; }
.user-name { color: var(--text-dim); font-size: 13px; }

/* ---------- 통계 바 ---------- */
.stats-bar {
  display: flex;
  gap: 18px;
  padding: 10px 22px;
  color: var(--text-dim);
  font-size: 12.5px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
}
.stats-bar b { color: var(--text); }
.stats-bar .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* ---------- 프로젝트 그리드/카드 ---------- */
.grid-wrap { flex: 1; overflow-y: auto; padding: 20px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gray);
}
.card.state-running::before { background: var(--green); }
.card.state-error::before { background: var(--red); }
.card.state-analyzing::before { background: var(--violet); }

.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-title { flex: 1; min-width: 0; }
.card-name { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-dir {
  color: var(--text-faint);
  font-size: 11.5px;
  font-family: var(--mono);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}
.status-badge { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid; flex-shrink: 0; }
.status-badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-badge.running { color: #86efac; border-color: #1d4d33; background: rgba(34,197,94,.1); }
.status-badge.running .dot { background: var(--green); animation: pulse 1.6s infinite; }
.status-badge.stopped { color: #94a3b8; border-color: #334155; background: rgba(100,116,139,.1); }
.status-badge.stopped .dot { background: var(--gray); }
.status-badge.error { color: #fca5a5; border-color: #5b2530; background: rgba(239,68,68,.1); }
.status-badge.error .dot { background: var(--red); }
.status-badge.analyzing { color: #c4b5fd; border-color: #46357a; background: rgba(167,139,250,.1); }
.status-badge.analyzing .dot { background: var(--violet); animation: pulse 1.2s infinite; }
.status-badge.aiwork { color: #c4b5fd; border-color: #46357a; background: rgba(167,139,250,.1); }
.status-badge.aiwork .dot { background: var(--violet); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* 아이콘 버튼 (카드 하단 슬롯 균일화) */
.btn.icon { padding: 5px 9px; font-size: 13px; line-height: 1; min-width: 30px; text-align: center; }
.btn.icon.active { background: rgba(99,102,241,.22); border-color: var(--accent); }

/* 드래그 앤 드랍 */
.drag-grip { color: var(--text-faint); cursor: grab; font-size: 13px; user-select: none; }
.card.dragging { opacity: .45; outline: 2px dashed var(--accent); outline-offset: -2px; }
.card.drag-over { box-shadow: 0 -3px 0 0 var(--accent); }
.card { transition: opacity .12s; }

/* 카드 내장 로그 (모든 카드 동일 높이) */
.card-log-wrap { margin-top: 2px; }
.card-log-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: var(--text-faint); margin-bottom: 5px;
}
.card-log-head .log-full {
  background: none; border: none; color: var(--accent); font-size: 11px;
  cursor: pointer; padding: 0;
}
.card-log {
  height: 170px;              /* 고정 높이 — 감독 화면 균일성 */
  background: #0a0e15;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  padding: 8px 10px;
  margin: 0;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* 카드 배경색 */
.card.tinted::before { background: var(--card-tint, var(--gray)); }

/* 색상 스와치 */
.swatch {
  width: 26px; height: 26px; border-radius: 7px;
  border: 2px solid rgba(255,255,255,.18);
  cursor: pointer; padding: 0;
}
.swatch:hover { border-color: #fff; }

.tag {
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: var(--mono);
}
.card-desc { color: var(--text-dim); font-size: 12.5px; line-height: 1.5; min-height: 18px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.card-warn { color: var(--yellow); font-size: 12px; }
.card-analysis-err { color: #fda4af; font-size: 12px; }

.card-actions {
  display: flex;
  gap: 5px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
  align-items: center;
  min-height: 34px; /* 상태와 무관하게 카드 하단 높이 균일 */
}
.card-uptime { color: var(--text-faint); font-size: 11px; margin-left: auto; align-self: center; }

/* 빈 상태 */
.empty { text-align: center; color: var(--text-dim); padding: 80px 0; }
.empty-icon { font-size: 42px; margin-bottom: 10px; }

/* ---------- 모달 ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(3, 7, 14, .68);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
}
.modal h2 { margin: 0 0 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal .mono { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }

details.adv { border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px 12px; margin-top: 6px; }
details.adv summary { color: var(--text-dim); font-size: 12.5px; cursor: pointer; user-select: none; }

/* ---------- 로그 드로어 ---------- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(3, 7, 14, .55);
  z-index: 90;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(780px, 92vw);
  background: var(--panel-2);
  border-left: 1px solid var(--border);
  z-index: 95;
  display: flex;
  flex-direction: column;
  box-shadow: -18px 0 40px rgba(0,0,0,.4);
}
.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.drawer-head .card-name { font-size: 15px; }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 14px; }
.log-pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: #0a0e15;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-y: auto;
  flex: 1;
  min-height: 220px;
  max-height: 100%;
  margin: 0;
}
.log-line.err { color: #fda4af; }
.log-line.sys { color: var(--text-faint); }
.drawer-section-title { font-size: 12.5px; color: var(--text-dim); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.drawer-section-title .btn { margin-left: auto; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 12.5px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }
.spin {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--violet);
  border-top-color: transparent;
  border-radius: 50%;
  animation: rot .8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- 토스트 ---------- */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  animation: slideIn .18s ease-out;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* CLI 사용 가능 표시 */
.cli-status { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.cli-status:last-child { border-bottom: none; }
.cli-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); flex-shrink: 0; }
.cli-dot.on { background: var(--green); }

@media (max-width: 720px) {
  .topbar-center { order: 3; width: 100%; }
  #search { max-width: none; flex: 1; }
}
