* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans KR', 'Pretendard Variable', sans-serif;
  color: #121826;
  background: #EEF1F6;
}
button, input { font: inherit; }
a { color: #1F4FD1; }
a:hover { color: #163A9E; }

.app { min-height: 100vh; display: flex; flex-wrap: wrap; }

/* ---------- 왼쪽 패널 ---------- */
.side {
  font-family: 'Pretendard Variable', Pretendard, sans-serif;
  flex: 1 1 260px; max-width: 300px;
  background: #0F1A2E; color: #DCE3F0;
  padding: 26px 20px; display: flex; flex-direction: column; gap: 22px;
  min-height: 100vh; position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: #1F4FD1; display: flex; align-items: center; justify-content: center; }
.brand-name { font-weight: 800; font-size: 19px; color: #fff; letter-spacing: -0.02em; }
.side-label { font-size: 12.5px; font-weight: 600; letter-spacing: 0.04em; color: #9AA8C2; }

.kw-nav { display: flex; flex-direction: column; gap: 6px; }
.kw-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 9px; border: 0;
  background: transparent; color: #DCE3F0; cursor: pointer; text-align: left;
  font-family: inherit; font-size: 15px; font-weight: 500; letter-spacing: -0.01em;
}
.kw-item:hover { background: #17253F; }
.kw-item.on { background: #1F4FD1; color: #fff; font-weight: 700; }
.kw-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-item .cnt { font-size: 12px; font-weight: 600; color: #9AA8C2; padding: 2px 8px; border-radius: 10px; flex: 0 0 auto; }
.kw-item.on .cnt { background: rgba(255,255,255,0.2); color: #fff; }
.kw-empty { font-size: 13.5px; color: #9AA8C2; line-height: 1.6; }

.side-actions { display: flex; flex-direction: column; gap: 10px; }
.side-btn {
  font-family: inherit; width: 100%; min-height: 48px; border-radius: 10px;
  border: 1px solid #C9D1DF; background: #fff; color: #121826;
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em; cursor: pointer;
}
.side-btn:hover { background: #F1F4F9; }
.side-btn-primary { background: #fff; border-color: #fff; font-weight: 800; }
.side-btn:disabled { opacity: 0.6; cursor: progress; }

.side-api { margin-top: auto; border-top: 1px solid #22314F; padding-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.side-api-title { font-size: 12.5px; font-weight: 600; color: #9AA8C2; }
.side-api-status { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: #F87171; }
.dot.ok { background: #34D399; }
.linkbtn { font-family: inherit; background: none; border: 0; padding: 0; text-align: left; color: #8FB0FF; font-size: 14px; cursor: pointer; min-height: 28px; }
.linkbtn:hover { color: #B9CCFF; text-decoration: underline; }

/* ---------- 오른쪽 본문 ---------- */
.main { flex: 999 1 560px; min-width: 0; padding: 32px 40px; display: flex; flex-direction: column; gap: 24px; }
.empty { background: #fff; border: 1px solid #DDE3EC; border-radius: 12px; padding: 48px; text-align: center; color: #5A6478; }
.empty h2 { margin: 0 0 8px; color: #121826; font-size: 22px; }

#kwView { display: flex; flex-direction: column; gap: 24px; }
#kwView[hidden], .empty[hidden] { display: none; }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .cards { grid-template-columns: minmax(0, 1fr); } .main { padding: 20px; } }
.card { background: #fff; border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; border: 1px solid #DDE3EC; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-title { font-weight: 600; font-size: 15px; }
.card-title small { font-weight: 500; color: #5A6478; margin-left: 6px; }
.card-hint { font-size: 12px; color: #5A6478; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; min-height: 32px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border-radius: 16px; font-size: 13px; border: 0; }
.chip button { border: 0; background: transparent; cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px; border-radius: 10px; color: inherit; }
.chip button:hover { background: rgba(0,0,0,0.08); }
.chip.term { background: #E6EDFF; color: #163A9E; }
.chip.ban { background: #FDECEC; color: #9B1C1C; }
.chips .none { font-size: 13px; color: #8A93A5; align-self: center; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #5A6478; }
.field input { min-height: 42px; border: 1px solid #C9D1DF; border-radius: 8px; padding: 0 12px; font-size: 14px; color: #121826; }
.field input:focus, .filter:focus { outline: 2px solid #1F4FD1; outline-offset: -1px; border-color: #1F4FD1; }
.mini-danger { border: 1px solid #F1C7C7; background: #fff; color: #9B1C1C; border-radius: 6px; font-size: 12px; min-height: 30px; padding: 0 10px; cursor: pointer; }
.mini-danger:hover { background: #FDECEC; }

.list { background: #fff; border-radius: 12px; border: 1px solid #DDE3EC; overflow: hidden; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid #E6EAF1; flex-wrap: wrap; gap: 10px; }
.list-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 0 12px; min-height: 40px; border-radius: 8px; cursor: pointer; color: #5A6478; font-size: 14px; }
.tab.on { background: #EEF1F6; color: #121826; font-weight: 600; }
.list-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filter { min-height: 36px; border: 1px solid #C9D1DF; border-radius: 8px; padding: 0 12px; font-size: 13px; width: 200px; }
.muted { color: #5A6478; font-size: 13px; }
.small { font-size: 12.5px; line-height: 1.6; }

.row { display: flex; gap: 16px; padding: 16px 20px; border-bottom: 1px solid #EEF1F6; align-items: flex-start; }
.row:last-child { border-bottom: 0; }
.row .time { flex: 0 0 76px; font-size: 13px; color: #5A6478; padding-top: 2px; }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row .title { font-weight: 600; font-size: 15px; text-decoration: none; color: #121826; line-height: 1.45; }
.row .title:hover { color: #1F4FD1; text-decoration: underline; }
.row .desc { font-size: 13px; color: #5A6478; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .src { font-size: 12.5px; color: #5A6478; }
.row .why { font-size: 12px; color: #9B1C1C; background: #FDECEC; padding: 1px 8px; border-radius: 10px; margin-left: 6px; }
.row.new .time::after { content: "NEW"; display: block; font-size: 10px; font-weight: 700; color: #1F4FD1; margin-top: 2px; }
.group { border-bottom: 1px solid #EEF1F6; }
.group:last-child { border-bottom: 0; }
.group .row { border-bottom: 0; }
.thumb { flex: 0 0 120px; width: 120px; height: 80px; border-radius: 8px; overflow: hidden; background: #EEF1F6; }
.thumb[hidden] { display: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rel-btn { margin-left: 10px; border: 1px solid #C9D1DF; background: #F5F7FB; color: #1F4FD1; border-radius: 12px; font-size: 12px; font-weight: 600; min-height: 26px; padding: 0 10px; cursor: pointer; }
.rel-btn:hover, .rel-btn.open { background: #E6EDFF; border-color: #B7C7F5; }
.sub { margin: 0 20px 14px 112px; border-left: 2px solid #DDE3EC; padding-left: 14px; display: flex; flex-direction: column; gap: 10px; }
.sub-row { display: flex; gap: 12px; align-items: baseline; }
.sub-row .time { flex: 0 0 76px; font-size: 12px; color: #5A6478; }
.sub-body { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; min-width: 0; }
.sub-title { font-size: 14px; color: #121826; text-decoration: none; }
.sub-title:hover { color: #1F4FD1; text-decoration: underline; }
@media (max-width: 700px) { .thumb { flex-basis: 84px; width: 84px; height: 60px; } .sub { margin-left: 20px; } }
.no-rows { padding: 40px 20px; text-align: center; color: #5A6478; font-size: 14px; }

/* ---------- 대화상자 / 알림 ---------- */
dialog { border: 0; border-radius: 14px; padding: 24px; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(15,26,46,0.25); }
dialog::backdrop { background: rgba(15,26,46,0.45); }
dialog h3 { margin: 0 0 16px; font-size: 18px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.btn { min-height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid #C9D1DF; background: #fff; color: #121826; font-size: 14px; cursor: pointer; }
.btn-primary { background: #1F4FD1; border-color: #1F4FD1; color: #fff; font-weight: 600; }
#apiTestMsg.ok { color: #047857; }
#apiTestMsg.err { color: #B91C1C; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: #121826; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .side { max-width: none; flex-basis: 100%; height: auto; min-height: 0; position: static; }
}
.sub .src { font-size: 12.5px; color: #5A6478; }
.sub .why { font-size: 12px; color: #9B1C1C; background: #FDECEC; padding: 1px 8px; border-radius: 10px; margin-left: 6px; }
