:root {
  --ground: #F3F2EF; --surface: #FFFFFF; --ink: #1B1D21; --muted: #5F6368;
  --line: #E2E0DB; --field: #F7F6F3; --border: #D6D3CD;
  --accent: #1F6F5C; --accent-hover: #185A4A; --accent-tint: #E4F0EC; --accent-ring: #9CC5B8;
  --dark: #1B1D21; --dark2: #24272C; --dark3: #2C3036; --dark-line: #3A3D42; --dark-muted: #A9ADB3; --mint: #7FC7B2;
  --warn-bg: #FDF1E7; --warn-ink: #8A3B06; --danger: #B42318;
  --s1: #B42318; --s2: #B54708; --s3: #4D7A1F; --s4: #1F6F5C;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--ground); color: var(--ink); font-size: 15px; line-height: 1.45;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon, .icon-btn svg, .lock-icon svg, .brand-icon svg { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1 1 160px; min-width: 0; }
.self-end { align-self: flex-end; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 15px; white-space: nowrap;
}
.btn:hover { background: var(--field); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; min-height: 48px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
.icon-btn:hover { background: var(--field); }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 14px; padding: 8px; min-height: 44px; text-decoration: underline; text-underline-offset: 3px; }

/* 입력 */
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); text-align: left; }
.fld input, .fld select, .fld textarea, .row > input {
  min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 15px; width: 100%;
}
.fld textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 0; text-align: left; }

/* 잠금 화면 */
.lock { min-height: 100vh; min-height: 100dvh; background: var(--dark); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.lock-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 18px; padding: 36px 28px 24px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.lock-icon { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-tint); color: var(--accent); display: flex; align-items: center; justify-content: center; align-self: center; }
.lock-icon svg { width: 30px; height: 30px; }
.lock-card h1 { margin: 0; font-size: 22px; }
.lock-fields { display: flex; flex-direction: column; gap: 14px; }
.lock-msg { margin: 0; min-height: 1.2em; color: var(--danger); font-size: 14px; }

/* 앱 레이아웃 */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 236px; flex: none; background: var(--dark); color: var(--ground); padding: 24px 14px;
  display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.brand-text strong { font-size: 17px; }
.me { font-size: 12px; color: var(--dark-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cats { display: flex; flex-direction: column; gap: 2px; }
.cat {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 8px 12px;
  border: none; border-radius: 8px; background: transparent; color: #C9CCD1; font-size: 14px; text-align: left;
}
.cat:hover { background: var(--dark2); }
.cat.on { background: var(--dark3); color: #fff; }
.cat .n { font-size: 13px; color: var(--dark-muted); }
.cat .warn-dot { color: #F2A266; }
.side-label { font-size: 12px; color: var(--dark-muted); padding: 0 12px; }
.groups-wrap { display: flex; flex-direction: column; gap: 6px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.side-foot .side-label { padding: 0 6px 4px; }
.side-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border: 1px solid var(--dark-line);
  border-radius: var(--radius); background: transparent; color: var(--ground); font-size: 14px;
}
.side-btn:hover { background: var(--dark2); }
.m-only { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px; padding: 24px 28px 20px; align-items: center; }
.search { flex: 1 1 280px; position: relative; display: block; }
.search .icon { position: absolute; left: 14px; top: 13px; color: var(--muted); }
.search input {
  width: 100%; height: 44px; padding: 0 14px 0 42px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 15px;
}
.panes { flex: 1; display: flex; gap: 20px; padding: 0 28px 28px; align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.list-pane { flex: 1 1 360px; min-width: 0; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.list-head { font-size: 13px; color: var(--muted); padding: 10px 12px 8px; }
#list { display: flex; flex-direction: column; gap: 2px; }
.item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--ink);
}
.item:hover { background: var(--field); }
.item.on { background: var(--accent-tint); border-color: var(--accent-ring); }
.tile { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; flex: none; }
.tile.big { width: 56px; height: 56px; border-radius: 14px; font-size: 22px; }
.item-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.item-name { font-size: 15px; font-weight: 500; display: flex; align-items: center; gap: 6px; min-width: 0; }
.item-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star { color: #C68A00; display: flex; }
.star svg { width: 16px; height: 16px; }
.badge { font-size: 11px; font-weight: 500; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 2px 6px; flex: none; }
.badge.grp { color: var(--muted); background: var(--field); }

.detail-pane { flex: 1 1 380px; min-width: 0; padding: 28px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 20px; }
.d-head { display: flex; align-items: center; gap: 16px; }
.d-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.d-title h2 { margin: 0; font-size: 22px; overflow-wrap: anywhere; }
.d-title a { font-size: 14px; overflow-wrap: anywhere; }
.d-field { display: flex; flex-direction: column; gap: 8px; }
.d-label { font-size: 13px; color: var(--muted); }
.d-value { flex: 1; min-width: 0; background: var(--field); border-radius: var(--radius); padding: 12px 14px; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-value.wrap { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
.d-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 18px; }
.warn { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.warn svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 16px; align-items: center; }
.back { display: none; }

/* 강도 표시 */
.meter-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; min-height: 18px; }
.meter { flex: 1; display: flex; gap: 4px; }
.meter span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.meter.s1 span:nth-child(-n+1) { background: var(--s1); }
.meter.s2 span:nth-child(-n+2) { background: var(--s2); }
.meter.s3 span:nth-child(-n+3) { background: var(--s3); }
.meter.s4 span { background: var(--s4); }
.meter-label { font-size: 13px; font-weight: 500; min-width: 56px; text-align: right; }
.meter-label.s1 { color: var(--s1); } .meter-label.s2 { color: var(--s2); } .meter-label.s3 { color: var(--s3); } .meter-label.s4 { color: var(--s4); }

/* 대화상자 */
.dlg { border: none; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); }
.dlg.wide { width: min(720px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(20, 21, 24, .55); }
.dlg form#edit-form { display: contents; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-head .icon-btn { border: none; }
.dlg-body { padding: 4px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 20px; position: sticky; bottom: 0; background: var(--surface); }
.set { display: flex; flex-direction: column; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: none; padding-bottom: 0; }
.set h3 { margin: 0; font-size: 15px; }
.set .btn { align-self: flex-start; }
.set form { display: flex; flex-direction: column; gap: 10px; }
.file-btn { position: relative; }
.code-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--accent-tint); border-radius: var(--radius); padding: 14px 16px; }
.code-box .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: 1px; color: var(--accent-hover); flex: 1; }
.table { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tr { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.tr:first-child { border-top: none; }
.tr .who { flex: 1 1 180px; min-width: 0; display: flex; flex-direction: column; }
.tr .who strong { font-weight: 500; }
.tr .who span { font-size: 12px; color: var(--muted); }
.tr .acts { display: flex; gap: 6px; }
.pill { font-size: 12px; border-radius: 6px; padding: 2px 8px; background: var(--field); color: var(--muted); }
.pill.admin { background: var(--accent-tint); color: var(--accent-hover); }
.pill.off { background: var(--warn-bg); color: var(--warn-ink); }

/* 알림 */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 100; background: var(--dark); color: var(--ground);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  max-width: calc(100vw - 32px);
}
.toast svg { width: 18px; height: 18px; flex: none; color: var(--mint); }
.toast .sub { color: var(--dark-muted); }

/* 폰 */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; background: var(--ground); color: var(--ink); padding: 18px 16px 6px; gap: 12px; overflow: visible; }
  .brand-icon { display: none; }
  .brand { padding: 0; }
  .brand-text strong { font-size: 24px; }
  .me { color: var(--muted); }
  .m-only { display: inline-flex; }
  .cats { flex-direction: row; overflow-x: auto; gap: 8px; padding-bottom: 4px; scrollbar-width: none; }
  .cat { flex: none; width: auto; min-height: 38px; border-radius: 19px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
  .cat:hover { background: var(--surface); }
  .cat.on { background: var(--dark); border-color: var(--dark); color: #fff; }
  .cat .n { color: inherit; opacity: .7; }
  .side-label { color: var(--muted); padding: 0 2px; }
  .side-foot { display: none; }
  .topbar { padding: 4px 16px 12px; }
  #btn-gen span { display: none; }
  #btn-gen { width: 44px; padding: 0; }
  .fab { position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px; padding: 0; z-index: 50; box-shadow: 0 8px 20px rgba(31,111,92,.35); }
  .fab span { display: none; }
  .fab .icon { width: 24px; height: 24px; }
  .panes { padding: 0 16px 100px; flex-direction: column; align-items: stretch; }
  .detail-pane { display: none; position: static; padding: 20px; }
  body.show-detail .detail-pane { display: flex; }
  body.show-detail .list-pane, body.show-detail .topbar, body.show-detail .cats, body.show-detail .groups-wrap, body.show-detail .fab { display: none; }
  .back { display: inline-flex; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .lock { background: var(--dark); }
}
.d-title a { color: var(--accent); text-underline-offset: 3px; }
.d-title a:hover { color: var(--accent-hover); }
.set form.row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.set form.row .fld:not(.grow) { flex: 0 0 auto; }
.set form.row .btn { align-self: flex-end; }
