:root {
  --bg: #05060a;
  --bg-2: #0a0c14;
  --card: rgba(18, 21, 31, .72);
  --card-solid: #12151f;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #e9ecf5;
  --text-dim: #8b93a7;
  --text-faint: #5f677b;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-strong: #9d8bff;
  --accent-soft: rgba(124, 92, 255, .14);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, .13);
  --err: #fb7185;
  --err-soft: rgba(251, 113, 133, .13);
  --radius: 16px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 20px 50px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Pretendard", "Segoe UI", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 8% -8%, rgba(124, 92, 255, .22), transparent 62%),
    radial-gradient(820px 480px at 100% 0%, rgba(34, 211, 238, .14), transparent 58%),
    radial-gradient(700px 700px at 50% 120%, rgba(124, 92, 255, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* 은은한 오로라 */
.aurora {
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 60vh;
  background:
    radial-gradient(closest-side, rgba(124, 92, 255, .20), transparent),
    radial-gradient(closest-side, rgba(34, 211, 238, .12), transparent);
  background-position: 20% 0, 78% 10%;
  background-size: 55% 100%, 45% 100%;
  background-repeat: no-repeat;
  filter: blur(30px);
  pointer-events: none;
  z-index: 0;
  animation: drift 14s ease-in-out infinite alternate;
}

.app-header, .layout { position: relative; z-index: 1; }
@keyframes drift {
  from { transform: translate3d(-2%, 0, 0) scale(1); }
  to { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 30px 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 22px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #7c5cff, #22d3ee);
  box-shadow: 0 10px 28px rgba(124, 92, 255, .45), 0 0 0 1px rgba(255,255,255,.12) inset;
}

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip-muted { background: rgba(255,255,255,.06); color: var(--text-dim); border-color: var(--border); }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(52,211,153,.3); }
.chip-err { background: var(--err-soft); color: var(--err); border-color: rgba(251,113,133,.3); }

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr);
  gap: 22px;
  padding: 18px 20px 20px;
  align-items: stretch;
  overflow: hidden;
}

@media (max-width: 1000px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .layout { grid-template-columns: 1fr; overflow: visible; }
  .card { height: auto; }
  .card-scroll { overflow: visible; }
  .preview-card { height: min(72vh, 660px); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex: 0 0 auto;
}

.card-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  margin-right: -6px;
  display: flex;
  flex-direction: column;
}

.card-scroll > * { flex-shrink: 0; }

.field.body-field {
  flex: 0 0 auto;
  min-height: 0;
}
.field.body-field textarea {
  flex: 0 0 auto;
  height: auto;
  min-height: 110px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px; }

/* ---------- form ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.field > span { font-size: 12.5px; font-weight: 600; color: #b9c0d2; }
.field > span em {
  font-style: normal;
  font-weight: 500;
  color: var(--text-faint);
  font-size: 11.5px;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { .field-row { grid-template-columns: 1fr; } }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(255, 255, 255, .035);
  transition: border-color .16s, box-shadow .16s, background .16s;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { resize: vertical; line-height: 1.58; }
.mono { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

/* ---------- per-field clear button ---------- */
.input-wrap { position: relative; display: flex; flex-direction: column; }
.input-wrap > input, .input-wrap > textarea { width: 100%; padding-right: 40px; }
.field.body-field > .input-wrap { flex: 1 1 auto; min-height: 0; }

.field-clear {
  position: absolute;
  right: 9px;
  z-index: 2;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 11px;
  line-height: 1;
  color: var(--text-faint);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s, opacity .15s;
}
.field-clear:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .13);
  border-color: var(--border-strong);
}
.field-clear.is-hidden { opacity: 0; pointer-events: none; }
.input-wrap > input + .field-clear { top: 50%; transform: translateY(-50%); }
.input-wrap > textarea + .field-clear { top: 9px; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(124, 92, 255, .75);
  background: rgba(124, 92, 255, .06);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .18);
}

select option { background: var(--card-solid); color: var(--text); }

.advanced { margin: 0 0 15px; }
.advanced summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-strong);
  padding: 6px 0;
  user-select: none;
}
.advanced[open] summary { margin-bottom: 8px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 11px;
  width: fit-content;
}
.segmented button {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 7px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.segmented button.active {
  background: linear-gradient(135deg, rgba(124,92,255,.9), rgba(34,211,238,.85));
  color: #fff;
  box-shadow: 0 4px 14px rgba(124,92,255,.35);
}

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }

.attachment-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-list li {
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid rgba(124,92,255,.28);
  padding: 5px 10px;
  border-radius: 9px;
  display: inline-flex; align-items: center; gap: 6px;
}

/* 파일 선택 input */
input[type="file"] {
  font-size: 12.5px;
  color: var(--text-dim);
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  margin-right: 10px;
  padding: 7px 13px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: rgba(255,255,255,.06);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
input[type="file"]::file-selector-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform .06s, box-shadow .18s, background .18s, border-color .18s, color .18s;
}
.btn:active { transform: translateY(1px); }
.btn-icon { font-size: 13px; line-height: 1; }

.btn-ghost {
  background: rgba(255, 255, 255, .04);
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover {
  border-color: rgba(124, 92, 255, .6);
  color: var(--accent-strong);
  background: rgba(124, 92, 255, .08);
}
.btn-tiny { background: transparent; color: var(--text-dim); padding: 5px 10px; font-size: 12px; }
.btn-tiny:hover { color: var(--err); }

.btn-primary {
  background: linear-gradient(135deg, #7c5cff, #4f46e5 55%, #22d3ee 140%);
  color: #fff;
  padding: 12px 28px;
  box-shadow: 0 10px 24px rgba(124, 92, 255, .38);
}
.btn-primary:hover { box-shadow: 0 14px 30px rgba(124, 92, 255, .5); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 10px 24px rgba(225, 29, 72, .34);
}
.btn-danger:hover { box-shadow: 0 14px 30px rgba(225, 29, 72, .46); }
.btn-danger:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.send-group { display: flex; align-items: center; gap: 10px; }

/* ---------- recipients tools ---------- */
.to-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -6px 0 15px;
  flex-wrap: wrap;
}
.count-badge {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.count-badge.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(52, 211, 153, .3); }
.count-badge.warn { background: rgba(251, 191, 36, .13); color: #fbbf24; border-color: rgba(251, 191, 36, .3); }
.file-btn { cursor: pointer; }
.file-btn-row { display: flex; }

/* ---------- tabs / panels ---------- */
.tabs { display: flex; flex-wrap: nowrap; gap: 4px; }
.tabs button {
  border: 0; background: transparent; font: inherit;
  color: var(--text-dim); padding: 8px; border-radius: 9px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 0;
  transition: color .15s, background .15s;
}
.tabs button svg { width: 17px; height: 17px; display: block; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- compose tabs (Write / HTML files) ---------- */
.compose-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--border);
}

.compose-tab {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .2px;
  color: var(--text-dim);
  padding: 8px 14px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.compose-tab:hover { color: var(--text); }
.compose-tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

.compose-panel > *:last-child { margin-bottom: 0; }

.hidden { display: none !important; }

.tab-panel { min-height: 0; }
.tab-panel[data-panel="preview"] { display: flex; flex: 1 1 auto; }
.tab-panel[data-panel="response"] { display: flex; flex: 1 1 auto; }
.tab-panel[data-panel="history"] { display: flex; flex-direction: column; flex: 1 1 auto; }

/* ---------- top-level view tabs (Send / Received) ---------- */
.view-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 30px 24px;
}

.view-tabbar {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 4px;
  padding-left: 10px;
  flex: 0 0 auto;
}

.view-tab {
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  background: rgba(255, 255, 255, .02);
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;
  padding: 9px 22px;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.view-tab:hover { color: var(--text); }
.view-tab.active {
  margin-bottom: -1px;
  background: var(--card-solid);
  color: var(--text);
  border-bottom: 1px solid var(--card-solid);
}

.view-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: 0 14px 14px 14px;
  background: rgba(255, 255, 255, .015);
  overflow: hidden;
}

.layout.single { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }

@media (max-width: 1000px) {
  .view-shell { flex: none; padding: 4px 16px 20px; }
  .view-body { flex: none; overflow: visible; }
}

#previewFrame {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.response-box {
  margin: 0;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  background: #07090f;
  color: #7ef0c0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #07090f;
}
.history-list li {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
  transition: background .15s;
}
.history-list li:last-child { border-bottom: none; }
.history-list li:hover { background: rgba(124, 92, 255, .08); }

.log-num { flex: none; min-width: 20px; text-align: right; color: var(--text-faint); }
.log-time { flex: none; color: var(--text-faint); }
.log-tag { flex: none; font-weight: 700; letter-spacing: .3px; }
.log-tag.ok { color: var(--ok); }
.log-tag.err { color: var(--err); }
.log-tag.warn { color: #fbbf24; }
.log-tag.dim { color: var(--text-dim); }
.log-text { flex: 0 1 auto; min-width: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-dim { flex: 1 1 auto; min-width: 0; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-note { flex: none; color: #fbbf24; }

/* 목록 행 오른쪽 끝 삭제 버튼 */
.log-del {
  flex: none;
  align-self: center;
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  padding: 3px;
  border-radius: 7px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.log-del svg { width: 14px; height: 14px; display: block; }
.log-del:hover { color: var(--err); background: var(--err-soft); }

.history-list li.empty {
  justify-content: center;
  color: var(--text-dim);
  cursor: default;
}
.history-list li.empty:hover { background: transparent; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 4, 8, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: linear-gradient(180deg, rgba(26, 29, 42, .96), rgba(15, 17, 26, .98));
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7), 0 0 0 1px rgba(124,92,255,.12) inset;
  padding: 22px;
  animation: pop .18s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }

.modal-body { display: block; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text-dim);
  width: 32px; height: 32px;
  border-radius: 9px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255,255,255,.08); }

.secret-input { position: relative; display: flex; }
.secret-input input, .secret-input textarea { padding-right: 70px; }
.secret-input textarea { resize: vertical; }
.eye-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  height: 30px;
  padding: 0 10px;
  font-size: 11.5px;
  font-weight: 600;
}
.secret-input textarea + .eye-btn { top: 8px; transform: none; }

.masked { -webkit-text-security: disc; text-security: disc; }

.hint-inline {
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 600;
}

.compose-options {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.check-num input[type="number"] {
  width: 58px;
  padding: 5px 8px;
  text-align: center;
  font-size: 12.5px;
}

.hint {
  margin: 2px 0 18px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}
.hint code {
  font-family: "JetBrains Mono", Consolas, monospace;
  background: rgba(255,255,255,.06);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent-strong);
}

/* ---------- 계정 편집 ---------- */
.account-list { display: flex; flex-direction: column; gap: 10px; }

.account-row {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 12px;
  background: rgba(255, 255, 255, .02);
}

.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 10px;
  padding-right: 28px;
}
@media (max-width: 560px) { .account-grid { grid-template-columns: 1fr; } }

.mini-field { display: flex; flex-direction: column; gap: 4px; }
.mini-field > span {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .2px;
}
.mini-field input {
  font-size: 12.5px;
  padding: 8px 10px;
}

.acc-remove {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 26px;
  height: 26px;
  font-size: 14px;
}

.account-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 11px;
  flex-wrap: wrap;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: #14161f;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 13px 22px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  box-shadow: 0 16px 40px rgba(0,0,0,.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  max-width: 80vw;
  text-align: center;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: rgba(16, 74, 50, .96); border-color: rgba(52,211,153,.4); }
.toast.err { background: rgba(90, 22, 34, .96); border-color: rgba(251,113,133,.4); }

/* ---------- scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.14);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.26); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }
