:root {
  --bg: #11151c; --panel: #1a2029; --panel2: #222a35; --line: #2c3542;
  --text: #e8edf3; --muted: #8b97a7; --dim: #5d6878;
  --approval: #ff8a3d; --ask: #c58cff; --error: #ff5c6c; --working: #3fa7ff;
  --done: #3ecf8e; --unknown: #a3a3a3; --idle: #6b7686; --ended: #4a5260;
  --primary: #3fa7ff; --danger: #ff5c6c; --ok: #3ecf8e;
  --r: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  padding-top: calc(48px + var(--safe-t)); padding-bottom: calc(66px + var(--safe-b)); overscroll-behavior-y: contain; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* 상단·하단 */
.top { position: fixed; top: 0; left: 0; right: 0; z-index: 10; height: calc(48px + var(--safe-t)); padding: var(--safe-t) 16px 0;
  display: flex; align-items: center; gap: 10px; background: rgba(17,21,28,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .title { font-weight: 700; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back { font-size: 22px; padding: 4px 10px 4px 0; background: none; border: 0; }
.live { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.live.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: rgba(17,21,28,.96);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); backdrop-filter: blur(10px); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 0 8px; font-size: 11px; color: var(--muted); position: relative; }
.tabs a .ti { font-size: 20px; line-height: 24px; }
.tabs a.on { color: var(--text); }
.badge { position: absolute; top: 3px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--approval); color: #111; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.badge:empty { display: none; }
main { padding: 12px 16px 24px; max-width: 720px; margin: 0 auto; }

/* 칩 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip b { font-variant-numeric: tabular-nums; }
.chip.warn { border-color: var(--error); color: var(--error); }
.chip.sel { background: var(--panel2); border-color: var(--text); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.sys { font-size: 12px; }
.sys .chip { padding: 4px 9px; font-size: 12px; }

/* 카드 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px;
  border-left: 4px solid var(--c, var(--line)); }
.card.tap:active { background: var(--panel2); }
.card .row1 { display: flex; align-items: center; gap: 8px; }
.card .name { font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .line { color: var(--muted); font-size: 13px; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.card .meta { color: var(--dim); font-size: 12px; margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.tool { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel2); color: var(--muted); font-weight: 600; }
.st { font-size: 12px; font-weight: 700; color: var(--c); white-space: nowrap; }
.est { font-weight: 400; color: var(--dim); }
.s-approval { --c: var(--approval); } .s-ask { --c: var(--ask); } .s-error { --c: var(--error); } .s-working { --c: var(--working); }
.s-done { --c: var(--done); } .s-unknown { --c: var(--unknown); } .s-idle { --c: var(--idle); } .s-ended { --c: var(--ended); }
.card.s-approval { background: linear-gradient(0deg, rgba(255,138,61,.07), rgba(255,138,61,.07)), var(--panel); }
.working-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--working); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* 버튼 */
.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 10px 14px; font-weight: 600; min-height: 44px; cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #061220; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #04150d; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger.fill { background: var(--danger); color: #1a0306; }
.btn.big { width: 100%; min-height: 52px; font-size: 16px; }
.btn.sm { min-height: 34px; padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.btns { display: flex; gap: 8px; margin-top: 10px; }
.btns > .btn { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.phrases { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.phrases::-webkit-scrollbar { display: none; }
.phrases .btn { flex: none; }

/* 상세 */
.screen { background: #0a0d12; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 11px; line-height: 1.35;
  white-space: pre-wrap; word-break: break-all; max-height: 46vh; overflow: auto; margin: 0; color: #cfd8e3; }
.sec { margin: 16px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.sec .sp { flex: 1; }
.text { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; max-height: 40vh; overflow: auto; }
.ev { font-size: 12px; color: var(--muted); padding-left: 16px; margin: 4px 0 0; }
.composer { display: flex; gap: 8px; margin-top: 8px; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 12px; font: inherit; }
.note { font-size: 12px; color: var(--dim); margin-top: 6px; }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }
input[type=search], input[type=password], input[type=number] { width: 100%; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font: inherit; margin-bottom: 10px; }

/* 스위치 */
.sw { position: relative; width: 50px; height: 30px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: var(--line); border-radius: 15px; transition: .2s; }
.sw span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.sw input:checked + span { background: var(--ok); }
.sw input:checked + span::before { transform: translateX(20px); }
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row .lbl { flex: 1; }

/* 시트·토스트 */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--panel); border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + var(--safe-b));
  max-height: 85vh; overflow: auto; max-width: 720px; margin: 0 auto; border-top: 1px solid var(--line); }
.sheet h3 { margin: 0 0 6px; font-size: 17px; }
.sheet p { margin: 0 0 12px; color: var(--muted); font-size: 14px; word-break: break-word; }
.sheet .btn { margin-top: 8px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(78px + var(--safe-b)); z-index: 30; background: #e8edf3; color: #111; border-radius: 12px;
  padding: 12px 14px; font-weight: 600; text-align: center; max-width: 520px; margin: 0 auto; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.bad { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.banner { background: var(--panel2); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.banner .t { flex: 1; }
.banner.warn { border-color: var(--error); color: #ffd0d5; }
.check { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.check input { width: 20px; height: 20px; }
.err { color: var(--error); font-size: 13px; word-break: break-word; }
.paused { opacity: .55; }

/* 로그인 */
body.login { padding: 0; display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { width: min(360px, calc(100% - 32px)); text-align: center; }
.login-box img { border-radius: 18px; }
.login-box h1 { margin: 12px 0 4px; font-size: 22px; }
.login-box input { margin-top: 14px; }
