* { box-sizing: border-box; }
:root {
  --bg: #f5f6f8; --panel: #fff; --line: #e3e6ea; --ink: #1c2430; --muted: #8a93a0;
  --brand: #2563eb; --brand-d: #1d4ed8; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
}
html, body { margin: 0; padding: 0; }
body { font: 14px/1.5 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #131a24; color: #c7d0db; flex-shrink: 0; }
.brand { font-weight: 700; color: #fff; padding: 18px 18px 10px; font-size: 15px; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a { color: #c7d0db; padding: 10px 18px; }
.sidebar nav a:hover { background: #1b2430; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar nav a.disabled { color: #5b6675; pointer-events: none; }
.nav-section { font-size: 11px; color: #5b6675; padding: 16px 18px 4px; text-transform: uppercase; letter-spacing: .05em; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; color: var(--ink); }
.topbar-title { display: none; font-weight: 700; }
.nav-overlay { display: none; }
.topbar .user { font-weight: 600; }
.content { padding: 24px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card-label { color: var(--muted); font-size: 12px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.grid2 > * { min-width: 0; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, monospace; }
.muted { color: var(--muted); }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* forms / buttons */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
textarea { width: 100%; resize: vertical; }
button, .btn { font: inherit; cursor: pointer; padding: 7px 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
button:hover, .btn:hover { background: #f0f2f5; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--brand-d); }
button.danger { background: var(--err); border-color: var(--err); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { border: none; background: none; color: var(--brand); padding: 0; }
.chk { display: inline-flex; align-items: center; gap: 5px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

/* compose */
.compose { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; max-width: 640px; display: flex; flex-direction: column; gap: 6px; }
.compose label { font-weight: 600; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.recipient-banner { background: #eef4ff; border: 1px solid #cfe0ff; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

/* compose 2단 레이아웃 */
.compose-grid { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .compose-grid { grid-template-columns: 1fr; } }
.compose-grid h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.compose-grid .compose { max-width: none; }
.list-scroll { max-height: 460px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.list-scroll table { border: none; border-radius: 0; }
.recipient-table th { position: sticky; top: 0; }
.recipient-table tbody tr { cursor: pointer; }
.recipient-table tbody tr:hover { background: #f0f4ff; }
.recipient-table tbody tr.sel { background: #dbe7ff; }

/* 미리보기 패널 */
.preview { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.preview h4 { margin: 0 0 10px; font-size: 14px; }
.preview-detail { display: grid; grid-template-columns: 64px 1fr; gap: 4px 10px; margin: 0 0 12px; }
.preview-detail dt { color: var(--muted); font-size: 13px; }
.preview-detail dd { margin: 0; font-size: 13px; }
.preview-msg-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.preview-msg { white-space: pre-wrap; background: #eef4ff; border: 1px solid #cfe0ff; border-radius: 8px; padding: 12px; font-size: 14px; min-height: 40px; }

/* batch */
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 5px; background: #eef1f5; color: #475569; margin: 1px 2px 1px 0; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eef1f5; color: var(--ink); }
.badge.active, .badge.sending { background: #e0edff; color: var(--brand-d); }
.badge.sent, .badge.done { background: #dcfce7; color: var(--ok); }
.badge.failed, .badge.canceled { background: #fee2e2; color: var(--err); }
.badge.queued, .badge.paused { background: #fef3c7; color: var(--warn); }
.progress { height: 6px; background: #eef1f5; border-radius: 99px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.progress .bar { height: 100%; background: var(--brand); transition: width .4s ease; }
.progress .bar.barfull { background: var(--err); }
.capfull { color: var(--err); font-weight: 600; }
.progress.lg { height: 12px; width: 100%; max-width: 520px; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-left: 8px; vertical-align: middle; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.controls { display: flex; gap: 8px; margin: 10px 0; }
.body-preview { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; white-space: pre-wrap; }

/* pager */
.pager { display: flex; gap: 4px; margin-top: 14px; }
.pager a { padding: 6px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* devices / setup */
.setup { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 20px; }
.steps { margin: 0 0 14px; padding-left: 20px; }
.steps li { margin: 4px 0; }
table.kv { width: auto; border: none; }
table.kv th { background: none; text-align: left; padding: 6px 16px 6px 0; color: var(--muted); white-space: nowrap; }
table.kv td { border: none; padding: 6px 12px 6px 0; }
table.kv code { font-size: 14px; }
.note { background: #f0f4f9; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; }
.note.warn { background: #fef3c7; }
.numform { display: flex; gap: 4px; margin-top: 6px; }
.numform input { padding: 4px 8px; font-size: 12px; width: 130px; }
.numform button { padding: 4px 8px; font-size: 12px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; }
.login-card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.login-card button { margin-top: 14px; background: var(--brand); border-color: var(--brand); color: #fff; padding: 10px; }
.error { background: #fee2e2; color: var(--err); padding: 8px 12px; border-radius: 7px; font-size: 13px; }

/* ── 모바일 반응형 ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-toggle { display: inline-block; }
  .topbar-title { display: inline-block; }
  .topbar .user { display: none; }

  /* 사이드바 = 오프캔버스 드로어 */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60; width: 230px;
    transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 6px 0 24px rgba(0,0,0,.35); }
  body.nav-open .nav-overlay { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }
  .main { width: 100%; min-width: 0; }
  .content { padding: 14px; }
  .topbar { padding: 8px 12px; }
  h1 { font-size: 19px; }
  h2 { font-size: 15px; }

  /* 넓은 표 → 가로 스크롤 (카드형 제외) */
  .content table:not(.cards-mobile) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .list-scroll { max-height: 320px; }

  /* 카드형 표 — 행을 카드로, 셀은 라벨:값 */
  table.cards-mobile, table.cards-mobile tbody { display: block; border: none; background: none; border-radius: 0; }
  table.cards-mobile thead { display: none; }
  table.cards-mobile tr { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 4px 14px; }
  table.cards-mobile td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: none; border-bottom: 1px solid var(--line); padding: 9px 0; text-align: right; white-space: normal; }
  table.cards-mobile tr td:last-child { border-bottom: none; }
  table.cards-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex-shrink: 0; }
  table.cards-mobile td.cell-block, table.cards-mobile td.actions-cell { display: block; text-align: left; }
  table.cards-mobile td.cell-block::before, table.cards-mobile td.actions-cell::before { display: block; margin-bottom: 5px; }
  table.cards-mobile td .tag { margin-bottom: 2px; }
  table.cards-mobile td.truncate { max-width: none; white-space: normal; overflow: visible; }
  table.cards-mobile td.actions-cell .device-actions { flex-wrap: wrap; }
  table.cards-mobile td.actions-cell form.numform { margin-top: 6px; }
  table.cards-mobile td.actions-cell .numform input { flex: 1; }

  /* 필터 입력 가로폭 */
  .filters { gap: 6px; }
  .filters input, .filters select, .filters .btn, .filters button { flex: 1 1 40%; min-width: 0; }
  .filters input[type="search"] { flex: 1 1 100%; }

  /* 카드/그리드 */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-value { font-size: 22px; }
  .grid2 { grid-template-columns: 1fr; }
  .compose-grid { grid-template-columns: 1fr; }
  .progress.lg { max-width: none; }

  /* 설정/주소 표 줄바꿈 */
  table.kv, table.kv tbody, table.kv tr, table.kv th, table.kv td { display: block; width: auto; }
  table.kv th { padding: 8px 0 2px; }
  table.kv code { font-size: 13px; word-break: break-all; }
  .compose { padding: 14px; }
  .device-actions { flex-wrap: wrap; }
}
