:root {
  --ink: #15202b;
  --muted: #4d5d6d;
  --accent: #0f766e;
  --ok: #0f766e;
  --warn: #b45309;
  --danger: #b91c1c;
  --glass: rgba(255, 255, 255, 0.48);
  --glass-strong: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(255, 255, 255, 0.62);
  --shadow: 0 12px 36px rgba(21, 42, 58, 0.1);
  --blur: 18px;
  --radius: 18px;
  --side-w: 220px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 8% -10%, #9fd6d0 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, #f3c9a6 0%, transparent 50%),
    radial-gradient(800px 500px at 70% 100%, #b7c9e8 0%, transparent 45%),
    linear-gradient(160deg, #d9e7ef 0%, #e8eef4 45%, #efe6db 100%);
  background-attachment: fixed;
}

.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 28%, rgba(15, 118, 110, 0.18), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(194, 65, 12, 0.14), transparent 26%),
    radial-gradient(circle at 70% 78%, rgba(37, 99, 235, 0.12), transparent 30%);
}

.shell, .auth { position: relative; z-index: 1; }

h1, h2, p { margin-top: 0; }
h1 {
  font-family: "Sora", "Manrope", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0;
}
h2 {
  font-family: "Sora", "Manrope", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 14px;
}
a { color: inherit; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
}

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
  gap: 16px;
  padding: 16px;
  align-items: stretch;
}

.side {
  color: var(--ink);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: var(--radius);
}

.brand {
  font-family: "Sora", sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0 8px;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f766e, #f59e0b);
}

.side nav { display: grid; gap: 4px; }
.side a {
  color: var(--ink);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 12px;
  display: block;
}
.side a.is-on,
.side a:hover { background: rgba(255, 255, 255, 0.5); }
.side a.is-on { font-weight: 700; }

.side-foot { margin-top: auto; padding: 0 8px; }
.linkish {
  background: none;
  border: 0;
  color: var(--ink);
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.who { color: var(--muted); font-size: 0.82rem; margin-top: 6px; }

main {
  min-width: 0;
  padding: 4px 4px 24px;
}
.page { width: 100%; max-width: none; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }
.lead, .muted { color: var(--muted); }
.lead { margin: 8px 0 16px; }

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  padding: 18px;
  margin-bottom: 16px;
  border-radius: var(--radius);
}

.form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 0.9rem; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

input, textarea, select {
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}
textarea { min-height: 140px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  align-items: center;
}
.radio-row .check { margin: 0; }
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.file-input {
  position: absolute;
  width: 0;
  height: 0;
  padding: 0;
  margin: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  clip: rect(0, 0, 0, 0);
}
.upload-btn { position: relative; display: inline-flex; }
.file-name {
  color: var(--muted);
  font-size: 0.88rem;
}
.tempo-block .form, .tempo-block { display: grid; gap: 12px; }
.source-pane[hidden] { display: none; }
.editor-wrap {
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.7);
}
.editor-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.35);
}
.editor-canvas {
  min-height: 220px;
  padding: 12px 14px;
  outline: none;
  line-height: 1.5;
}
.editor-canvas img { max-width: 100%; height: auto; }
.mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; }

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 11px;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:hover { filter: brightness(1.03); }
.btn.primary {
  background: linear-gradient(135deg, #0f766e, #0d9488);
  border-color: transparent;
  color: white;
}
.btn.danger {
  background: linear-gradient(135deg, #e11d48, #be123c);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  box-shadow: 0 10px 24px rgba(190, 18, 60, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.actions.footer {
  justify-content: flex-end;
  margin-top: 8px;
}
.btn.compact {
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: 9px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.actions form { margin: 0; }
.row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}
.row-actions form { margin: 0; display: inline; }
.col-actions { width: 1%; white-space: nowrap; }

main a:not(.btn) { color: #0f5f5a; }

.flash, .note-bad {
  padding: 11px 14px;
  margin-bottom: 14px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.58);
}
.flash-ok { border-color: rgba(15, 118, 110, 0.25); background: rgba(236, 253, 245, 0.75); }
.flash-bad, .note-bad { border-color: rgba(185, 28, 28, 0.22); background: rgba(254, 242, 242, 0.78); }

.worker {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 0.9rem;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: #c2410c; }

.panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  overflow: auto;
}

.list {
  width: 100%;
  border-collapse: collapse;
}
.list th {
  text-align: left;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.22);
  border-bottom: 1px solid rgba(255, 255, 255, 0.4);
  white-space: nowrap;
}
.list td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.32);
  vertical-align: middle;
}
.list tbody tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: rgba(255, 255, 255, 0.28); }
.card .list {
  margin: 0 -6px;
  width: calc(100% + 12px);
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.45);
  white-space: nowrap;
}
.pill-running { background: rgba(209, 250, 229, 0.8); color: #065f46; }
.pill-paused, .pill-queued { background: rgba(254, 243, 199, 0.85); color: #92400e; }
.pill-done { background: rgba(219, 234, 254, 0.85); color: #1e40af; }
.pill-stopped { background: rgba(254, 226, 226, 0.85); color: #991b1b; }
.pill-draft { background: rgba(241, 245, 249, 0.85); color: #334155; }
.pill-sent { background: rgba(209, 250, 229, 0.8); color: #065f46; }
.pill-failed { background: rgba(254, 226, 226, 0.85); color: #991b1b; }
.pill-pending, .pill-sending { background: rgba(254, 243, 199, 0.85); color: #92400e; }
.pill-skipped { background: rgba(241, 245, 249, 0.85); color: #334155; }

.addr-wrap {
  max-height: 420px;
  overflow: auto;
  margin: 0 -6px;
}

.bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.45);
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0 12px;
}
.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #0f766e, #14b8a6);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.stat {
  padding: 12px 14px;
  border-radius: 14px;
}
.stat b {
  display: block;
  font-size: 0.98rem;
  font-weight: 700;
  word-break: break-all;
}
.stat span { color: var(--muted); font-size: 0.8rem; }
.errors { margin: 0; padding-left: 18px; }
.errors li { margin: 4px 0; word-break: break-word; }

.tempo-block {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 22px;
}

.page, .form, .tempo-block, .source-pane { min-width: 0; }
.block-add { display: flex; flex-wrap: wrap; gap: 6px; }
.letter-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.letter-col {
  display: grid;
  gap: 10px;
  min-width: 0;
  align-content: start;
}
.block-list { display: grid; gap: 10px; min-width: 0; }
.letter-block {
  padding: 12px;
  border-radius: 14px;
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.block-tools, .block-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.block-tools { width: 100%; }
.block-tools-end { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.block-row > input,
.block-row > select,
.block-row > button,
.block-row > label {
  width: auto;
  max-width: 100%;
  flex: 0 1 auto;
}
.block-row input[type="color"] {
  width: 2.4rem;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 3px;
}
.drag-handle {
  cursor: grab;
  user-select: none;
  touch-action: none;
  padding: 4px 8px;
  color: var(--muted);
  letter-spacing: -2px;
  font-weight: 700;
}
.drag-handle:active { cursor: grabbing; }
.block-kind {
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
}
.letter-block.is-dragging {
  opacity: 0.4;
  outline: 2px dashed rgba(15, 118, 110, 0.7);
}
.letter-block.drop-before {
  box-shadow: none;
  border-top: 8px solid #0f766e;
}
.letter-block.drop-after {
  box-shadow: none;
  border-bottom: 8px solid #0f766e;
}
.drag-ghost {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  padding: 8px 14px;
  border-radius: 10px;
  background: #0f766e;
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.35);
}
.letter-block.is-collapsed { padding-top: 8px; padding-bottom: 8px; }
.letter-block.is-collapsed .block-body { display: none; }
.block-fold {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.letter-block:not(.is-collapsed) .block-fold { display: none; }
.text-edit {
  min-height: 90px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
}
.img-prev {
  display: block;
  width: auto;
  max-width: 240px;
  max-height: 120px;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  background: #eef2f6;
}
.img-size {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 180px;
  min-width: 0;
  font-size: 0.85rem;
}
.img-size input[type="range"] { flex: 1; min-width: 80px; }
.img-size-val { font-weight: 700; min-width: 2.6rem; }
.gmail-preview {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(21, 32, 43, 0.08);
  min-height: 0;
  align-self: start;
}
.gmail-chrome {
  padding: 10px 14px;
  border-bottom: 1px solid #e6e6e6;
  background: #f6f8fc;
}
.gmail-from { font-size: 0.78rem; color: #5f6368; }
.gmail-subj { font-weight: 700; margin-top: 4px; }
.media-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(21, 32, 43, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
}
.media-modal[hidden] { display: none; }
.media-dialog {
  width: min(860px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  padding: 16px;
  border-radius: 18px;
}
.media-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.media-head h2 { margin: 0; }
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.media-tile {
  position: relative;
  padding: 0;
  border: 1px solid rgba(21, 32, 43, 0.1);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 1;
}
.media-pick {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: #fff;
  cursor: pointer;
}
.media-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-tile:hover { outline: 2px solid #0f766e; }
.media-del {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(185, 28, 28, 0.92);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(185, 28, 28, 0.35);
}
.media-del:hover { filter: brightness(1.08); }

.gmail-preview iframe {
  display: block;
  width: 100%;
  min-height: 240px;
  height: 240px;
  border: 0;
  background: #f2f2f2;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 960px) {
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .shell {
    display: flex;
    flex-direction: column;
    padding: 10px;
  }
  .side { min-height: auto; }
  .side nav { display: flex; gap: 6px; flex-wrap: wrap; }
  .side-foot { margin-top: 8px; }
  .grid-2, .stats { grid-template-columns: 1fr; }
  .letter-split { grid-template-columns: minmax(0, 1fr); }
  .row-actions { flex-wrap: wrap; justify-content: flex-start; }
}
