/* Editor chrome. The preview's own styling lives in the iframe skeleton
   (src/render/shell.rs) so that it cannot leak into the exported email. */

:root {
  --accent: #2563eb;
  --border: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --panel: #ffffff;
  --shell: #f6f8fb;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--shell);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Shown until the wasm bundle mounts, and left in place carrying an
   explanation if it never does. */
.boot {
  display: block;
  max-width: 34rem;
  margin: 18vh auto 0;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.boot-failed {
  border-color: #fecdd3;
  color: var(--ink);
}

/* Toolbar ---------------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 650;
}

.brand-mark {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.brand-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.subject {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

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

.subject input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: inherit;
  background: #fff;
}

.segments {
  display: flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #f1f5f9;
}

.segment {
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segment.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.12);
}

button {
  font: inherit;
  cursor: pointer;
}

.toolbar .ghost {
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.toolbar .primary {
  padding: 8px 15px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Workspace -------------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr) 280px;
  flex: 1;
  min-height: 0;
}

.rail,
.inspector {
  overflow-y: auto;
  background: var(--panel);
  padding: 14px;
}

.rail {
  border-right: 1px solid var(--border);
}

.inspector {
  border-left: 1px solid var(--border);
}

.rail-title,
.panel-head h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-items {
  display: grid;
  gap: 6px;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: grab;
  user-select: none;
}

.rail-item:hover {
  border-color: #bfd3ff;
  background: #f8faff;
}

.rail-item:active {
  cursor: grabbing;
}

.rail-item svg,
.panel-head svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Preview ---------------------------------------------------------------- */

.preview {
  display: flex;
  justify-content: center;
  overflow: auto;
  padding: 18px;
}

.preview-device {
  max-width: 100%;
  height: 100%;
  transition: width 0.18s ease;
}

.preview-device iframe {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 32px -18px rgb(15 23 42 / 0.4);
}

/* Inspector -------------------------------------------------------------- */

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-head h2 {
  margin: 0;
}

.panel.empty {
  padding-top: 6px;
}

.empty-title {
  margin: 0 0 4px;
  font-weight: 650;
}

.empty-body,
.field-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.panel-fields {
  display: grid;
  gap: 12px;
  margin: 14px 0 18px;
}

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

/* `label` as well as `span`: the colour field cannot wrap its input in a
   <label> (that would forward Reset clicks to the picker), so its caption is a
   sibling tied to the input by for/id instead. */
.field span,
.field > label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  color: inherit;
}

/* The colour swatch sits beside its reset rather than above it: the picker is
   square and a full-width one reads as a broken text input. */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field .color-row input[type="color"] {
  width: 46px;
  height: 32px;
  flex: none;
  padding: 3px;
  cursor: pointer;
}

.color-reset {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

/* Hidden rather than removed, so the row does not change height when the first
   colour is chosen and the reset appears. */
.color-reset.is-hidden {
  visibility: hidden;
}

/* Says the contrast is short rather than blocking the choice: it is the
   visitor's brand colour, and moving a fill for them would be presumptuous. */
.field-warning {
  margin: 2px 0 0;
  color: #b45309;
  font-size: 12px;
  line-height: 1.4;
}

/* A link the model refused. The field has already been reset to the stored
   value, so this explains why what was typed is gone. */
.field input[aria-invalid="true"] {
  border-color: #e11d48;
  background: #fff1f2;
}

.field-buttons,
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.field-buttons button,
.panel-actions button {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.panel-actions .danger {
  border-color: #fecdd3;
  color: #be123c;
}

/* Narrow screens: the rail becomes a horizontal strip of buttons above the
   preview. Touch devices do not fire HTML5 drag events at all, so tapping a
   palette item — which inserts after the selection — is the only path there,
   and it needs to be reachable without a 176px column eating the viewport. */
@media (max-width: 900px) {
  .workspace {
    display: flex;
    flex-direction: column;
  }

  .rail,
  .inspector {
    flex: none;
    /* Bounded in pixels as well as proportionally. `40vh` each leaves the
       preview 20vh minus the toolbar whatever the viewport is, so a taller
       frame scales the squeeze rather than relieving it — the embedded editor
       gets twelve more preview pixels from sixty more frame pixels. The px cap
       is what actually gives the preview a floor, on a phone as much as inside
       the landing page's iframe. */
    max-height: min(40vh, 220px);
    border: 0;
    border-top: 1px solid var(--border);
  }

  .rail {
    order: -1;
    border-top: 0;
    border-bottom: 1px solid var(--border);
  }

  .rail-items {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .rail-hint {
    display: none;
  }

  .preview {
    flex: 1;
    min-height: 0;
    padding: 10px;
  }

  .subject {
    order: 1;
    width: 100%;
    flex-basis: 100%;
  }
}
