:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f3; --border: #d9dde3;
  --text: #16181d; --text-2: #4a505a; --muted: #6b7280;
  --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e5edff;
  --danger: #c62828; --danger-soft: #fdecec;
  --ok: #1b7a3d; --ok-soft: #e3f4e8;
  --warn: #9a5b00; --warn-soft: #fff3db;
  --bad: #b3261e; --bad-soft: #fde7e5;
  --bar: #3b6fd8; --notice: #fff6d6; --notice-text: #6b4a00;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1b1e24; --surface-2: #252932; --border: #343a45;
    --text: #eceef2; --text-2: #b8bec9; --muted: #8b93a1;
    --accent: #6f9bff; --accent-text: #0b1020; --accent-soft: #1f2a44;
    --danger: #ff7a70; --danger-soft: #3a1d1d;
    --ok: #6fd394; --ok-soft: #173223;
    --warn: #f0b64d; --warn-soft: #3a2c12;
    --bad: #ff8a80; --bad-soft: #3d1c1a;
    --bar: #7aa2ff; --notice: #3a3218; --notice-text: #f3dc9a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 110px; scroll-padding-bottom: 96px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; }
.topbar nav a {
  padding: 8px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none;
  white-space: nowrap; font-size: 15px;
}
.topbar nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar nav a.primary-link { color: var(--accent); font-weight: 600; }
@media (max-width: 420px) { .brand { display: none; } .topbar nav { margin-left: 0; width: 100%; justify-content: space-between; } }

main { max-width: 820px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }

/* 입력 요소 */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); min-height: 46px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
textarea.mono, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, "D2Coding", monospace; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label.field, div.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.req { color: var(--danger); margin-left: 2px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
@media (max-width: 520px) { .row.wrap { flex-direction: column; gap: 0; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* 세그먼트 선택 */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 72px; min-height: 44px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; font-weight: 600; color: var(--text-2);
}
.seg button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* 검색 */
.search-box { position: relative; margin-bottom: 10px; }
.search-box input { font-size: 18px; min-height: 54px; padding-left: 44px; border-radius: 14px; }
.search-box svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
details.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; }
details.filters summary { padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--text-2); }
details.filters .body { padding: 4px 14px 14px; }
.result-bar { display: flex; justify-content: space-between; align-items: center; margin: 6px 2px 10px; font-size: 14px; color: var(--muted); }

/* 카드 */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.card:active { background: var(--surface-2); }
.card-title { font-weight: 700; font-size: 16px; margin-bottom: 6px; word-break: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; }
.chip.dev { background: var(--accent-soft); color: var(--accent); }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status.s-해결 { background: var(--ok-soft); color: var(--ok); }
.status.s-임시조치 { background: var(--warn-soft); color: var(--warn); }
.status.s-미해결 { background: var(--bad-soft); color: var(--bad); }

/* 상세 */
.detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.detail h1 { margin-top: 0; word-break: break-word; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 15px; margin-bottom: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section { margin-top: 18px; }
.section h3 { font-size: 14px; color: var(--text-2); margin: 0 0 6px; }
.pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.similar { margin-top: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.similar ul { list-style: none; margin: 8px 0 0; padding: 0; }
.similar li { padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.similar li a { text-decoration: none; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); }

/* 폼 */
.notice {
  position: sticky; top: 57px; z-index: 5; margin: 0 0 14px; padding: 8px 12px; border-radius: 10px;
  background: var(--notice); color: var(--notice-text); font-size: 13px; font-weight: 600;
}
@media (max-width: 420px) { .notice { top: 53px; } }
.form-actions { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.form-actions .btn { flex: 1; }

/* 통계 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 76px 1fr 34px; align-items: center; gap: 8px; font-size: 13px; }
.bar-row .lbl { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .val { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.bar-track { height: 14px; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 0; }
.hero { font-size: 32px; font-weight: 800; }
.top-list { list-style: none; margin: 0; padding: 0; }
.top-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px; }
.top-list li:first-child { border-top: 0; }
.top-list .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.top-list .cnt { font-weight: 700; font-variant-numeric: tabular-nums; }

/* 설정 */
.cat-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.cat-row input { flex: 1; min-height: 40px; }
.cat-row .used { font-size: 12px; color: var(--muted); width: 48px; text-align: right; }

/* 로그인 */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; }
.login h1 { text-align: center; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
