:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #15171c;
  --sub: #5d6372;
  --line: #e2e4ea;
  --soft: #eef1f8;
  --accent: #2f55d4;
  --accent-ink: #ffffff;
  --ok: #17845a;
  --ok-soft: #e3f4ec;
  --bad: #c43a31;
  --bad-soft: #fbe9e7;
  --wait: #8a6a12;
  --wait-soft: #faf2dc;
  --bubble: #e9eaee;
  --phone: #ffffff;
  --shadow: 0 1px 2px rgba(20, 23, 30, .06), 0 4px 16px rgba(20, 23, 30, .05);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101216; --card: #1a1d23; --ink: #eceef2; --sub: #a1a7b4; --line: #2c3039; --soft: #222630;
    --accent: #7393ff; --accent-ink: #0d1020; --ok: #4cc58f; --ok-soft: #173126; --bad: #ff7d72; --bad-soft: #3a1d1b;
    --wait: #e2bf5d; --wait-soft: #332a12; --bubble: #2a2e37; --phone: #15171c; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101216; --card: #1a1d23; --ink: #eceef2; --sub: #a1a7b4; --line: #2c3039; --soft: #222630;
  --accent: #7393ff; --accent-ink: #0d1020; --ok: #4cc58f; --ok-soft: #173126; --bad: #ff7d72; --bad-soft: #3a1d1b;
  --wait: #e2bf5d; --wait-soft: #332a12; --bubble: #2a2e37; --phone: #15171c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  word-break: keep-all; -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* 머리 */
header.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: -.5px; }
.brand { font-weight: 750; font-size: 17px; letter-spacing: -.2px; line-height: 1.2; }
.brand-box { min-width: 0; }
.space-name { font-size: 11.5px; color: var(--sub); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
nav.bottom.five { grid-template-columns: repeat(5, 1fr); }
details.more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 650; font-size: 14px; min-height: 32px; display: flex; align-items: center; }
.adm { display: grid; gap: 8px; padding: 12px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.adm .who { font-weight: 650; }
.adm .meta { font-size: 12.5px; color: var(--sub); overflow-wrap: anywhere; }
.adm .ctl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.adm .ctl select { min-height: 38px; font-size: 13.5px; }
.adm .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill.off { background: var(--soft); color: var(--sub); }
.temp-pw { font-family: ui-monospace, Consolas, monospace; font-size: 17px; font-weight: 700; letter-spacing: .5px; user-select: all; }
.mode-chip { margin-left: auto; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--wait-soft); color: var(--wait); font-weight: 600; }
.mode-chip.real { background: var(--ok-soft); color: var(--ok); }
nav.tabs { display: none; gap: 4px; margin-left: 18px; }
nav.tabs a, nav.bottom a { text-decoration: none; color: var(--sub); font-weight: 600; }
nav.tabs a { padding: 6px 12px; border-radius: 9px; }
nav.tabs a.on { background: var(--soft); color: var(--ink); }

main { max-width: 1080px; margin: 0 auto; padding: 16px 16px 96px; }
h2 { font-size: 20px; margin: 4px 0 4px; letter-spacing: -.3px; }
.lead { color: var(--sub); margin: 0 0 14px; font-size: 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid2 { display: grid; gap: 14px; }

label.f { display: block; font-size: 13px; color: var(--sub); font-weight: 600; margin: 12px 0 6px; }
label.f:first-child { margin-top: 0; }
input[type=text], input[type=password], input[type=number], input[type=url], textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { resize: vertical; min-height: 120px; }
textarea.mono { font-family: ui-monospace, Consolas, "D2Coding", monospace; font-size: 13px; }
.hint { font-size: 12.5px; color: var(--sub); margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--card); font-weight: 650; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--soft); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 40px; padding: 6px 8px; line-height: 1.3; font-weight: 650; color: var(--sub); cursor: pointer; min-width: 0; overflow-wrap: anywhere; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* 숫자 요약 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.stat span { font-size: 12.5px; color: var(--sub); font-weight: 600; }
.stat.ok b { color: var(--ok); } .stat.bad b { color: var(--bad); }
.stat.big { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; }
.stat.big b { font-size: 34px; }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.queued, .pill.sending { background: var(--wait-soft); color: var(--wait); }
.pill.sent { background: var(--ok-soft); color: var(--ok); }
.pill.failed { background: var(--bad-soft); color: var(--bad); }

.list { border-top: 1px solid var(--line); margin-top: 8px; max-height: 420px; overflow: auto; }
.li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.li .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .num { color: var(--sub); font-variant-numeric: tabular-nums; font-size: 13px; }
.li .why { grid-column: 1 / -1; font-size: 12.5px; color: var(--bad); }
.li.prob .why { color: var(--sub); }

.msg { margin-top: 10px; font-size: 14px; padding: 10px 12px; border-radius: 10px; }
.msg.err { background: var(--bad-soft); color: var(--bad); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.warn { background: var(--wait-soft); color: var(--wait); }

/* 미리보기 폰 */
.phone { width: 300px; max-width: 100%; margin: 0 auto; border-radius: 34px; border: 9px solid #20232a; background: var(--phone); overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.ph-bar { display: flex; justify-content: space-between; padding: 8px 18px 4px; font-size: 11px; font-weight: 700; }
.ph-head { text-align: center; padding: 4px 0 10px; border-bottom: 1px solid var(--line); }
.ph-ava { width: 38px; height: 38px; border-radius: 50%; background: var(--soft); margin: 0 auto 3px; display: grid; place-items: center; font-size: 15px; color: var(--sub); }
.ph-name { font-size: 12px; font-weight: 650; }
.ph-body { padding: 12px 12px 18px; min-height: 360px; max-height: 520px; overflow: auto; }
.ph-type { text-align: center; font-size: 10.5px; color: var(--sub); margin-bottom: 8px; }
.bub { max-width: 86%; background: var(--bubble); border-radius: 18px 18px 18px 6px; overflow: hidden; font-size: 13.5px; line-height: 1.5; }
.bub img { display: block; width: 100%; }
.bub .t { padding: 9px 12px; white-space: pre-wrap; word-break: break-all; }
.bub .t a { color: var(--accent); }
.bub .subj { padding: 9px 12px 0; font-weight: 700; }
.ph-time { font-size: 10px; color: var(--sub); margin: 4px 0 0 4px; }
.linkcard { margin-top: 6px; max-width: 86%; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: 12px; background: var(--card); }
.linkcard img { display: block; width: 100%; max-height: 140px; object-fit: cover; }
.linkcard div { padding: 7px 10px; color: var(--sub); }

.imgbox { display: flex; gap: 12px; align-items: center; }
.imgbox .grow { flex: 1; min-width: 0; }
.btns3 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 12px; }
.btns3 #stopBtn { grid-column: 1 / -1; justify-self: end; }
input[type=file] { max-width: 100%; font-size: 13px; }
.grid2 > * { min-width: 0; }
main { overflow-x: clip; }
.imgbox img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* 아래 탭(폰) */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.bottom a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; padding: 4px 0; }
nav.bottom a svg { width: 22px; height: 22px; }
nav.bottom a.on { color: var(--accent); }

/* 로그인 */
.login { max-width: 380px; margin: 9vh auto 0; }
.login .logo { width: 52px; height: 52px; border-radius: 15px; font-size: 20px; margin-bottom: 14px; }

.sticky-send { position: sticky; bottom: 76px; z-index: 4; }

/* 엑셀 올리기 */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
select { width: 100%; min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
label.check { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 14px; font-weight: 600; cursor: pointer; }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cols3 label.f { margin-top: 12px; }
@media (max-width: 520px) { .cols3 { grid-template-columns: minmax(0, 1fr); gap: 0; } }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

/* AI 초안 */
.lab-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 6px; }
.lab-row label.f { margin: 0; }
.ai-panel { border: 1px solid var(--line); background: var(--soft); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.ai-panel textarea { min-height: 96px; }
.ai-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; }
.ai-card .t { white-space: pre-wrap; word-break: break-all; font-size: 14px; }
.ai-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; font-size: 12.5px; color: var(--sub); }
.ai-card .warnnum { color: var(--wait); font-size: 12.5px; }

@media (min-width: 860px) {
  nav.tabs { display: flex; }
  nav.bottom { display: none; }
  main { padding-bottom: 40px; }
  .grid2 { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); align-items: start; }
  .grid2 > .side { position: sticky; top: 74px; }
  .sticky-send { position: static; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat.big { grid-column: auto; display: block; }
  .stat.big b { font-size: 24px; }
}
