* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Apple SD Gothic Neo", sans-serif;
  color: #1c1c1e;
}
/* 밋밋한 회색 대신 은은한 인디고 색조의 그라디언트 배경 — 흰 카드들이
   붕 떠 보이지 않게 바탕에 색을 준다. */
body {
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(79, 107, 237, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(139, 92, 246, 0.08), transparent 55%),
    #f4f5fb;
}
.hidden { display: none !important; }
.center { display: flex; align-items: center; justify-content: center; height: 100vh; }
.error { color: #e5484d; font-size: 13px; margin-top: 10px; min-height: 16px; }
.hint { color: #999; font-size: 12px; }

.card { background: #fff; padding: 32px; border-radius: 14px; box-shadow: 0 8px 30px rgba(49, 46, 129, 0.12); width: 320px; }
.card h1 { font-size: 18px; margin: 0 0 20px; }
.card label { display: block; font-size: 13px; color: #555; margin: 12px 0 4px; }
.card input { width: 100%; padding: 8px 10px; border: 1px solid #d8d8de; border-radius: 7px; font-size: 14px; }
.card button[type=submit] {
  width: 100%; margin-top: 20px; padding: 10px; border: none; border-radius: 7px;
  background: linear-gradient(135deg, #4f6bed, #6d5bea); color: #fff; font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.card button[type=submit]:hover { filter: brightness(1.05); }

/* ---- 상단 바: 짙은 인디고 그라디언트로 브랜드 존재감을 준다 ---- */
#topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 24px;
  background: linear-gradient(120deg, #312e81, #4338ca 55%, #4f46e5);
  box-shadow: 0 2px 12px rgba(49, 46, 129, 0.25);
}
#topbar .brand { font-weight: 700; font-size: 16px; color: #fff; display: flex; align-items: center; gap: 8px; }
#topbar .brand::before { content: "⬡"; color: #a5b4fc; font-size: 18px; }
#topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; }
#topbar nav a { color: #e0e7ff; text-decoration: none; font-size: 14px; white-space: nowrap; font-weight: 500; }
#topbar nav a:hover { color: #fff; }
#user-label { color: #c7d2fe; font-size: 13px; white-space: nowrap; }
/* .link의 연한 라벤더색은 짙은 상단바 위에서만 읽힌다 — 흰 패널 안에서
   같은 클래스를 쓰면 거의 안 보이는 글씨가 된다(실제로 겪음: 패널의
   "새로고침"/"+ 추가"/"켜짐"/"삭제"가 전부 안 보였음). 기본은 읽히는
   색으로 두고, 상단바 안에서만 연한 색으로 덮어쓴다. */
button.link { background: none; border: none; color: #4f6bed; cursor: pointer; font-size: 14px; padding: 0; white-space: nowrap; }
button.link:hover { color: #3b53d4; }
#topbar button.link { color: #e0e7ff; }
#topbar button.link:hover { color: #fff; }

main { display: grid; grid-template-columns: 320px 1fr; gap: 18px; padding: 18px; align-items: start; }
.panel { background: #fff; border-radius: 14px; padding: 18px; box-shadow: 0 4px 20px rgba(49, 46, 129, 0.07); }
.panel h2 { font-size: 15px; margin: 0 0 14px; color: #312e81; }

/* ---- 노트북(에이전트) 목록 ---- */
.agent-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px;
  margin-bottom: 8px; cursor: pointer; transition: border-color 0.1s ease, background 0.1s ease;
  border: 1px solid #ececf0; border-left: 3px solid #d8d8e6;
}
.agent-row:hover { border-color: #c7c7f5; background: #fafaff; }
.agent-row.selected { border-color: #4f6bed; border-left-color: #4f6bed; background: #f0f3fe; }
.agent-row.online { border-left-color: #22c55e; }
.agent-row.running { border-left-color: #f5a623; }

.agent-avatar {
  position: relative; width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: #eef0fb; display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.agent-avatar .status-dot {
  position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: #c7c7d1; border: 2px solid #fff;
}
.agent-row.online .status-dot { background: #22c55e; }
.agent-row.running .status-dot { background: #f5a623; }

.agent-row .name { flex: 1; font-size: 14px; min-width: 0; }
.agent-row .name-text { display: block; overflow-wrap: break-word; word-break: break-word; }
.agent-row .meta { font-size: 11px; color: #9a9aa2; }
.agent-row.running .meta { color: #b8790f; font-weight: 600; }
.agent-row .revoke { font-size: 11px; color: #e5484d; background: none; border: none; cursor: pointer; flex-shrink: 0; }

/* ---- 워치 패널 ---- */
.watch-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 60px 20px; color: #9a9aa2; text-align: center; }
.watch-empty-icon { font-size: 40px; opacity: 0.6; }
.watch-empty p { margin: 0; font-size: 13px; line-height: 1.6; }

.watch-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.watch-controls select { padding: 6px 8px; border: 1px solid #d8d8de; border-radius: 7px; }
button.primary { background: linear-gradient(135deg, #4f6bed, #6d5bea); color: #fff; border: none; border-radius: 7px; padding: 8px 14px; cursor: pointer; font-weight: 500; }
button.danger { background: #e5484d; color: #fff; border: none; border-radius: 7px; padding: 8px 14px; cursor: pointer; font-weight: 500; }
button.primary:hover, button.danger:hover { filter: brightness(1.05); }
.status { padding: 3px 10px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.status.idle { background: #eeeef1; color: #71717a; }
.status.running { background: #22c55e; color: #fff; }
.running-flow { font-size: 12px; color: #4f6bed; font-weight: 600; white-space: nowrap; background: #eef0fd; padding: 3px 10px; border-radius: 10px; }

/* 화면 미리보기를 브라우저 창처럼 감싸서(맥 신호등 버튼 흉내) 그냥 뜬
   이미지가 아니라 "그 노트북 화면을 들여다보는" 느낌을 준다. */
#preview-frame { border-radius: 12px; overflow: hidden; box-shadow: 0 6px 24px rgba(20, 20, 40, 0.12); }
.preview-frame-bar {
  display: flex; align-items: center; gap: 6px; padding: 9px 12px;
  background: linear-gradient(180deg, #3a3a42, #2a2a30);
}
.preview-frame-dot { width: 9px; height: 9px; border-radius: 50%; background: #55555d; }
.preview-frame-dot:nth-child(1) { background: #ff5f56; }
.preview-frame-dot:nth-child(2) { background: #ffbd2e; }
.preview-frame-dot:nth-child(3) { background: #27c93f; }
.preview-frame-title { margin-left: 8px; font-size: 12px; color: #c8c8ce; font-family: ui-monospace, monospace; }
#preview-wrap { min-height: 200px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #1c1c1e; }
#preview-image { max-width: 100%; display: none; }
#preview-wrap .hint { color: #77777f; }

.log-label { font-size: 12px; font-weight: 700; color: #9a9aa2; text-transform: uppercase; letter-spacing: 0.04em; margin: 16px 0 6px; }
#watch-log { max-height: 200px; overflow-y: auto; background: #1c1c1e; color: #ddd; font-family: ui-monospace, monospace; font-size: 12px; padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; }
#watch-log .hint { color: #77777f; }

/* ---- 예약 실행 ---- */
#schedules-panel { grid-column: 1 / -1; }
#schedules-panel h2 { display: flex; align-items: center; justify-content: space-between; }

#schedule-form { padding: 12px; background: #f7f7fb; border-radius: 10px; margin-bottom: 12px; }
.sched-form-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sched-form-grid select, .sched-form-grid input { padding: 7px 9px; border: 1px solid #d8d8de; border-radius: 7px; font-size: 13px; }
.sched-form-grid select { flex: 1; min-width: 140px; }
.sched-days { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.sched-day { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #3f3f46; }
.sched-day input { width: auto; margin: 0; }
#schedule-form .row { display: flex; gap: 8px; margin-top: 10px; }
/* .primary/.danger는 제외 — 이 규칙이 명시도에서 이겨 배경을 흰색으로
   덮어쓰면 흰 글씨가 흰 바탕에 얹혀 버튼이 안 보인다(모달에서 겪은 것과
   같은 문제). */
#schedule-form .row button:not(.primary):not(.danger) {
  padding: 7px 14px; border-radius: 7px; border: 1px solid #d8d8de; background: #fff; cursor: pointer;
}
#schedule-form .row button.primary { padding: 7px 14px; }

.sched-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border: 1px solid #ececf0; border-radius: 9px; margin-bottom: 6px;
}
.sched-row.sched-off { opacity: 0.5; }
.sched-time { font-family: ui-monospace, monospace; font-size: 15px; font-weight: 600; color: #4f46e5; min-width: 52px; }
.sched-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.sched-flow { font-size: 14px; font-weight: 500; }
.sched-sub { font-size: 11px; color: #9a9aa2; }
.sched-toggle, .sched-delete { font-size: 12px; flex-shrink: 0; }
.sched-delete { color: #e5484d; }

/* ---- 실행 이력 ---- */
/* 2열 그리드의 두 열에 걸쳐 아래쪽 전체 폭을 쓴다. */
#runs-panel { grid-column: 1 / -1; }
#runs-panel h2 { display: flex; align-items: center; justify-content: space-between; }
.runs-refresh { font-size: 12px; font-weight: 400; }

.run-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border: 1px solid #ececf0; border-radius: 9px; margin-bottom: 6px; cursor: pointer;
}
.run-row:hover { border-color: #4f6bed; background: #fafaff; }
.run-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.run-flow { font-size: 14px; font-weight: 500; }
.run-sub { font-size: 11px; color: #9a9aa2; }

.run-status {
  flex-shrink: 0; min-width: 74px; text-align: center;
  padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.run-status--running { background: #dcfce7; color: #15803d; }
.run-status--finished { background: #eeeef1; color: #52525b; }
.run-status--stopped { background: #fef3c7; color: #a16207; }
.run-status--disconnected { background: #fee2e2; color: #b91c1c; }

.run-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12px; color: #71717a; margin-bottom: 12px; }

/* 실패 순간 화면 썸네일 — 클릭하면 새 탭에서 원본 크기로 열린다. */
.shot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; }
.shot-item { display: block; text-decoration: none; border: 1px solid #ececf0; border-radius: 8px; overflow: hidden; background: #fafafa; }
.shot-item:hover { border-color: #4f6bed; }
.shot-item img { width: 100%; display: block; aspect-ratio: 16 / 10; object-fit: cover; background: #1c1c1e; }
.shot-caption {
  display: block; padding: 5px 7px; font-size: 10px; color: #71717a;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-log {
  background: #1c1c1e; color: #ddd; font-family: ui-monospace, monospace; font-size: 12px;
  padding: 12px; border-radius: 10px; white-space: pre-wrap; max-height: 50vh; overflow-y: auto;
}

.modal { position: fixed; inset: 0; background: rgba(30, 27, 75, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: #fff; padding: 24px; border-radius: 14px; width: 360px; max-width: 90vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(30, 27, 75, 0.3); }
.modal-card--wide { width: 760px; }
.modal-card h2 { font-size: 16px; margin: 0 0 16px; color: #312e81; }
.modal-card label { display: block; font-size: 13px; color: #555; margin: 10px 0 4px; }
.modal-card input { width: 100%; padding: 8px 10px; border: 1px solid #d8d8de; border-radius: 7px; }
.modal-card hr { border: none; border-top: 1px solid #eee; margin: 16px 0; }
.modal-card select { width: 100%; padding: 8px 10px; border: 1px solid #d8d8de; border-radius: 7px; }
/* 체크박스는 라벨 옆에 붙어야 하므로 위 input 규칙(width:100%)에서 뺀다. */
.checkbox-row { display: flex; align-items: center; gap: 7px; margin: 7px 0; font-size: 13px; color: #3f3f46; }
.checkbox-row input[type="checkbox"] { width: auto; margin: 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
/* .primary/.danger는 지금까지처럼 그라디언트/빨강을 유지해야 하는데,
   이 규칙(.modal-actions button)이 명시도(specificity)가 같아서 CSS 파일
   안 등장 순서상 나중 규칙인 이게 이겨버려 배경을 흰색으로 덮어써
   버튼 글씨가 흰 바탕에 흰 글씨로 안 보이는 버그가 있었다(button.primary가
   text color:#fff을 주는데 배경만 이 규칙이 흰색으로 바꿔버림) —
   :not()으로 그 둘은 건드리지 않게 뺀다. */
.modal-actions button:not(.primary):not(.danger) { padding: 8px 14px; border-radius: 7px; border: 1px solid #d8d8de; background: #fff; cursor: pointer; }
.modal-actions button.primary, .modal-actions button.danger { padding: 8px 14px; }
.pending-row { display: flex; align-items: center; justify-content: space-between; padding: 8px; border-bottom: 1px solid #eee; }
.pending-row button { font-size: 13px; padding: 4px 10px; border-radius: 7px; border: none; background: #22c55e; color: #fff; cursor: pointer; }

/* 좁은 화면(모바일 등): 노트북 목록 / 프리뷰 패널을 2열 그리드 대신 세로로 쌓는다. */
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
}
