/* Light theme modelled on Planning Center People: white surfaces, blue accent. */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --fg: #1d2733;
  --muted: #667385;
  --card: #ffffff;
  --line: #e1e6ed;
  --line-strong: #c9d1dc;
  --accent: #2e6ee6;
  --accent-hover: #1f5ad0;
  --accent-soft: #e8f0fd;
  --warn: #9a5b00;
  --warn-bg: #fff6e0;
  --warn-line: #f3d48a;
  --err: #c0362c;
  --err-bg: #fdecea;
  --ok: #18794e;
  --ok-bg: #e6f6ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ---------- Header + tabs ---------- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 14px 24px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; gap: 14px; align-items: center; }
.me { color: var(--muted); }
.logout {
  padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--fg);
}
.logout:hover { background: var(--bg); text-decoration: none; }

.tabs { max-width: 1160px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer;
  padding: 10px 12px 12px; border-bottom: 3px solid transparent; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count {
  min-width: 22px; padding: 0 7px; border-radius: 999px; font-size: 12px; line-height: 20px; text-align: center;
  background: var(--accent-soft); color: var(--accent);
}

/* ---------- Layout ---------- */
main { max-width: 1160px; margin: 0 auto; padding: 24px 24px 64px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.panel-desc { margin: 0; color: var(--muted); max-width: 680px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Buttons + inputs ---------- */
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn, .action-cell button, .person-actions button {
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 14px; font-weight: 600;
}
.btn:hover:not(:disabled), .action-cell button:hover:not(:disabled), .person-actions button:hover:not(:disabled) { background: var(--bg); }
.btn-primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled), button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
input {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 12px; background: var(--card); min-width: 0;
}
input:focus, button:focus-visible, select:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Scan status + summary ---------- */
.scan-state { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: 22px; }
#scan-progress { width: 200px; height: 8px; accent-color: var(--accent); }
.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
}
.summary-card:hover { border-color: var(--line-strong); }
.summary-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.summary-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.summary-value { font-size: 22px; font-weight: 700; }
.summary-warn .summary-value { color: var(--warn); }

/* ---------- Tables ---------- */
.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #f9fafc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfd; }
tr.mismatch td { background: var(--warn-bg); }
tr.mismatch:hover td { background: #fff0cc; }
td.mono, .mono { font-variant-numeric: tabular-nums; }
.name-cell { white-space: nowrap; }
.name-cell strong { font-weight: 600; }
#audit-body td:nth-child(1), #audit-body td:nth-child(2) { white-space: nowrap; }
#audit-body td:nth-child(5), #audit-body td:nth-child(6) { min-width: 170px; }
.audit-values div { display: flex; gap: 8px; white-space: nowrap; }
.audit-key { color: var(--muted); min-width: 64px; font-size: 12px; line-height: 22px; }
.audit-values .changed { color: var(--ok); font-weight: 700; }
.small { font-size: 12px; }
.action-cell button { padding: 5px 12px; font-size: 13px; }
.name-cell a { margin-left: 6px; font-size: 12px; }
.empty-value { color: var(--muted); font-style: italic; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.badge.both_missing { background: var(--err-bg); color: var(--err); border-color: #f6c9c4; }
.badge.member_missing, .badge.remote_missing { background: var(--accent-soft); color: var(--accent); border-color: #c9dafb; }
.badge.mismatch { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.badge.success { background: var(--ok-bg); color: var(--ok); border-color: #bfe5d0; }
.badge.failed { background: var(--err-bg); color: var(--err); border-color: #f6c9c4; }

.action-msg { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; }
.action-msg.warn { color: var(--warn); }
.check-col { width: 36px; padding-right: 0; }
.check-col input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.bulk-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px; border-radius: var(--radius);
  background: #f9fafc; border: 1px dashed var(--line-strong); color: var(--muted);
}
.bulk-bar.has-selection { background: var(--accent-soft); border: 1px solid #c9dafb; color: var(--accent); font-weight: 600; }
#bulk-info::before { content: '☑'; margin-right: 6px; color: var(--accent); }
.bulk-actions { display: flex; gap: 8px; }
.bulk-dialog {
  width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 14px; padding: 22px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.2); color: var(--fg);
}
.bulk-dialog::backdrop { background: rgba(16, 24, 40, 0.35); }
.bulk-dialog h2 { margin: 0 0 12px; font-size: 18px; }
#bulk-progress { width: 100%; height: 10px; accent-color: var(--accent); }
#bulk-summary { font-weight: 700; font-size: 15px; margin: 0 0 8px; }
.failure-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.failure-list li { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.failure-list li:last-child { border-bottom: 0; }
.failure-reason { color: var(--err); font-size: 13px; margin-top: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#bulk-confirm-text { font-weight: 600; margin: 0 0 8px; }
.confirm-warn { color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 8px 10px; margin: 0 0 10px; }
#bulk-confirm-list { max-height: 260px; margin-bottom: 8px; }
#bulk-confirm-list li { padding: 7px 12px; }
.choice-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Notices ---------- */
.notice {
  max-width: 1112px; margin: 16px auto 0; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow);
}
.notice.error { color: var(--err); background: var(--err-bg); border-color: #f6c9c4; }
.notice.ok { color: var(--ok); background: var(--ok-bg); border-color: #bfe5d0; }
.forbidden {
  max-width: 560px; margin: 64px auto; padding: 24px; font-size: 16px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- Lookup ---------- */
.lookup-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.lookup-form { padding: 16px; }
.field-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.help-card { padding: 16px 18px; background: #fbfcfe; }
.help-card h2 { margin: 0 0 8px; font-size: 15px; }
.help-steps { margin: 0 0 12px; padding-left: 20px; color: var(--fg); }
.help-steps li { margin-bottom: 2px; }
.addr-mock { border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); padding: 8px 10px 10px; margin-bottom: 12px; }
.addr-dots { display: flex; gap: 5px; margin-bottom: 7px; }
.addr-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.addr-bar {
  display: flex; align-items: center; background: var(--bg); border-radius: 999px; padding: 5px 12px;
  font-size: 12px; overflow: hidden; white-space: nowrap;
}
.addr-lock { font-size: 10px; margin-right: 6px; }
.addr-host { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.addr-id {
  color: var(--accent); font-weight: 700; background: var(--accent-soft); border: 1.5px solid var(--accent);
  border-radius: 5px; padding: 0 4px; flex-shrink: 0;
}
.addr-callout { text-align: right; color: var(--accent); font-size: 12px; font-weight: 600; margin-top: 4px; }
.addr-arrow { display: inline-block; margin-right: 2px; }
.help-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.help-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.help-chips code {
  font-size: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px;
  overflow-wrap: anywhere;
}
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.lookup-row { display: flex; gap: 8px; }
.lookup-row input { flex: 1; }
.person-card { display: flex; gap: 20px; padding: 20px; max-width: 760px; }
.avatar {
  width: 96px; height: 96px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line);
  object-fit: cover; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.person-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.person-head strong { font-size: 18px; }
.person-lines { flex: 1; min-width: 0; }
.person-grid { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 0; }
.person-grid dt { color: var(--muted); }
.person-grid dd { margin: 0; overflow-wrap: anywhere; }
.person-actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

@media (max-width: 760px) {
  .topbar-inner, main { padding-left: 16px; padding-right: 16px; }
  .brand-sub, .me { display: none; }
  .panel-head { flex-direction: column; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .person-card { flex-direction: column; }
  .lookup-layout { grid-template-columns: 1fr; }
}
