/* ── 테마 변수: 라이트 기본 / 다크 오버라이드 / 시스템(prefers-color-scheme) ── */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --chip-bg: #e0edff;
  --chip-text: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
:root[data-theme="light"] { color-scheme: light; }

/* 다크 팔레트 (공통 정의) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1420;
  --surface: #171d2b;
  --border: #2a3346;
  --text: #e6eaf2;
  --muted: #93a0b5;
  --primary: #4f8cff;
  --primary-dark: #3b82f6;
  --chip-bg: #1e2f4d;
  --chip-text: #9cc2ff;
  --danger: #f87171;
  --ok: #4ade80;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #0f1420;
    --surface: #171d2b;
    --border: #2a3346;
    --text: #e6eaf2;
    --muted: #93a0b5;
    --primary: #4f8cff;
    --primary-dark: #3b82f6;
    --chip-bg: #1e2f4d;
    --chip-text: #9cc2ff;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic",
    "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* ── 상단바 ── */
#topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  height: 56px; display: flex; align-items: center; gap: 24px;
}
.brand { font-weight: 700; font-size: 15px; }
.brand span { color: var(--primary); }
#topnav { display: flex; gap: 6px; flex: 1; }
.navlink { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.navlink:hover { background: var(--bg); color: var(--text); }
.userbox { display: flex; align-items: center; gap: 12px; }
#userLabel { font-size: 12px; color: var(--muted); }
.theme-select {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 5px 8px; font-size: 12px; font-family: inherit; cursor: pointer;
}
.theme-select:focus { outline: none; border-color: var(--primary); }

/* ── 메인/푸터 ── */
#app { flex: 1; }
.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px; }
.page h2 { margin: 0 0 4px; font-size: 20px; }
.page > .muted { margin-top: 0; }
#footer { text-align: center; padding: 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

.muted { color: var(--muted); }
.error-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.empty { padding: 40px 0; text-align: center; }

/* ── 중앙 정렬 (로그인/로딩) ── */
.center-screen { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.center-block { max-width: 560px; margin: 80px auto; text-align: center; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 32px;
}
.login-card { max-width: 420px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 0 0 8px; }
.login-card p { margin: 0 0 20px; }

/* ── 버튼 ── */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: .12s; font-family: inherit;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.btn-ghost { background: transparent; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── 스피너 ── */
.spinner {
  width: 28px; height: 28px; margin: 0 auto 10px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 구성원 목록 ── */
.part-block { margin-top: 24px; }
.part-title { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.chip { font-size: 11px; background: var(--chip-bg); color: var(--chip-text); padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.part-review-link { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--primary); }
.part-review-link:hover { text-decoration: underline; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.member-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow); transition: .12s;
}
.member-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.member-name { font-weight: 700; font-size: 15px; }
.member-uid { color: var(--muted); font-size: 12px; }
.member-role { margin-top: 6px; font-size: 11px; color: var(--chip-text); font-weight: 600; }
.no-daily {
  margin-top: 8px; display: inline-block; font-size: 11px; font-weight: 700;
  color: #c2410c; background: #ffedd5; padding: 2px 8px; border-radius: 999px;
}

/* ── 리뷰 목록 ── */
.backlink { color: var(--muted); font-size: 13px; display: inline-block; margin-bottom: 8px; }
.backlink:hover { color: var(--primary); }
.date-header { font-size: 13px; color: var(--muted); margin: 22px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.review-list { display: flex; flex-direction: column; gap: 8px; }
.review-row {
  display: flex; align-items: stretch; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.review-open { flex: 1; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.review-open:hover { background: var(--bg); border-radius: 10px; }
.review-row > .btn { margin: 10px 12px 10px 0; align-self: center; }
.review-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rv-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.rv-author { font-size: 12px; font-weight: 700; color: var(--text); }
/* 타입·툴: 강조 아닌 구분용 — 테두리만, 채움색 없음 */
.rv-type, .rv-tool {
  font-size: 11px; padding: 1px 7px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent;
}
.rv-type { color: var(--text); }
.rv-tool { color: var(--muted); }
.review-stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.review-stats .add { color: var(--ok); }
.review-stats .del { color: var(--danger); }
.review-stats .hashrange { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── 심각도 배지 (양쪽 테마 공통, 자체 색상 알약) ── */
.badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.sev-critical { background: #fde2e1; color: #b42318; }
.sev-high { background: #ffe0cc; color: #c2410c; }
.sev-medium { background: #fef3c7; color: #a16207; }
.sev-low { background: #e5e7eb; color: #4b5563; }
.sev-none { background: #dcfce7; color: #15803d; }
.sev-tbd { background: #e0e7ff; color: #4f46e5; }

/* ── 상세 ── */
.detail-page { display: flex; flex-direction: column; }
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 12px; }
.review-frame {
  width: 100%;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
}

/* 상세 화면에서는 페이지(외부) 스크롤을 없애고 iframe 하나만 스크롤되게 한다 */
body.view-detail { height: 100vh; overflow: hidden; }
body.view-detail #app { display: flex; flex-direction: column; min-height: 0; }
/* width:100% — flex 컬럼 + margin:auto 조합에서 폭이 content 로 줄어드는 것 방지 */
body.view-detail .detail-page { flex: 1; min-height: 0; width: 100%; padding-bottom: 20px; }
body.view-detail .review-frame { flex: 1; min-height: 0; }

/* ── 조직도 테이블 ── */
.org-table { width: 100%; border-collapse: collapse; margin-top: 12px; background: var(--surface); box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; }
.org-table th, .org-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.org-table th { background: var(--bg); color: var(--muted); font-weight: 600; }
.org-table input, .org-table select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; background: var(--surface); color: var(--text); }
.org-table input:focus, .org-table select:focus { outline: none; border-color: var(--primary); }
.org-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

@media (max-width: 720px) {
  .topbar-inner { gap: 12px; padding: 0 12px; }
  #userLabel { display: none; }
  .org-table { display: block; overflow-x: auto; }
}
