:root {
  --bg: #0e1420;
  --panel: #161e2e;
  --line: #243047;
  --text: #e6eaf2;
  --muted: #8b97ad;
  --accent: #5b8cff;
  --danger: #ff6b6b;
  --warn: #f5b942;
  --ok: #4ade80;

  /* Discord 미리보기 색상 */
  --dc-bg: #313338;
  --dc-embed: #2b2d31;
  --dc-text: #dbdee1;
  --dc-muted: #949ba4;
  --dc-link: #00a8fc;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans KR', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, legend, .brand-name, .preview-head {
  font-family: 'Sora', 'IBM Plex Sans KR', sans-serif;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ── 버튼 ─────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 500;
  border-radius: 8px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07101f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* ── 폼 요소 ─────────────────────────── */
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea, .color-pick {
  display: block;
  margin-top: 6px;
}

input[type='text'], input[type='password'], input[type='url'], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.error { color: var(--danger); margin: 0; font-size: 14px; }
.warn { color: var(--warn); margin: 0; }

/* ── 로그인 ──────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  display: grid;
  gap: 16px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }

/* ── 상단바 ──────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #07101f;
  border-radius: 8px;
  font-size: 16px;
}
.brand-name { font-weight: 600; font-size: 17px; }

.tabs { display: flex; gap: 4px; margin-left: auto; margin-right: 20px; }
.tab {
  padding: 7px 16px; border: 1px solid transparent; background: none; color: var(--muted);
  font: inherit; font-size: 14px; border-radius: 8px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--panel); border-color: var(--line); }

/* ── 작업 영역 ───────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 480px) minmax(0, 1fr);
  gap: 28px;
  padding: 28px;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}

/* ── 기록 화면 ───────────────────────── */
.history-view { max-width: 760px; margin: 0 auto; padding: 28px; }
.history-view .schedule-item .s-side { flex-wrap: wrap; justify-content: flex-end; }

/* ── 템플릿 ──────────────────────────── */
.template-btns { display: flex; gap: 8px; align-items: flex-end; padding-bottom: 2px; }
.template-btns .btn { flex: 1; }

.composer { display: grid; gap: 18px; }

fieldset {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  display: grid;
  gap: 14px;
  min-width: 0;
}
legend {
  padding: 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.row { display: grid; gap: 12px; }
.row.two { grid-template-columns: 1fr 1fr; }
.row.three { grid-template-columns: 1.2fr 1fr auto; align-items: end; }
.row.emoji-title { grid-template-columns: 84px 1fr; }

.emoji-field input { text-align: center; }

.color-pick { display: flex; gap: 8px; }
.color-pick input[type='color'] {
  width: 44px; height: 42px; padding: 2px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}

.check {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px;
}
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.image-list { display: grid; gap: 8px; }
.image-row { display: flex; gap: 8px; }
.image-row input { flex: 1; }
.image-row .btn { padding: 8px 12px; }

.status { margin: 0; padding: 10px 14px; border-radius: 8px; font-size: 14px; border: 1px solid var(--line); }
.status.ok { color: var(--ok); border-color: rgba(74, 222, 128, .4); }
.status.err { color: var(--danger); border-color: rgba(255, 107, 107, .4); }

.actions { display: flex; justify-content: flex-end; }

/* ── 미리보기 ────────────────────────── */
.preview-pane { position: sticky; top: 20px; }
.preview-head { font-weight: 600; margin-bottom: 12px; font-size: 14px; }

.discord-frame {
  background: var(--dc-bg);
  border-radius: 12px;
  padding: 20px 16px;
  color: var(--dc-text);
  font-family: 'gg sans', 'Noto Sans', 'IBM Plex Sans KR', sans-serif;
  border: 1px solid #1e1f22;
}

.msg { display: flex; gap: 14px; }
.avatar {
  flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  background: #fff; color: #5b2d8e;
  display: grid; place-items: center;
  font-size: 20px;
}
.msg-body { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.msg-author { font-weight: 600; color: #b48cff; font-size: 16px; }
.bot-tag {
  background: #5865f2; color: #fff; font-size: 10px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px;
}
.msg-time { color: var(--dc-muted); font-size: 12px; }
.pv-mention { color: #c9cdfb; background: rgba(88,101,242,.3); display: inline-block; padding: 0 3px; border-radius: 3px; margin-bottom: 4px; }

.embed {
  position: relative;
  max-width: 520px;
  background: var(--dc-embed);
  border-left: 4px solid var(--embed-color, #5b2d8e);
  border-radius: 4px;
  padding: 10px 16px 14px 12px;
}
.embed-desc { margin-top: 2px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.embed-desc:empty, .embed-footer:empty { display: none; }
.embed-footer { margin-top: 10px; font-size: 12px; color: var(--dc-muted); }

.embed-images { display: grid; gap: 4px; margin-top: 10px; }
.embed-images:empty { display: none; }
/* 카드 모양에서 "이미지 → 글" 순서를 고르면 이미지를 본문보다 먼저 보여줌 */
.embed.img-first { display: flex; flex-direction: column; }
.embed.img-first .embed-images { order: -1; margin-top: 0; margin-bottom: 10px; }
.embed-images img {
  display: block; width: 100%; border-radius: 6px; object-fit: cover; max-height: 320px; background: #1e1f22;
}

/* 카드 모양(둥근 모서리) · 색상 없음 · 작은 썸네일 미리보기 */
.embed.nocolor { border-left-color: #1e1f22; }
.embed.card {
  border-left: none;
  border-radius: 12px;
  padding: 12px 16px 14px 16px;
}
.embed.card:not(.nocolor) { box-shadow: inset 4px 0 0 var(--embed-color, #5b2d8e); padding-left: 20px; }
.embed.card .embed-images img { border-radius: 10px; }
.embed-thumb {
  position: absolute; top: 12px; right: 14px;
  width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: #1e1f22;
}
.embed.has-thumb { padding-right: 100px; }

/* 서버 이모지 */
.emoji { width: 1.25em; height: 1.25em; vertical-align: -0.3em; object-fit: contain; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; max-height: 168px; overflow-y: auto; padding: 2px; }
.emoji-grid:empty { display: none; }
.emoji-btn {
  width: 40px; height: 40px; padding: 4px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.emoji-btn:hover { border-color: var(--accent); }
.emoji-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.emoji-btn img { width: 28px; height: 28px; object-fit: contain; display: block; }

.reactions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.reaction {
  display: inline-flex; align-items: center; gap: 6px;
  background: #2b2d31; border: 1px solid #3f4147; border-radius: 8px;
  padding: 2px 8px; font-size: 14px; color: var(--dc-muted);
}
.reaction.mine { background: rgba(88,101,242,.15); border-color: #5865f2; }

/* ── 이미지 썸네일 ───────────────────── */
.thumb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.thumb-list:empty { display: none; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: var(--bg);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.loading::after {
  content: '업로드 중…'; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(14, 20, 32, .75); font-size: 12px; color: var(--muted);
}
.thumb .thumb-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; border: 0; background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; font-size: 15px; line-height: 1;
}
.thumb .thumb-del:hover { background: var(--danger); }
.thumb .thumb-del:focus-visible { outline: 2px solid var(--accent); }
.upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ── 토글 스위치 ─────────────────────── */
.switch-row { display: flex; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; color: var(--text); font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 42px; height: 24px; border-radius: 12px; background: var(--line);
  position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 투표 입력 ───────────────────────── */
#poll-fields { display: grid; gap: 12px; }
.poll-answers { display: grid; gap: 8px; }
.answer-row { display: flex; gap: 8px; }
.answer-row input { flex: 1; }
.poll-opts { align-items: end; }
.poll-multi { padding-bottom: 12px; }

/* ── 세그먼트 (지금 / 예약) ──────────── */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; width: fit-content; }
.seg-item { position: relative; margin: 0; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-item span { display: block; padding: 9px 20px; font-size: 14px; color: var(--muted); }
.seg-item input:checked + span { background: var(--accent); color: #07101f; font-weight: 600; }
.seg-item input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
input[type='datetime-local'] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color-scheme: dark;
}

/* ── 미리보기: 투표 (Discord 스타일) ── */
.poll { margin-top: 8px; max-width: 520px; background: var(--dc-embed); border: 1px solid #3f4147; border-radius: 8px; padding: 12px 14px; }
.poll-q { font-weight: 700; color: #f2f3f5; font-size: 15px; word-wrap: break-word; }
.poll-hint { color: var(--dc-muted); font-size: 12px; margin: 2px 0 10px; }
.poll-list { display: grid; gap: 6px; }
.poll-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: #1e1f22; border-radius: 6px; font-size: 14px; color: var(--dc-text); word-break: break-word;
}
.poll-item .dot { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #80848e; }
.poll-item.multi .dot { border-radius: 4px; }

/* ── 예약 목록 ───────────────────────── */
.schedules { margin-top: 26px; }
.schedule-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.schedule-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.schedule-item .s-title { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedule-item .s-meta { grid-column: 1; font-size: 13px; color: var(--muted); }
.schedule-item .s-err { grid-column: 1 / -1; font-size: 13px; color: var(--danger); }
.schedule-item .s-side { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.pending { color: var(--accent); border-color: rgba(91, 140, 255, .5); }
.badge.sent { color: var(--ok); border-color: rgba(74, 222, 128, .4); }
.badge.failed { color: var(--danger); border-color: rgba(255, 107, 107, .4); }
.schedule-item a { color: var(--accent); font-size: 13px; }

@media (max-width: 480px) {
  .seg-item span { padding: 9px 14px; }
}

/* ── 반응형 ──────────────────────────── */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; padding: 16px; }
  .preview-pane { position: static; order: -1; }
  .topbar { padding: 12px 16px; }
}
@media (max-width: 480px) {
  .row.two, .row.three { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
