/* 병원 홈페이지 마스터 관리자 — 화면 스타일 */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --ink: #1d2430;
  --ink-2: #4a5568;
  --muted: #8792a4;
  --line: #e2e6ec;
  --line-2: #eef1f5;
  --accent: #2f6df0;
  --accent-soft: #eaf1fe;
  --accent-ink: #1b4fbd;
  --ok: #14a05f;
  --ok-soft: #e5f6ee;
  --warn: #c47a12;
  --warn-soft: #fdf3e2;
  --danger: #d0402f;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .05), 0 8px 24px rgba(20, 30, 50, .06);
  --sidebar-w: 268px;
  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------- 사이드바 ---------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line-2);
}
.logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 19px;
}
.sidebar-head strong { display: block; font-size: 14.5px; }
.sidebar-head span { display: block; font-size: 11.5px; color: var(--muted); }

.side-nav { padding: 12px 10px; display: grid; gap: 2px; }
.side-nav button {
  text-align: left;
  padding: 9px 11px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--ink-2);
}
.side-nav button:hover { background: var(--panel-2); }
.side-nav button.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.side-section { flex: 1; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line-2); }
.side-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.mini-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
  color: var(--accent-ink);
  text-transform: none;
  letter-spacing: 0;
}
.mini-btn:hover { background: var(--accent-soft); border-color: #c9dbfb; }

.site-list { overflow-y: auto; padding: 0 10px 14px; display: grid; gap: 2px; }
.site-list button {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 0; background: transparent; border-radius: 8px;
  cursor: pointer; text-align: left; font-size: 13px;
}
.site-list button:hover { background: var(--panel-2); }
.site-list button.is-active { background: var(--accent-soft); font-weight: 600; }
.site-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-list .port { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: #cfd6e0; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.sidebar-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line-2);
  font-size: 11px; color: var(--muted);
}

/* ---------- 본문 ---------- */

.main { margin-left: var(--sidebar-w); padding: 26px 30px 60px; min-height: 100vh; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { font-size: 21px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 버튼 ---------- */

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2a61d8; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: #f0c8c3; background: var(--danger-soft); }
.btn.danger:hover { background: #fbdedb; }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  font-size: 18px; color: var(--muted); line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

/* ---------- 사이트 카드 ---------- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }

.site-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 13px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 11px;
}
.site-card-top { display: flex; align-items: flex-start; gap: 10px; }
.site-card h3 { font-size: 15.5px; }
.site-card .sub { font-size: 12px; color: var(--muted); }
.site-card-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border-radius: 8px; padding: 7px 9px; }
.stat b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--muted); }
.site-card-actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line-2); padding-top: 11px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.internal { background: var(--accent-soft); color: var(--accent-ink); border-color: #cfdefb; }
.badge.ent { background: #e6f7fb; color: #0b7b98; border-color: #c3e9f2; }
.badge.ortho { background: #ecefff; color: #3244a8; border-color: #d2d9fb; }
.badge.on { background: var(--ok-soft); color: var(--ok); border-color: #c6ead8; }
.badge.off { background: #f1f3f6; color: var(--muted); }

/* ---------- 탭 ---------- */

.tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 9px 13px; font-size: 13.5px; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.is-active { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- 폼 ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel > h3 { font-size: 14.5px; margin-bottom: 3px; }
.panel > .panel-hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }

.field { display: block; margin-bottom: 13px; }
.field > .label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; margin-bottom: 5px; }
.field > .label .hint { font-weight: 400; color: var(--muted); font-size: 11.5px; }

input[type=text], input[type=number], input[type=url], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 109, 240, .12);
}
textarea { resize: vertical; min-height: 74px; line-height: 1.6; }

.toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  width: 38px; height: 22px; border-radius: 20px; background: #d3d9e2;
  position: relative; transition: background .15s; flex: none;
}
.toggle .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .track { background: var(--ok); }
.toggle input:checked + .track::after { transform: translateX(16px); }

/* ---------- 반복 항목 리스트 ---------- */

.repeat { display: grid; gap: 10px; }
.repeat-item {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  padding: 12px 13px 4px;
  position: relative;
}
.repeat-head {
  display: flex; align-items: center; gap: 6px;
  margin: -4px -4px 9px 0;
}
.repeat-head .no {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: #fff; border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px; font-variant-numeric: tabular-nums;
}
.repeat-head .title { flex: 1; font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repeat-head .tools { display: flex; gap: 2px; }
.repeat-head .tools button {
  border: 0; background: transparent; cursor: pointer;
  width: 24px; height: 24px; border-radius: 5px; color: var(--muted); font-size: 13px; line-height: 1;
}
.repeat-head .tools button:hover { background: #fff; color: var(--ink); }
.repeat-head .tools button.remove:hover { background: var(--danger-soft); color: var(--danger); }

.add-row { margin-top: 10px; }

.string-row { display: flex; gap: 6px; margin-bottom: 6px; }
.string-row input { flex: 1; }

/* ---------- 이미지 ---------- */

.image-cat { margin-bottom: 22px; }
.image-cat-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 4px; flex-wrap: wrap; }
.image-cat-head h4 { font-size: 13.5px; }
.image-cat-head code { font-size: 11px; color: var(--muted); background: var(--panel-2); padding: 1px 6px; border-radius: 4px; }
.image-cat-head p { margin: 0; font-size: 12px; color: var(--muted); flex-basis: 100%; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-top: 10px; }
.image-tile {
  border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
  background: #fff; position: relative;
}
.image-tile img { width: 100%; height: 92px; object-fit: cover; display: block; background: var(--panel-2); }
.image-tile .meta { padding: 6px 8px; font-size: 11px; }
.image-tile .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.image-tile .meta span { color: var(--muted); font-size: 10.5px; }
.image-tile .del {
  position: absolute; top: 5px; right: 5px;
  border: 0; border-radius: 6px; width: 24px; height: 24px; cursor: pointer;
  background: rgba(255,255,255,.92); color: var(--danger); font-size: 14px; line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.image-tile .del:hover { background: var(--danger); color: #fff; }

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: 9px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  background: var(--panel-2);
  transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.image-pick { display: flex; gap: 8px; align-items: center; }
.image-pick .preview {
  width: 54px; height: 42px; border-radius: 6px; object-fit: cover;
  border: 1px solid var(--line); background: var(--panel-2); flex: none;
}
.image-pick input { flex: 1; }

/* ---------- 표 ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { background: var(--panel-2); font-size: 11.5px; color: var(--ink-2); font-weight: 600; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
td.wrap { white-space: normal; word-break: break-all; max-width: 420px; }
td.num { font-variant-numeric: tabular-nums; }
.status-2 { color: var(--ok); }
.status-4, .status-5 { color: var(--danger); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; font-size: 15px; color: var(--ink-2); margin-bottom: 5px; }

/* ---------- 저장 바 ---------- */

.savebar {
  position: sticky; bottom: 0;
  margin: 20px -30px -60px;
  padding: 12px 30px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  z-index: 5;
}
.savebar .status { flex: 1; font-size: 12.5px; color: var(--muted); }
.savebar .status.dirty { color: var(--warn); font-weight: 600; }

/* ---------- 모달 ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 28, 42, .42);
  display: grid; place-items: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 12px;
  width: min(560px, 100%); max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(15, 25, 45, .28);
}
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 15.5px; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- 토스트 ---------- */

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast {
  background: #232c3b; color: #fff;
  padding: 10px 15px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 8px 26px rgba(15, 25, 45, .3);
  max-width: 380px;
  animation: rise .18s ease-out;
}
.toast.ok { background: #14663f; }
.toast.err { background: #92241a; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.note {
  background: var(--warn-soft);
  border: 1px solid #f0dcb6;
  border-radius: 8px;
  padding: 10px 13px;
  font-size: 12.5px;
  color: #7a5310;
  margin-bottom: 14px;
}
.note.info { background: var(--accent-soft); border-color: #cfdefb; color: var(--accent-ink); }

code.inline { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

@media (max-width: 900px) {
  .sidebar { position: static; width: auto; height: auto; }
  .main { margin-left: 0; padding: 20px 16px 60px; }
  .savebar { margin: 20px -16px -60px; padding: 12px 16px; }
  .site-list { max-height: 200px; }
}

/* ---------- AI 조수 서랍 ---------- */

.ai-toggle { position: relative; }
.ai-toggle .dot-badge {
  position: absolute; top: -3px; right: -3px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
}

.ai-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 32px rgba(20, 30, 50, .1);
  display: flex; flex-direction: column;
  z-index: 40;
  transform: translateX(100%);
  transition: transform .2s ease;
}
.ai-drawer.is-open { transform: translateX(0); }

.ai-head {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 14px; border-bottom: 1px solid var(--line-2);
}
.ai-head .title { flex: 1; min-width: 0; }
.ai-head strong { display: block; font-size: 14px; }
.ai-head span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ai-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.ai-msg { max-width: 92%; font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.ai-msg.me {
  align-self: flex-end;
  background: var(--accent); color: #fff;
  padding: 8px 12px; border-radius: 12px 12px 3px 12px;
}
.ai-msg.ai {
  align-self: flex-start;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 9px 12px; border-radius: 12px 12px 12px 3px;
}
.ai-msg.err { align-self: stretch; max-width: 100%; background: var(--danger-soft); border-color: #f0c8c3; color: #8d2b1f; }
.ai-msg .cursor { opacity: .45; }

.ai-proposal {
  align-self: stretch; max-width: 100%;
  border: 1px solid #cfdefb; border-radius: 10px;
  background: var(--accent-soft);
  padding: 11px 12px;
}
.ai-proposal .path {
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #fff; border: 1px solid #cfdefb; border-radius: 5px;
  padding: 1px 6px; display: inline-block; color: var(--accent-ink);
}
.ai-proposal .reason { font-size: 12.5px; margin: 7px 0 8px; color: var(--ink-2); }
.ai-proposal .diff { display: grid; gap: 5px; margin-bottom: 9px; }
.ai-proposal .diff div {
  font-size: 11.5px; line-height: 1.6; border-radius: 6px; padding: 6px 8px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 150px; overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ai-proposal .diff .before { background: #fdeceb; color: #7d2d24; }
.ai-proposal .diff .after { background: #e6f6ed; color: #1b5c3a; }
.ai-proposal .diff b { font-family: var(--font); font-size: 10.5px; display: block; opacity: .7; margin-bottom: 2px; }
.ai-proposal .acts { display: flex; gap: 6px; }
.ai-proposal.done { background: var(--ok-soft); border-color: #c6ead8; }
.ai-proposal.done .acts { display: none; }
.ai-applied { font-size: 12px; color: var(--ok); font-weight: 600; }

.ai-foot { border-top: 1px solid var(--line-2); padding: 10px 12px; }
.ai-foot textarea { min-height: 62px; font-size: 13px; }
.ai-foot-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.ai-foot-row .meta { flex: 1; font-size: 11px; color: var(--muted); }

.ai-empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 22px 10px; }
.ai-empty b { display: block; color: var(--ink-2); font-size: 13.5px; margin-bottom: 6px; }
.ai-chip {
  display: inline-block; margin: 3px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 20px;
  background: #fff; font-size: 12px; cursor: pointer; color: var(--ink-2);
}
.ai-chip:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }

@media (max-width: 900px) {
  .ai-drawer { width: 100vw; }
}

/* ---------- 메인 갤러리 ---------- */

.gal-list { display: grid; gap: 10px; margin-top: 12px; }

.gal-item {
  display: grid;
  grid-template-columns: 46px 108px 1fr auto;
  align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; padding: 10px 12px;
}
.gal-no {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink);
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}
.gal-thumb {
  width: 108px; height: 74px; object-fit: cover;
  border-radius: 7px; border: 1px solid var(--line); background: var(--panel-2);
  display: block;
}
.gal-main { min-width: 0; }
.gal-main input { width: 100%; }
.gal-file {
  font-size: 11px; color: var(--muted); margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.gal-tools { display: flex; gap: 3px; }
.gal-tools button {
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  width: 30px; height: 30px; border-radius: 7px; color: var(--muted); font-size: 13px; line-height: 1;
}
.gal-tools button:hover { background: var(--panel-2); color: var(--ink); }
.gal-tools button.remove:hover { background: var(--danger-soft); color: var(--danger); border-color: #f0c8c3; }
.gal-tools button:disabled { opacity: .35; cursor: not-allowed; }

.gal-preview { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.gal-preview figure { margin: 0; flex: none; width: 118px; }
.gal-preview img {
  width: 118px; height: 78px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); display: block; background: var(--panel-2);
}
.gal-preview figcaption {
  font-size: 11px; color: var(--ink-2); margin-top: 5px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gal-preview figcaption b { color: var(--accent-ink); }

@media (max-width: 700px) {
  .gal-item { grid-template-columns: 40px 1fr; grid-template-areas: "no thumb" "main main" "tools tools"; }
  .gal-no { grid-area: no; }
  .gal-thumb { grid-area: thumb; width: 100%; }
  .gal-main { grid-area: main; }
  .gal-tools { grid-area: tools; }
}

.image-pick { align-items: center; }
.image-pick.drag { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 8px; }
.image-pick select { min-width: 0; }
.image-pick .btn { flex: none; }

/* ═══════════════════════════════════════════════════════════
   디자인 정리 — 조금 더 부드럽고 눈에 잘 들어오게
   (앞의 규칙을 덮어씁니다. 뒤에 오는 것이 이깁니다)
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #171d28;
  --ink-2: #495468;
  --muted: #8a94a6;
  --line: #e5e9f0;
  --line-2: #f0f3f7;
  --accent: #3b6cf6;
  --accent-soft: #eef3ff;
  --accent-ink: #2251d8;
  --ok: #10a06a;
  --ok-soft: #e6f7f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 29, 40, .04), 0 6px 20px rgba(23, 29, 40, .05);
  --shadow-lg: 0 2px 6px rgba(23, 29, 40, .05), 0 18px 44px rgba(23, 29, 40, .09);
  --preview-w: 460px;
}

body { letter-spacing: -0.005em; }

/* 사이드바 — 살짝 떠 있는 느낌 */
.sidebar { background: #fbfcfe; border-right-color: var(--line-2); }
.logo {
  background: linear-gradient(140deg, #3b6cf6, #6b5bf6);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 108, 246, .28);
}
.side-nav button { transition: background .14s, color .14s; }
.side-nav button.is-active {
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--accent-ink);
}
.site-list button { transition: background .14s; }
.site-list button.is-active { background: #fff; box-shadow: var(--shadow); }

/* 제목 */
.page-head h1 { font-size: 22px; letter-spacing: -0.02em; font-weight: 750; }

/* 버튼 — 조금 더 둥글고 눌리는 느낌 */
.btn {
  border-radius: 10px;
  font-weight: 500;
  transition: background .14s, border-color .14s, transform .06s, box-shadow .14s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #4a78f8, #3b6cf6);
  border-color: #3260e0;
  box-shadow: 0 1px 2px rgba(31, 73, 184, .2), 0 4px 14px rgba(59, 108, 246, .26);
}
.btn.primary:hover { background: linear-gradient(180deg, #4272f7, #3363ea); }
.btn.ok { background: linear-gradient(180deg, #16ac74, #10a06a); border-color: #0d8f5e; }
.btn.small { border-radius: 8px; }

/* 카드 — 살짝 떠오르게 */
.panel, .site-card { border-radius: var(--radius); }
.site-card { transition: box-shadow .16s, transform .16s, border-color .16s; }
.site-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: #d8e0ee;
}
.stat { background: linear-gradient(180deg, #fbfcfe, #f5f7fb); border: 1px solid var(--line-2); }
.stat b { font-weight: 700; letter-spacing: -0.01em; }

/* 실행 중 점을 은은하게 숨쉬듯 */
.dot.on { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--ok-soft); }
  50%      { box-shadow: 0 0 0 5px rgba(16, 160, 106, .13); }
}

/* 탭 */
.tabs { gap: 4px; }
.tabs button { border-radius: 9px 9px 0 0; font-weight: 500; }
.tabs button.is-active { background: linear-gradient(180deg, var(--accent-soft), transparent); }

/* 입력 */
input[type=text], input[type=number], input[type=url], input[type=password], textarea, select {
  border-radius: 9px;
  background: var(--panel-2);
  transition: background .14s, border-color .14s, box-shadow .14s;
}
input:hover, textarea:hover, select:hover { background: #fff; }
input:focus, textarea:focus, select:focus { background: #fff; }

/* 반복 항목 */
.repeat-item { border-radius: 11px; transition: border-color .14s, background .14s; }
.repeat-item:focus-within { border-color: #c9d8fb; background: #fff; }

/* 저장 바 */
.savebar { backdrop-filter: blur(14px) saturate(1.4); }

/* ─────────── 실시간 미리보기 패널 ─────────── */

body.with-preview .main { margin-right: var(--preview-w); }
body.with-preview .savebar { margin-right: 0; }

.preview-pane {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--preview-w);
  background: #eceff4;
  border-left: 1px solid var(--line);
  display: none;
  flex-direction: column;
  z-index: 30;
}
body.with-preview .preview-pane { display: flex; }

.preview-head {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line-2);
}
.preview-head select { width: auto; flex: 1; min-width: 0; font-size: 12.5px; padding: 5px 8px; }
.preview-head .seg {
  display: flex; gap: 2px; padding: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.preview-head .seg button {
  border: 0; background: transparent; cursor: pointer;
  padding: 4px 9px; border-radius: 7px; font-size: 12px; color: var(--muted);
}
.preview-head .seg button.on { background: #fff; color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow); }

.preview-body { flex: 1; overflow: auto; display: grid; place-items: start center; padding: 14px; }
.preview-frame {
  background: #fff; border: 0; display: block;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(23, 29, 40, .1), 0 14px 40px rgba(23, 29, 40, .12);
  transition: width .2s ease;
}
.preview-frame.desktop { width: 100%; height: 100%; min-height: 640px; }
.preview-frame.mobile { width: 390px; height: 100%; min-height: 720px; border-radius: 20px; }

.preview-foot {
  padding: 7px 12px; background: #fff;
  border-top: 1px solid var(--line-2);
  font-size: 11px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.preview-foot .live { color: var(--ok); font-weight: 600; }
.preview-foot .spacer { flex: 1; }

/* 미리보기가 열려 있으면 AI 서랍은 그 왼쪽에 붙습니다 */
body.with-preview .ai-drawer { right: var(--preview-w); }

@media (max-width: 1500px) { :root { --preview-w: 400px; } }
@media (max-width: 1280px) {
  body.with-preview .main { margin-right: 0; }
  .preview-pane { display: none !important; }
}

/* ── AI 서랍과 미리보기가 겹치던 문제 ────────────────────────────
   닫힌 서랍은 transform 으로 밀어만 놔서 화면 밖에 있는 것처럼 보여도
   실제로는 그 자리를 차지한 채 미리보기를 하얗게 덮고 있었습니다. */
.ai-drawer {
  visibility: hidden;
  pointer-events: none;
  transition: transform .2s ease, visibility 0s linear .2s;
}
.ai-drawer.is-open {
  visibility: visible;
  pointer-events: auto;
  transition: transform .2s ease, visibility 0s;
}
/* 열려 있을 때만 미리보기 왼쪽으로 비켜섭니다. */
body.with-preview .ai-drawer { right: 0; }
body.with-preview .ai-drawer.is-open { right: var(--preview-w); }

/* ═══════════════════════════════════════════════════════════
   다크 모드
   html[data-theme="dark"] 하나만 보면 되도록, '시스템 따름'은
   자바스크립트가 실제 값(dark/light)으로 바꿔서 붙여 줍니다.
   ═══════════════════════════════════════════════════════════ */

:root[data-theme="dark"] {
  --bg: #11141b;
  --panel: #1a1e27;
  --panel-2: #212632;
  --ink: #e7ebf3;
  --ink-2: #a9b3c4;
  --muted: #8d97aa;
  --line: #2c3340;
  --line-2: #232935;
  --accent: #5b8bff;
  --accent-soft: #1c2740;
  --accent-ink: #a9c5ff;
  --ok: #34c68d;
  --ok-soft: #12301f;
  --warn: #e2a441;
  --warn-soft: #302610;
  --danger: #f0705f;
  --danger-soft: #35191a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .28);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .34), 0 18px 44px rgba(0, 0, 0, .44);
  color-scheme: dark;
}

/* 흰 배경으로 박아 둔 곳들을 패널 색으로 돌립니다. */
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .mini-btn,
:root[data-theme="dark"] .btn,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .ai-drawer,
:root[data-theme="dark"] .ai-chip,
:root[data-theme="dark"] .gal-item,
:root[data-theme="dark"] .gal-tools button,
:root[data-theme="dark"] .image-tile,
:root[data-theme="dark"] .table-wrap,
:root[data-theme="dark"] .repeat-head .no,
:root[data-theme="dark"] .ai-proposal .path,
:root[data-theme="dark"] .preview-head,
:root[data-theme="dark"] .preview-foot,
:root[data-theme="dark"] .side-nav button.is-active,
:root[data-theme="dark"] .site-list button.is-active,
:root[data-theme="dark"] .preview-head .seg button.on {
  background: var(--panel);
}

:root[data-theme="dark"] .sidebar { background: #161a22; }
:root[data-theme="dark"] .stat { background: var(--panel-2); border-color: var(--line-2); }
:root[data-theme="dark"] .repeat-head .tools button:hover,
:root[data-theme="dark"] tbody tr:hover { background: var(--panel-2); }
:root[data-theme="dark"] .repeat-item:focus-within { background: var(--panel); border-color: #3a4a6b; }
:root[data-theme="dark"] .toggle .track::after { background: #dfe5ef; }
:root[data-theme="dark"] .toggle .track { background: #39414f; }

/* 입력칸 — 평소 살짝 어둡게, 만지면 밝게 */
:root[data-theme="dark"] input[type=text],
:root[data-theme="dark"] input[type=number],
:root[data-theme="dark"] input[type=url],
:root[data-theme="dark"] input[type=password],
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select { background: var(--panel-2); }
:root[data-theme="dark"] input:hover,
:root[data-theme="dark"] textarea:hover,
:root[data-theme="dark"] select:hover,
:root[data-theme="dark"] input:focus,
:root[data-theme="dark"] textarea:focus,
:root[data-theme="dark"] select:focus { background: #262d3b; }

/* 그라데이션·특수 색 */
:root[data-theme="dark"] .btn.primary {
  background: linear-gradient(180deg, #4f7ef5, #3f6ae8);
  border-color: #3a63d8;
  box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(59,108,246,.22);
}
:root[data-theme="dark"] .btn.primary:hover { background: linear-gradient(180deg, #5b88f7, #4674ef); }
:root[data-theme="dark"] .btn.ok { background: linear-gradient(180deg, #22ab77, #1b9a6b); border-color: #178a5f; }
:root[data-theme="dark"] .btn.danger { background: var(--danger-soft); border-color: #5a2c28; color: #ff9384; }
:root[data-theme="dark"] .badge.internal { background: var(--accent-soft); border-color: #2f4373; }
:root[data-theme="dark"] .badge.ent { background: #11303a; color: #6fd4ec; border-color: #1d4a58; }
:root[data-theme="dark"] .badge.ortho { background: #1d2450; color: #9fabff; border-color: #2f3a74; }
:root[data-theme="dark"] .badge.on { background: var(--ok-soft); border-color: #1d5238; }
:root[data-theme="dark"] .badge.off { background: var(--panel-2); }
:root[data-theme="dark"] .note { background: var(--warn-soft); border-color: #4b3a15; color: #e9c07a; }
:root[data-theme="dark"] .note.info { background: var(--accent-soft); border-color: #2f4373; color: var(--accent-ink); }
:root[data-theme="dark"] code.inline { background: var(--panel-2); border-color: var(--line); }
:root[data-theme="dark"] .dropzone { background: var(--panel-2); }
:root[data-theme="dark"] .dropzone:hover,
:root[data-theme="dark"] .dropzone.drag { background: var(--accent-soft); }
:root[data-theme="dark"] .savebar { background: rgba(26,30,39,.92); }
:root[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.62); }
:root[data-theme="dark"] .preview-pane { background: #0d1016; }
:root[data-theme="dark"] .ai-msg.ai { background: var(--panel-2); }
:root[data-theme="dark"] .ai-proposal { background: var(--accent-soft); border-color: #2f4373; }
:root[data-theme="dark"] .ai-proposal .diff .before { background: #3a1d1c; color: #ffb0a4; }
:root[data-theme="dark"] .ai-proposal .diff .after { background: #133024; color: #86e3b6; }
:root[data-theme="dark"] .ai-proposal.done { background: var(--ok-soft); border-color: #1d5238; }
:root[data-theme="dark"] .gal-no { background: var(--accent-soft); color: var(--accent-ink); }
:root[data-theme="dark"] .image-tile .del { background: rgba(26,30,39,.92); }
:root[data-theme="dark"] .toast { background: #2b3341; }
:root[data-theme="dark"] .site-card:hover { border-color: #3b475c; }
:root[data-theme="dark"] .tabs button.is-active { background: linear-gradient(180deg, var(--accent-soft), transparent); }

/* 사진·미리보기는 원래 색 그대로 두되 눈부시지 않게 */
:root[data-theme="dark"] .preview-frame { box-shadow: 0 3px 10px rgba(0,0,0,.5), 0 14px 40px rgba(0,0,0,.55); }
:root[data-theme="dark"] .gal-thumb,
:root[data-theme="dark"] .image-tile img,
:root[data-theme="dark"] .image-pick .preview { background: var(--panel-2); }

/* 테마 고르는 단추 */
.theme-seg {
  display: flex; gap: 2px; margin-top: 9px; padding: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.theme-seg button {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  padding: 5px 0; border-radius: 7px; font-size: 11.5px; color: var(--muted);
}
.theme-seg button:hover { color: var(--ink-2); }
.theme-seg button.on { background: var(--panel); color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow); }

/* ── 사이트 카드 현황 ───────────────────────────────────────── */

.site-card-body { grid-template-columns: repeat(3, 1fr); }
.site-card-body + .site-card-body { margin-top: -4px; }

.stat.wide b { font-size: 13px; }

/* 완성도 막대 */
.fill-bar {
  height: 4px; border-radius: 4px; margin-top: 5px;
  background: var(--line); overflow: hidden;
}
.fill-bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); transition: width .3s ease; }
.fill-bar.low i { background: var(--warn); }
.fill-bar.verylow i { background: var(--danger); }

/* 아래쪽 요약 줄 */
.site-meta {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font-size: 11.5px; color: var(--muted);
  padding-top: 2px;
}
.site-meta b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.site-meta .warn { color: var(--warn); }

/* 소아청소년과 배지 (따뜻한 초록) */
.badge.pediatrics { background: #e7f7ef; color: #17714b; border-color: #c3e9d5; }
:root[data-theme="dark"] .badge.pediatrics { background: #12301f; color: #6fd9a6; border-color: #1d5238; }
