:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-muted: #fbfbfa;
  --text: #1d1d1b;
  --muted: #72706b;
  --line: #e7e3dc;
  --accent: #7c1a8b;
  --accent-soft: #f7e8fb;
  --danger: #9f2f2d;
  --danger-soft: #fdebec;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(35, 75, 88, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(35, 75, 88, 0.03) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px;
  font-family: "SF Pro Display", "Geist Sans", "Helvetica Neue", Arial, sans-serif;
}

@media (min-width: 981px) {
  body {
    overflow: hidden;
  }
}

button,
input,
select,
textarea {
  font: inherit;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-panel,
.editor-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
}

.auth-panel {
  padding: 40px;
}

.auth-panel-minimal {
  padding: 28px;
}

.turnstile-wrap {
  min-height: 65px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.muted,
.hint {
  color: var(--muted);
  line-height: 1.55;
}

.muted {
  margin: 16px 0 28px;
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
}

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

.field {
  display: grid;
  gap: 7px;
}

.field-full {
  grid-column: 1 / -1;
}

.inline-control {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 8px;
}

.color-select {
  position: relative;
}

.color-select select {
  color: transparent;
  padding-left: 39px;
}

.color-swatch {
  position: absolute;
  top: 50%;
  left: 14px;
  z-index: 1;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}

.color-swatch.green {
  background: #22c55e;
}

.color-swatch.orange {
  background: #f97316;
}

.color-swatch.red {
  background: #ef4444;
}

label {
  font-size: 13px;
  font-weight: 700;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input {
  height: 44px;
  padding: 0 13px;
}

select {
  height: 44px;
  padding: 0 38px 0 13px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 13px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

textarea {
  min-height: 120px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 75, 88, 0.12);
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 1;
  background: var(--surface-muted);
  color: var(--muted);
  cursor: default;
}

.field-invalid label {
  color: var(--danger);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff8f8;
  box-shadow: 0 0 0 3px rgba(159, 47, 45, 0.12);
}

.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.file-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  background: var(--surface-muted);
}

.file-picker:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 26, 139, 0.12);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 6px;
  padding: 0 12px;
  background: #1d1d1b;
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.file-button:hover {
  background: #2d292d;
}

.file-label {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.button-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.icon-button:hover,
.icon-button.is-copied {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-button:active {
  transform: scale(0.96);
}

.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button {
  background: #1d1d1b;
  color: #fff;
}

.accent-button {
  background: var(--accent);
}

.accent-button:hover {
  background: #9b2a9f;
}

.button:hover {
  background: #333330;
}

.secondary-button,
.ghost-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.ghost-button {
  color: var(--muted);
}

.button:active,
.secondary-button:active,
.ghost-button:active {
  transform: scale(0.98);
}

.error {
  margin: 0;
  border: 1px solid rgba(159, 47, 45, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 28px 18px;
}

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

.pending-toggle {
  gap: 8px;
}

.pending-toggle span {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pending-toggle.has-pending span {
  background: var(--accent-soft);
  color: var(--accent);
}

.pending-list {
  display: grid;
  gap: 10px;
  max-height: min(58dvh, 560px);
  margin-top: 22px;
  overflow-y: auto;
  padding-right: 2px;
}

.pending-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.pending-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-muted);
}

.pending-details {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.pending-details strong,
.pending-details span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-details span {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.82fr) minmax(520px, 1.18fr);
  gap: 18px;
  height: calc(100dvh - 132px);
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 28px 28px;
  overflow: hidden;
}

.editor-panel,
.preview-panel {
  min-width: 0;
  padding: 22px;
}

.editor-panel {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading {
  margin-bottom: 20px;
}

.panel-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  border-radius: 999px;
  padding: 5px 9px;
  background: #edf3ec;
  color: #346538;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.recipient-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.preset-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.preset-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.preset-button.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 26, 139, 0.12);
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.actions > button {
  width: 100%;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(29, 29, 27, 0.48);
  animation: modal-fade-in 170ms ease-out both;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop.is-closing {
  pointer-events: none;
  animation: modal-fade-out 140ms ease-in both;
}

.modal-panel {
  width: min(100%, 560px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(29, 29, 27, 0.22);
  animation: modal-rise-in 190ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.modal-backdrop.is-closing .modal-panel {
  animation: modal-rise-out 140ms ease-in both;
}

.pending-modal-panel {
  width: min(100%, 760px);
}

.import-modal-panel {
  width: min(100%, 980px);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-close {
  min-height: 36px;
}

.send-summary {
  display: grid;
  gap: 12px;
  margin: 22px 0 0;
}

.send-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-muted);
}

.send-summary dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.send-summary dd {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.schedule-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 96px;
  gap: 10px;
  margin-bottom: 4px;
}

.schedule-picker label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.schedule-picker select {
  background-color: #ffffff;
  color: var(--text);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.code-textarea {
  min-height: min(240px, 30dvh);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.code-textarea[readonly] {
  background: var(--surface-muted);
  color: var(--muted);
}

.import-actions {
  grid-template-columns: 1fr 1fr 1fr;
}

@keyframes modal-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modal-fade-out {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

@keyframes modal-rise-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modal-rise-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  max-width: min(390px, calc(100vw - 32px));
  border: 1px solid #e7e3dc;
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.98);
  color: #1d1d1b;
  box-shadow: 0 16px 40px rgba(29, 29, 27, 0.14);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
}

.toast::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #7c1a8b;
}

.toast[data-variant="success"] {
  border-color: #d9eadc;
}

.toast[data-variant="success"]::before {
  background: #22c55e;
}

.toast[data-variant="error"] {
  border-color: #f2c3c3;
  background: #fff8f8;
  color: #6f1d1b;
}

.toast[data-variant="error"]::before {
  background: #ef4444;
}

.toast[hidden] {
  display: none;
}

#preview {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #17121a;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .editor-panel,
  .preview-panel {
    overflow: visible;
  }

  #preview {
    flex: none;
    min-height: 640px;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 22px 16px 14px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > button {
    flex: 1;
  }

  .workspace {
    padding: 0 16px 16px;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading-actions > button {
    width: 100%;
  }

  .actions,
  .import-grid,
  .import-actions {
    grid-template-columns: 1fr;
  }

  .recipient-presets,
  .pending-item,
  .schedule-picker {
    grid-template-columns: 1fr;
  }

  .auth-panel,
  .editor-panel,
  .preview-panel {
    padding: 20px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  #preview {
    min-height: 560px;
  }
}

@media (max-width: 420px) {
  .topbar h1 {
    font-size: 31px;
  }

  .workspace {
    padding-left: 10px;
    padding-right: 10px;
  }

  .auth-panel,
  .editor-panel,
  .preview-panel {
    padding: 16px;
  }
}
