:root {
  --bg: #f5f7fb; --panel: #fff; --line: #e5e8ef; --text: #1f2430; --muted: #7a8194;
  --primary: #1e6ff1; --primary-soft: #e8f0fe; --danger: #e5484d; --ok: #18a058; --warn: #e6a100;
  --head: #4b5262;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; display: flex; min-height: 100vh; }
a { color: inherit; text-decoration: none; cursor: pointer; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* 레이아웃 */
.sidebar { width: 220px; background: #fff; border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: -.5px; color: #11407e; padding: 0 10px 22px; }
.brand b { color: var(--primary); }
.brand.big { font-size: 30px; text-align: center; padding-bottom: 8px; }
.sidebar nav a { display: block; padding: 11px 12px; border-radius: 8px; margin-bottom: 2px; color: #3a4150; }
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.engine { margin-top: auto; font-size: 12px; padding: 10px 12px; border-radius: 8px; background: var(--bg); color: var(--muted); line-height: 1.6; }
.engine .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--ok); }
.engine.off .dot { background: var(--danger); }
.logout { font-size: 12px; color: var(--muted); padding: 12px; }
main { flex: 1; padding: 28px 34px; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.page-head h1 { white-space: nowrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 8px; }
.spacer { flex: 1; }

/* 버튼 · 폼 */
.btn { border: 1px solid var(--line); background: #fff; padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #c5cbd8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #155bd0; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #4a5162; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; background: var(--primary-soft); padding: 6px 10px; border-radius: 8px; }
.bulk span { font-weight: 600; color: var(--primary); margin-right: 4px; }

/* 통계 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .value.money { color: var(--ok); }

/* 표 */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--head); color: #fff; font-weight: 600; font-size: 13px; padding: 11px 8px; white-space: nowrap; }
.table th:first-child { border-radius: 8px 0 0 8px; }
.table th:last-child { border-radius: 0 8px 8px 0; }
.table td { padding: 11px 8px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.table .left { text-align: left; }
.table tbody tr:hover { background: #fafbfd; }
.table tr.mine td { background: #eaf7ef; font-weight: 600; }
.kw-name { font-weight: 600; }
.kw-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rank-now { font-size: 16px; font-weight: 700; }
.rank-now.good { color: var(--ok); }
.rank-now.bad { color: var(--danger); }
.badge { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.badge.ok { background: #e3f5ea; color: var(--ok); }
.badge.warn { background: #fff4d6; color: #a36f00; }
.badge.err { background: #fde8e8; color: var(--danger); }
.badge.dry { background: #efe9ff; color: #6a43d6; }
.badge.real { background: var(--primary-soft); color: var(--primary); }
.badge.off { background: #eceef2; color: #6b7280; font-size: 11px; padding: 1px 7px; }

.filter-bar { margin-bottom: 14px; }
.pager { display: flex; gap: 4px; justify-content: center; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.stat .value.up { color: var(--danger); } .stat .value.down { color: var(--primary); }

/* 키워드 관리 창: 지금 상태 · 잠긴 칸 */
h4 { font-size: 13px; margin: 16px 0 8px; color: #3a4150; }
.now-box { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0 4px; }
.now-box .cell { background: var(--bg); border-radius: 10px; padding: 12px 14px; }
.now-box .cell .label { font-size: 12px; color: var(--muted); }
.now-box .cell .value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.now-box .cell .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.now-box .why { grid-column: 1 / -1; background: #f3f6ff; border-radius: 10px; padding: 10px 14px; font-size: 13px; line-height: 1.6; }
.lock-note { background: #fff4e6; color: #a34700; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 6px; }
input:disabled, select:disabled { background: #f1f3f6; color: #9aa1ad; }
@media (max-width: 820px) { .now-box { grid-template-columns: 1fr 1fr; } }

/* 예산 플래너 · 등급 · 탐색 */
label.inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
label.inline input[type=number] { width: 130px; }
.scenarios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.scenario { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 16px 18px; cursor: pointer; }
.scenario.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.scenario .label { font-size: 12px; color: var(--muted); }
.scenario .budget { font-size: 20px; font-weight: 700; margin: 4px 0 10px; }
.scenario .line { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.tier { display: inline-block; min-width: 22px; text-align: center; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; color: #fff; }
.tier.A { background: #e8590c; } .tier.B { background: #1e6ff1; } .tier.C { background: #868e96; }
.badge.explore { background: #fff0f6; color: #c2255c; font-size: 11px; padding: 1px 7px; }
.badge.fixed { background: #fff4e6; color: #d9480f; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.explore-box { background: var(--bg); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cell-off { color: var(--muted); }
.cell-pick { background: var(--primary-soft); font-weight: 700; }
@media (max-width: 820px) { .scenarios { grid-template-columns: 1fr; } }

/* 검색 가능한 드롭다운 */
.ss { position: relative; min-width: 0; }
.ss-btn { font: inherit; width: 100%; min-width: 180px; max-width: 360px; text-align: left; padding: 8px 30px 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.ss-btn::after { content: "▾"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.ss-btn:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.ss-panel { position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; width: max(100%, 340px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(20,30,60,.15); padding: 8px; }
.ss-search { width: 100%; margin-bottom: 6px; }
.ss-list { max-height: 320px; overflow-y: auto; }
.ss-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-item.active { background: var(--primary-soft); }
.ss-item.selected { font-weight: 700; color: var(--primary); }
.ss-none { padding: 12px; color: var(--muted); text-align: center; }
label .ss-btn { max-width: none; }
.status-msg { font-size: 12px; color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.empty { text-align: center; padding: 40px; color: var(--muted); line-height: 1.8; }
.up { color: var(--danger); } .down { color: var(--primary); }

/* 토글 */
.switch { position: relative; display: inline-block; width: 42px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd4de; border-radius: 22px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }

/* 계정 */
.acc { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.acc dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 10px 0 0; font-size: 13px; }
.acc dt { color: var(--muted); }
.acc dd { margin: 0; font-family: Consolas, monospace; word-break: break-all; }
.guide ol { margin: 8px 0 0; padding-left: 20px; line-height: 1.9; color: #4a5162; }

/* 다이얼로그 */
dialog { border: none; border-radius: 14px; padding: 24px; width: min(460px, 94vw); box-shadow: 0 20px 60px rgba(20,30,60,.25); }
dialog.wide { width: min(1100px, 96vw); }
dialog::backdrop { background: rgba(20, 28, 45, .45); }
.kw-pick { border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 260px; overflow: auto; margin-bottom: 14px; }
.kw-pick label { flex-direction: row; align-items: center; gap: 8px; margin: 0; padding: 6px 4px; color: var(--text); }
.kw-pick label.disabled { color: var(--muted); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.charts > * { min-width: 0; }
.table td.wrap { white-space: normal; min-width: 240px; }
.chart-box { position: relative; height: 260px; }
.tabs-mini { margin-top: 8px; }
.settings { border-top: 1px solid var(--line); margin-top: 18px; }

/* 스케줄 */
.title-input { font-size: 17px; font-weight: 600; width: 360px; }
.cards { display: flex; gap: 12px; flex-wrap: wrap; }
.bid-card { border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 210px; cursor: pointer; background: #fff; }
.bid-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.bid-card .top { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.bid-card .sw { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.bid-card .x { margin-left: auto; color: var(--muted); cursor: pointer; padding: 0 4px; }
.bid-card input { width: 100%; margin-top: 6px; padding: 6px 8px; }
.bid-card .lbl { font-size: 12px; color: var(--muted); margin-top: 8px; }
.bid-card.add { display: flex; align-items: center; justify-content: center; color: var(--muted); border-style: dashed; min-height: 110px; }
.bid-card.erase .top { color: var(--muted); }
.grid-wrap { overflow-x: auto; user-select: none; }
.sched { border-collapse: separate; border-spacing: 2px; }
.sched th { font-size: 11px; color: var(--muted); font-weight: 500; padding: 4px; }
.sched td { width: 38px; height: 30px; background: #eef0f4; border-radius: 4px; cursor: pointer; font-size: 11px; color: #fff; text-align: center; font-weight: 700; }
.sched td:hover { outline: 2px solid var(--primary); }
.tpl-row { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.tpl-row:last-child { border-bottom: none; }
.tpl-row .name { font-weight: 600; flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 99px; color: #fff; }

/* 분석 */
.recommend { background: #eaf7ef; border: 1px solid #c6ebd4; color: #1d6b3d; padding: 12px 14px; border-radius: 10px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.recommend.none { background: var(--bg); border-color: var(--line); color: var(--muted); }
.table tr.best td { background: #eaf7ef; font-weight: 600; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
.heat th { font-weight: 500; color: var(--muted); padding: 3px 4px; white-space: nowrap; text-align: right; }
.heat td { min-width: 34px; height: 28px; text-align: center; border-radius: 4px; background: #f1f3f6; color: #333; }
.file-btn { cursor: pointer; margin: 0; flex-direction: row; }
.guide-list { margin: 0 0 14px; padding-left: 20px; line-height: 1.9; color: #4a5162; font-size: 13px; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }

/* 부정클릭 */
.snippet { background: #1f2430; color: #e6edf7; padding: 12px 14px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-all; margin: 8px 0; }
textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.site-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.site-row:last-child { border-bottom: none; }
.site-row b { flex: 1; }

/* 로그인 */
.login-body { align-items: center; justify-content: center; }
.login-card { background: #fff; padding: 36px; border-radius: 16px; width: min(380px, 92vw); box-shadow: 0 10px 40px rgba(20,30,60,.08); }
.login-card h2 { text-align: center; margin-bottom: 8px; }
.login-card p { text-align: center; margin: 0 0 18px; font-size: 13px; }
.alert { background: #fde8e8; color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222a3a; color: #fff; padding: 12px 20px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 1000; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }

@media (max-width: 820px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .brand { padding: 0 12px 0 0; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .sidebar nav a { white-space: nowrap; }
  .engine, .logout { display: none; }
  main { padding: 18px 16px; }
  .charts { grid-template-columns: 1fr; }
  .title-input { width: 100%; }
}
