:root {
  --sky-50: #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-200: #bae6fd;
  --sky-300: #7dd3fc;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #0369a1;
  --ink: #0f2a3d;
  --muted: #5b7488;
  --line: #d9ecf8;
  --white: #ffffff;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 18px;
  --shadow: 0 10px 40px -12px rgba(2, 132, 199, 0.25), 0 2px 6px rgba(2, 132, 199, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #bfe7ff 0%, #e6f6ff 45%, #ffffff 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ---------- floating clouds ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 999px;
  opacity: 0.7;
  filter: blur(1px);
  animation: drift linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}
.c1 { width: 220px; height: 60px; top: 12%; left: -240px; animation-duration: 70s; }
.c1::before { width: 100px; height: 100px; top: -50px; left: 30px; }
.c1::after { width: 80px; height: 80px; top: -35px; left: 110px; }
.c2 { width: 160px; height: 45px; top: 55%; left: -200px; animation-duration: 95s; animation-delay: -40s; }
.c2::before { width: 70px; height: 70px; top: -35px; left: 25px; }
.c2::after { width: 60px; height: 60px; top: -25px; left: 80px; }
.c3 { width: 260px; height: 70px; top: 80%; left: -280px; animation-duration: 120s; animation-delay: -80s; opacity: .5; }
.c3::before { width: 120px; height: 120px; top: -60px; left: 40px; }
.c3::after { width: 90px; height: 90px; top: -40px; left: 140px; }
@keyframes drift { to { transform: translateX(calc(100vw + 320px)); } }

/* ---------- header ---------- */
.topbar {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px;
  display: block;
  border-radius: 14px;
  box-shadow: 0 8px 20px -6px rgba(2, 132, 199, .6);
}
.brand h1 { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.8);
  border: 1px solid var(--line);
  font-size: .85rem; font-weight: 600; color: var(--muted);
  backdrop-filter: blur(8px);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.status.ok { color: var(--success); }
.status.ok .dot { background: var(--success); box-shadow: 0 0 0 4px rgba(16,185,129,.18); }
.status.fail { color: var(--danger); }
.status.fail .dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(239,68,68,.15); }

/* ---------- layout ---------- */
.layout {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 24px 48px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: stretch;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(12px);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 18px; flex-wrap: wrap;
}
.card h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }

/* ---------- fields ---------- */
.row { display: flex; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.port { width: 96px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; margin-bottom: 6px;
  font-size: .78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
small { font-weight: 500; text-transform: none; letter-spacing: 0; color: #8aa3b5; }

input, textarea {
  font: inherit; color: inherit;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--sky-50);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus {
  background: #fff;
  border-color: var(--sky-400);
  box-shadow: 0 0 0 4px rgba(56,189,248,.18);
}
.input-wrap { position: relative; }
.input-wrap input { padding-right: 44px; }
.icon-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--sky-100); color: var(--sky-700); }

/* toggle */
.toggle, .check {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 0 16px; font-size: .9rem; cursor: pointer; user-select: none;
}
.toggle input { display: none; }
.track {
  width: 40px; height: 22px; border-radius: 999px;
  background: #cbd5e1; position: relative; transition: background .2s;
  flex-shrink: 0;
}
.thumb {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s;
}
.toggle input:checked + .track { background: var(--sky-500); }
.toggle input:checked + .track .thumb { transform: translateX(18px); }
.check input { accent-color: var(--sky-500); width: 16px; height: 16px; }

.hint {
  margin: 16px 0 0; padding: 12px 14px;
  font-size: .82rem; color: var(--muted); line-height: 1.5;
  background: var(--sky-50); border-radius: 12px; border: 1px dashed var(--sky-200);
}
.hint a { color: var(--sky-600); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border-radius: 12px; border: 1.5px solid transparent;
  font: inherit; font-weight: 700; font-size: .92rem;
  cursor: pointer; transition: transform .1s, box-shadow .2s, background .2s, border-color .2s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.full { width: 100%; }
.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--sky-400), var(--sky-600));
  box-shadow: 0 10px 22px -8px rgba(2,132,199,.7);
}
.btn.primary:hover { box-shadow: 0 14px 28px -8px rgba(2,132,199,.8); }
.btn.ghost {
  color: var(--sky-700); background: #fff; border-color: var(--sky-200);
}
.btn.ghost:hover { background: var(--sky-50); border-color: var(--sky-300); }

.btn.loading .btn-label::after {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 8px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  vertical-align: -2px; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip-btn {
  border: 1px solid var(--sky-200); background: var(--sky-50); color: var(--sky-700);
  font: inherit; font-size: .78rem; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.chip-btn:hover { background: var(--sky-100); }
.presets { display: flex; gap: 6px; }

.link-btn {
  border: 0; background: transparent; color: var(--sky-600);
  font: inherit; font-weight: 700; font-size: .85rem;
  padding: 4px 8px; border-radius: 8px; cursor: pointer;
}
.link-btn:hover { background: var(--sky-50); }
.link-btn.on { background: var(--sky-100); }

/* ---------- compose ---------- */
.compose { display: flex; flex-direction: column; }

.recipients { border-bottom: 1px solid var(--line); }
.recip-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.recip-row:first-child { border-top: 0; }
.recip-label {
  width: 34px; padding-top: 7px;
  font-size: .85rem; font-weight: 700; color: var(--muted);
}
.chips { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 36px; cursor: text; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 12px; border-radius: 999px;
  background: var(--sky-100); color: var(--sky-700);
  font-size: .85rem; font-weight: 600;
  animation: pop .18s ease-out;
}
.chip.invalid { background: #fee2e2; color: #b91c1c; }
.chip button {
  border: 0; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,.7); color: inherit; cursor: pointer;
  display: grid; place-items: center; font-size: 13px; line-height: 1;
}
.chip button:hover { background: #fff; }
.chip-input {
  flex: 1; min-width: 180px; border: 0; outline: none; background: transparent;
  padding: 7px 2px; font-size: .95rem;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }

.subject {
  border: 0; border-bottom: 1px solid var(--line); outline: none;
  padding: 16px 2px; font-size: 1.15rem; font-weight: 700; background: transparent;
}
.subject::placeholder { color: #9bb3c4; }

.editor-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; gap: 10px;
}
.seg { display: inline-flex; padding: 4px; background: var(--sky-50); border-radius: 12px; border: 1px solid var(--line); }
.seg-btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: .82rem; font-weight: 700;
  padding: 6px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.seg-btn.active { background: #fff; color: var(--sky-700); box-shadow: 0 1px 4px rgba(2,132,199,.15); }
.seg-btn:disabled { opacity: .4; cursor: not-allowed; }
.counter { font-size: .8rem; color: #8aa3b5; }

#body, #preview {
  flex: 1; width: 100%; min-height: 300px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: #fff;
}
#body {
  resize: none; padding: 16px; outline: none; line-height: 1.6; font-size: .98rem;
  transition: border-color .15s, box-shadow .15s;
}
#body:focus { border-color: var(--sky-400); box-shadow: 0 0 0 4px rgba(56,189,248,.15); }
#body.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .88rem; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attachments:empty { display: none; }
.file {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 12px; border-radius: 12px;
  background: var(--sky-50); border: 1px solid var(--line);
  font-size: .84rem; animation: pop .18s ease-out;
}
.file .name { font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .size { color: var(--muted); }
.file button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 24px; height: 24px; border-radius: 6px;
}
.file button:hover { background: #fff; color: var(--danger); }

.compose-foot {
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  margin-top: 18px; flex-wrap: wrap;
}
.compose-foot .primary { min-width: 150px; }

.hidden { display: none !important; }

.compose.dragover { outline: 3px dashed var(--sky-300); outline-offset: -8px; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: 14px;
  background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: .9rem; line-height: 1.45;
  animation: slide .25s ease-out;
}
.toast.out { animation: slideOut .25s ease-in forwards; }
.toast .ico {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.toast.success .ico { background: var(--success); }
.toast.error .ico { background: var(--danger); }
.toast.info .ico { background: var(--sky-500); }
.toast strong { display: block; margin-bottom: 2px; }
.toast p { margin: 0; color: var(--muted); word-break: break-word; }
@keyframes slide { from { transform: translateY(12px); opacity: 0; } }
@keyframes slideOut { to { transform: translateX(30px); opacity: 0; } }
