* { box-sizing: border-box; }
:root {
  --bg: #f5f6f8; --panel: #fff; --line: #e3e6ea; --ink: #1c2430; --muted: #8a93a0;
  --brand: #2563eb; --brand-d: #1d4ed8; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
}
html, body { margin: 0; padding: 0; }
body { font: 14px/1.5 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #131a24; color: #c7d0db; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; color: #fff; padding: 18px 18px 12px; font-size: 15px; }
.sidebar nav { display: flex; flex-direction: column; flex: 1; padding-bottom: 10px; }
.sidebar nav a { color: #c7d0db; padding: 10px 18px; display: flex; align-items: center; gap: 10px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #1b2430; color: #fff; }
.sidebar nav a.active { background: #1b2430; color: #fff; border-left-color: var(--brand); font-weight: 600; }
.sidebar nav a.disabled { color: #5b6675; pointer-events: none; }
.nav-ico { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; line-height: 1; }
.nav-section { font-size: 11px; color: #5b6675; padding: 13px 18px 4px; margin-top: 6px; border-top: 1px solid #232c38; text-transform: uppercase; letter-spacing: .05em; }
.nav-bottom { margin-top: auto; border-top: 1px solid #232c38; padding-top: 6px; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; color: var(--ink); }
.topbar-title { display: none; font-weight: 700; }
.nav-overlay { display: none; }
.topbar .user { font-weight: 600; }
.content { padding: 24px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card-label { color: var(--muted); font-size: 12px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.grid2 > * { min-width: 0; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, monospace; }
.muted { color: var(--muted); }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.realtor-info { font-size: 12px; margin-top: 2px; }
.canceled { color: var(--err); font-size: 12px; }

/* 말풍선 tooltip — 번호 위에 올리면 중개사 상세(상호/대표자/지역/도로명) */
.tip { position: relative; display: inline-block; cursor: help; border-bottom: 1px dotted var(--muted); }
.tip::after {
  content: attr(data-tip);
  white-space: pre-line;
  position: absolute; left: 0; top: 100%; z-index: 20;
  margin-top: 6px; min-width: 140px; max-width: 280px;
  background: #0f172a; color: #e2e8f0;
  padding: 7px 10px; border-radius: 6px; font-size: 12px; line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none;
}
.tip:hover::after, .tip:focus::after, .tip:focus-within::after { opacity: 1; visibility: visible; }
.tip { outline: none; }

/* forms / buttons */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters .fgroup { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.filters .fgroup input { padding: 6px 7px; }
.filters .btn-reset { font-size: 12px; color: var(--muted); text-decoration: none; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; }
.filters .btn-reset:hover { background: #f0f2f5; }
.exclude-box { font-size: 12px; }
.exclude-box > summary { cursor: pointer; color: var(--muted); padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; list-style: none; }
.exclude-box[open] > summary { background: #fff7ed; border-color: #fed7aa; color: #b45309; }
.exclude-list { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; max-width: 520px; }
.exclude-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.exclude-item input { padding: 0; }
.linkbtn { border: none; background: none; padding: 2px 4px; cursor: pointer; font-size: 12px; opacity: .55; }
.linkbtn:hover { opacity: 1; background: none; }
.schedule-box { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 12px; margin: 10px 0; background: #fafbfc; }
.schedule-box legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .linkbtn { font-size: 13px; }
.exclude-note { color: #b45309; font-size: 12px; }
.block-link { margin-left: 10px; font-size: 12px; color: var(--muted); text-decoration: none; }
.block-link:hover { color: var(--ink); }
.badge.blocked { background: #fee2e2; color: #b91c1c; }
.src-badge { display: inline-block; margin-left: 5px; padding: 1px 6px; border-radius: 999px; font-size: 11px; font-weight: 600; vertical-align: middle; }
.src-hanbang { background: #e0e7ff; color: #3730a3; }
.src-naver { background: #dcfce7; color: #15803d; }
.src-auction1 { background: #fef3c7; color: #b45309; }
.src-daangn { background: #ffedd5; color: #c2410c; }
.campaign-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel); }
.campaign-today { margin-top: 6px; font-size: 13px; background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; border-radius: 7px; padding: 5px 10px; display: inline-block; }
.changelog { list-style: none; margin: 0; padding: 0; }
.changelog li { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.changelog li:last-child { border-bottom: none; }
.cl-date { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 42px; font-size: 12px; }
.cl-title { font-weight: 600; }
.cl-detail { color: var(--muted); font-size: 12px; }
.star { border: none; background: none; cursor: pointer; padding: 0 5px 0 0; font-size: 15px; color: #cbd5e1; line-height: 1; }
.star.on { color: #f59e0b; }
.star:hover { background: none; color: #f59e0b; }
.memo-line { margin-top: 2px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 2px; }
.memo-text { background: #fffbeb; border: 1px solid #fde68a; border-radius: 4px; padding: 1px 6px; white-space: pre-wrap; word-break: break-word; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
textarea { width: 100%; resize: vertical; }
button, .btn { font: inherit; cursor: pointer; padding: 7px 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
button:hover, .btn:hover { background: #f0f2f5; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--brand-d); }
button.danger { background: var(--err); border-color: var(--err); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { border: none; background: none; color: var(--brand); padding: 0; }
.chk { display: inline-flex; align-items: center; gap: 5px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

/* compose */
.compose { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; max-width: 640px; display: flex; flex-direction: column; gap: 6px; }
.compose label { font-weight: 600; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.recipient-banner { background: #eef4ff; border: 1px solid #cfe0ff; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

/* compose 2단 레이아웃 */
.compose-grid { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .compose-grid { grid-template-columns: 1fr; } }
.compose-grid h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.compose-grid .compose { max-width: none; }
.list-scroll { max-height: 460px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.list-scroll table { border: none; border-radius: 0; }
.recipient-table th { position: sticky; top: 0; }
.recipient-table tbody tr { cursor: pointer; }
.recipient-table tbody tr:hover { background: #f0f4ff; }
.recipient-table tbody tr.sel { background: #dbe7ff; }

/* 미리보기 패널 */
.preview { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.preview h4 { margin: 0 0 10px; font-size: 14px; }
.preview-detail { display: grid; grid-template-columns: 64px 1fr; gap: 4px 10px; margin: 0 0 12px; }
.preview-detail dt { color: var(--muted); font-size: 13px; }
.preview-detail dd { margin: 0; font-size: 13px; }
.preview-msg-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.preview-msg { white-space: pre-wrap; background: #eef4ff; border: 1px solid #cfe0ff; border-radius: 8px; padding: 12px; font-size: 14px; min-height: 40px; }

/* batch */
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 5px; background: #eef1f5; color: #475569; margin: 1px 2px 1px 0; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eef1f5; color: var(--ink); }
.badge.active, .badge.sending { background: #e0edff; color: var(--brand-d); }
.badge.sent, .badge.done { background: #dcfce7; color: var(--ok); }
.badge.failed, .badge.canceled { background: #fee2e2; color: var(--err); }
.badge.queued, .badge.paused { background: #fef3c7; color: var(--warn); }
.progress { height: 6px; background: #eef1f5; border-radius: 99px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.progress .bar { height: 100%; background: var(--brand); transition: width .4s ease; }
.progress .bar.barfull { background: var(--err); }
.capfull { color: var(--err); font-weight: 600; }
.progress.lg { height: 12px; width: 100%; max-width: 520px; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-left: 8px; vertical-align: middle; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.controls { display: flex; gap: 8px; margin: 10px 0; }
.retry-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 4px; }
.retry-form label { font-weight: 600; font-size: 13px; }
.retry-form select { padding: 6px 8px; }
.body-preview { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; white-space: pre-wrap; }

/* pager */
.pager { display: flex; gap: 4px; margin-top: 14px; }
.pager a { padding: 6px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* devices / setup */
.setup { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 20px; }
.steps { margin: 0 0 14px; padding-left: 20px; }
.steps li { margin: 4px 0; }
table.kv { width: auto; border: none; }
table.kv th { background: none; text-align: left; padding: 6px 16px 6px 0; color: var(--muted); white-space: nowrap; }
table.kv td { border: none; padding: 6px 12px 6px 0; }
table.kv code { font-size: 14px; }
.note { background: #f0f4f9; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; }
.note.warn { background: #fef3c7; }

/* 실거래가 목록 — 행 클릭 시 펼쳐지는 상세 행 */
tr.row-expand:hover td { background: #fafbfc; }
tr.detail > td { background: #fafbfc; padding: 10px 14px; }
.trade-detail { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 18px; font-size: 12.5px; }
.trade-detail-item { display: flex; gap: 8px; }
.trade-detail-k { color: var(--muted); flex-shrink: 0; min-width: 64px; }
.trade-detail-v { color: var(--ink); }

/* 전기 조회 진행 로그(SSE) */
.occ-log { background: #0f172a; color: #cbd5e1; border-radius: 8px; padding: 10px 14px; margin: 10px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; max-height: 200px; overflow-y: auto; }
.occ-line { padding: 1px 0; }
.occ-line.ok { color: #4ade80; font-weight: 600; }
.occ-line.err { color: #f87171; font-weight: 600; }
.numform { display: flex; gap: 4px; margin-top: 6px; }
.numform input { padding: 4px 8px; font-size: 12px; width: 130px; }
.numform button { padding: 4px 8px; font-size: 12px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; }
.login-card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.login-card button { margin-top: 14px; background: var(--brand); border-color: var(--brand); color: #fff; padding: 10px; }
.error { background: #fee2e2; color: var(--err); padding: 8px 12px; border-radius: 7px; font-size: 13px; }

/* ── 모바일 반응형 ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-toggle { display: inline-block; }
  .topbar-title { display: inline-block; }
  .topbar .user { display: none; }

  /* 사이드바 = 오프캔버스 드로어 */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60; width: 230px;
    transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 6px 0 24px rgba(0,0,0,.35); }
  body.nav-open .nav-overlay { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }
  .main { width: 100%; min-width: 0; }
  .content { padding: 14px; }
  .topbar { padding: 8px 12px; }
  h1 { font-size: 19px; }
  h2 { font-size: 15px; }

  /* 넓은 표 → 가로 스크롤 (카드형 제외) */
  .content table:not(.cards-mobile) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .list-scroll { max-height: 320px; }

  /* 카드형 표 — 행을 카드로, 셀은 라벨:값 */
  table.cards-mobile, table.cards-mobile tbody { display: block; border: none; background: none; border-radius: 0; }
  table.cards-mobile thead { display: none; }
  table.cards-mobile tr { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 4px 14px; }
  table.cards-mobile td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: none; border-bottom: 1px solid var(--line); padding: 9px 0; text-align: right; white-space: normal; }
  table.cards-mobile tr td:last-child { border-bottom: none; }
  table.cards-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex-shrink: 0; }
  table.cards-mobile td.cell-block, table.cards-mobile td.actions-cell { display: block; text-align: left; }
  table.cards-mobile td.cell-block::before, table.cards-mobile td.actions-cell::before { display: block; margin-bottom: 5px; }
  table.cards-mobile td .tag { margin-bottom: 2px; }
  table.cards-mobile td.truncate { max-width: none; white-space: normal; overflow: visible; }
  table.cards-mobile td.actions-cell .device-actions { flex-wrap: wrap; }
  table.cards-mobile td.actions-cell form.numform { margin-top: 6px; }
  table.cards-mobile td.actions-cell .numform input { flex: 1; }

  /* 필터 입력 가로폭 */
  .filters { gap: 6px; }
  .filters input, .filters select, .filters .btn, .filters button { flex: 1 1 40%; min-width: 0; }
  .filters input[type="search"] { flex: 1 1 100%; }

  /* 카드/그리드 */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-value { font-size: 22px; }
  .grid2 { grid-template-columns: 1fr; }
  .compose-grid { grid-template-columns: 1fr; }
  .progress.lg { max-width: none; }

  /* 설정/주소 표 줄바꿈 */
  table.kv, table.kv tbody, table.kv tr, table.kv th, table.kv td { display: block; width: auto; }
  table.kv th { padding: 8px 0 2px; }
  table.kv code { font-size: 13px; word-break: break-all; }
  .compose { padding: 14px; }
  .device-actions { flex-wrap: wrap; }
}

.sortable th a { color: var(--muted); white-space: nowrap; }
.sortable th a:hover { color: var(--brand); }

/* 도움말 (접기) */
.help { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
.help > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--warn); list-style: revert; }
.help .help-body { padding: 0 16px 12px; font-size: 13px; }
.help .help-body ol { padding-left: 20px; margin: 6px 0; }
.help .help-body li { margin: 3px 0; }
.help .help-body p { margin: 8px 0 4px; }
.help .help-body pre { background: #0f172a; color: #e2e8f0; border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 6px 0; }
.help .help-body pre code { background: none; color: inherit; padding: 0; border-radius: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre; }
.help .help-body :not(pre) > code { background: #eef2f7; border-radius: 4px; padding: 1px 5px; font-size: 12px; }

/* 통합조회(원스탑) 강조 — 볼드 + 화려한 그라데이션 */
.sidebar nav a.nav-hero {
  font-weight: 800;
  color: #fff;
  background: linear-gradient(90deg, #6d28d9 0%, #2563eb 60%, #0ea5e9 100%);
  border-left-color: #f0abfc;
  margin: 4px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.45);
  letter-spacing: 0.2px;
}
.sidebar nav a.nav-hero:hover { filter: brightness(1.12); background: linear-gradient(90deg, #6d28d9 0%, #2563eb 60%, #0ea5e9 100%); }
.sidebar nav a.nav-hero.active { border-left-color: #f0abfc; }
.nav-hero-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  background: rgba(255,255,255,0.22);
  color: #fff;
  padding: 1px 7px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}

/* 통합조회 전기결과 — 조회 대상 호 강조 */
.hl-row > td { background: #fef9c3 !important; }
.hl-row > td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }
.hl-tag { display:inline-block; margin-left:6px; font-size:11px; font-weight:700; color:#92400e; background:#fde68a; padding:1px 7px; border-radius:999px; vertical-align:middle; }

/* 통합조회 최근 히스토리 칩 */
.hist-chips { display:flex; flex-wrap:wrap; gap:6px; }
.hist-chip { display:inline-block; padding:5px 10px; border:1px solid #d1d5db; border-radius:999px; background:#fff; color:#374151; text-decoration:none; font-size:13px; max-width:340px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.hist-chip:hover { border-color:#2563eb; background:#eff6ff; color:#1e40af; }
.hist-chip.search { background:#f9fafb; color:#6b7280; }
.hist-chip.search:hover { background:#f3f4f6; color:#374151; }

/* 히스토리 칩 개별 삭제 버튼 */
.hist-wrap { display:inline-flex; align-items:stretch; }
.hist-wrap .hist-chip { border-top-right-radius:0; border-bottom-right-radius:0; border-right:none; }
.hist-x { border:1px solid #d1d5db; border-left:none; border-top-right-radius:999px; border-bottom-right-radius:999px; background:#fff; color:#9ca3af; cursor:pointer; font-size:14px; line-height:1; padding:0 9px; }
.hist-x:hover { background:#fee2e2; color:#dc2626; border-color:#fca5a5; }
