:root {
  --accent: #fdda79;
  --accent-dark: #f4c642;
  --ink: #111111;
  --muted: #6f6b63;
  --paper: #f8f7f4;
  --surface: #ffffff;
  --line: #e8e1d2;
  --soft: #fff6de;
  --blue: #285c7f;
  --green: #2e6f4f;
  --danger: #a54242;
  --shadow: 0 18px 50px rgba(17, 17, 17, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Mona Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.locked {
  display: none;
}

[hidden] {
  display: none !important;
}

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

button {
  border: 0;
}

.app {
  min-height: 100vh;
  padding: 22px;
}

.login-screen {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 22px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  margin: 0 auto;
  max-width: 420px;
  padding: 26px;
  width: 100%;
}

.login-logo {
  height: 50px;
  width: 50px;
}

.login-card h1 {
  font-size: 36px;
}

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

.brand-lockup {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  aspect-ratio: 1;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  display: block;
  flex: 0 0 54px;
  height: 54px;
  object-fit: contain;
  padding: 5px;
  width: 54px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 3px;
  text-transform: uppercase;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  line-height: 1.08;
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 50px);
}

h2 {
  font-size: 22px;
}

.connection-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 13px;
  white-space: nowrap;
}

.connection-pill.connected {
  background: #e9f6ef;
  border-color: #b9dec9;
  color: var(--green);
}

.connect-panel,
.customer-sidebar,
.control-panel,
.preview-pane {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.connect-panel {
  border-radius: 8px;
  margin: 0 auto 18px;
  max-width: 1540px;
  padding: 14px;
}

.connect-form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(260px, 1fr) auto auto;
}

.env-status {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 58px;
  padding: 9px 12px;
}

.env-status strong {
  display: block;
  font-weight: 800;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(285px, 340px) minmax(330px, 430px) minmax(430px, 1fr);
  margin: 0 auto;
  max-width: 1540px;
}

.activity-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 18px auto 0;
  max-width: 1540px;
  overflow: hidden;
}

.activity-heading {
  padding: 14px 18px;
}

.activity-live {
  background: #e9f6ef;
  border: 1px solid #b9dec9;
  border-radius: 999px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 9px;
  text-transform: uppercase;
}

.activity-log {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 12px 18px 16px;
}

.activity-entry,
.activity-empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  padding: 9px 10px;
}

.activity-entry {
  display: grid;
  gap: 8px;
  grid-template-columns: 80px minmax(0, 1fr);
}

.activity-entry time {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: nowrap;
}

.activity-entry span {
  color: #2f2d29;
  overflow-wrap: anywhere;
}

.activity-entry.success {
  border-color: #b9dec9;
}

.activity-entry.success span {
  color: var(--green);
}

.activity-entry.error {
  border-color: #e2b7b7;
}

.activity-entry.error span {
  color: var(--danger);
}

.sent-email-section {
  border-top: 1px solid var(--line);
}

.sent-email-grid {
  display: grid;
  gap: 0;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  min-height: 360px;
}

.sent-email-list {
  border-right: 1px solid var(--line);
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding: 12px 18px 16px;
}

.sent-email-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 3px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.sent-email-item.active {
  background: var(--soft);
  border-color: var(--accent-dark);
}

.sent-email-item span,
.sent-email-item em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sent-email-item strong {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sent-email-preview {
  background: #ece8dd;
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  min-width: 0;
  padding: 14px;
}

.sent-email-meta {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 10px;
}

.sent-email-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sent-email-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sent-email-preview iframe {
  background: #ffffff;
  border: 0;
  min-height: 320px;
  width: 100%;
}

.sent-email-text {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
  padding: 10px;
}

.sent-email-text summary {
  cursor: pointer;
  font-weight: 800;
}

.sent-email-text pre {
  color: #2f2d29;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  margin: 10px 0 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

.customer-sidebar,
.control-panel,
.preview-pane {
  border-radius: 8px;
  min-height: 680px;
  overflow: hidden;
}

.customer-sidebar,
.control-panel {
  max-height: calc(100vh - 150px);
}

.customer-sidebar {
  display: flex;
  flex-direction: column;
}

.control-panel {
  overflow: auto;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-heading {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 18px;
}

.panel-heading.compact {
  border-bottom: 0;
  padding: 0 0 14px;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.panel-section:last-child {
  border-bottom: 0;
}

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.smtp-summary {
  display: grid;
  gap: 10px;
}

.smtp-summary div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 8px 10px;
}

.smtp-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.smtp-summary strong {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 8px 10px;
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  background: transparent;
  border: 0;
  color: var(--ink);
  min-width: 0;
  outline: 0;
  padding: 0;
  width: 100%;
}

.field textarea {
  resize: vertical;
}

.field:focus-within {
  border-color: var(--ink);
}

.toggle-field {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
}

.toggle-field input {
  accent-color: var(--ink);
  height: 18px;
  width: 18px;
}

.toggle-field span {
  font-weight: 800;
}

.button {
  align-items: center;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 43px;
  padding: 0 16px;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button:not(:disabled):hover,
.icon-button:not(:disabled):hover {
  transform: translateY(-1px);
}

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

.button.secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

.button.dark {
  background: var(--ink);
  color: #ffffff;
}

.button.quiet {
  background: transparent;
  color: var(--muted);
}

.icon-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 20px;
  height: 40px;
  justify-content: center;
  line-height: 1;
  transition: transform 0.2s ease;
  width: 40px;
}

.customer-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 12px;
}

.customer-card {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 12px;
  grid-template-columns: 42px minmax(0, 1fr);
  padding: 12px;
  text-align: left;
  width: 100%;
}

.customer-card.active {
  background: var(--soft);
  border-color: var(--accent-dark);
}

.avatar {
  align-items: center;
  aspect-ratio: 1;
  background: var(--ink);
  border-radius: 50%;
  color: var(--accent);
  display: grid;
  font-weight: 800;
  justify-items: center;
}

.customer-main {
  min-width: 0;
}

.customer-line {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
}

.customer-name,
.customer-price {
  white-space: nowrap;
}

.customer-name {
  flex: 1 1 auto;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-price {
  color: var(--green);
  flex: 0 0 auto;
  font-weight: 800;
  margin-left: 8px;
  overflow: visible;
  text-align: right;
}

.customer-price-stack {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.1;
}

.customer-price-original {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-decoration: line-through;
}

.customer-price-discounted {
  color: var(--green);
  display: block;
  font-size: 15px;
  font-weight: 800;
}

.customer-email,
.customer-product {
  color: var(--muted);
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.badge {
  border: 1px solid rgba(17, 17, 17, 0.14);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
}

.badge.warn {
  border-color: #e5c1a8;
  color: #8f531f;
}

.empty-state {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  min-height: 180px;
  padding: 20px;
  text-align: center;
}

.preview-heading {
  flex: 0 0 auto;
}

.preview-nav {
  display: flex;
  gap: 8px;
}

.subject-strip {
  align-items: center;
  background: var(--soft);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  grid-template-columns: 70px minmax(0, 1fr);
  padding: 12px 18px;
}

.subject-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.subject-strip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-preview {
  background: #ece8dd;
  flex: 1 1 auto;
  min-height: 410px;
  padding: 18px;
}

.email-preview iframe {
  background: #ffffff;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(17, 17, 17, 0.08);
  height: 100%;
  min-height: 410px;
  width: 100%;
}

.plain-text-block {
  border-top: 1px solid var(--line);
  padding: 12px 18px;
}

.plain-text-block summary {
  cursor: pointer;
  font-weight: 800;
}

.plain-text-block pre {
  color: #2f2d29;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  margin: 12px 0 0;
  overflow: auto;
  white-space: pre-wrap;
}

.action-row {
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px;
}

.status-log {
  color: var(--muted);
  font-size: 14px;
  min-height: 24px;
  padding: 0 18px 18px;
}

.status-log.error {
  color: var(--danger);
}

.status-log.success {
  color: var(--green);
}

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: minmax(270px, 330px) minmax(420px, 1fr);
  }

  .control-panel {
    grid-column: 1 / -1;
    min-height: 0;
    order: 3;
  }
}

@media (max-width: 860px) {
  .app {
    padding: 12px;
  }

  .topbar,
  .connect-form {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .connect-form {
    display: grid;
  }

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

  .customer-sidebar,
  .control-panel,
  .preview-pane {
    max-height: none;
    min-height: 0;
  }

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

  .subject-strip {
    grid-template-columns: 1fr;
  }

  .activity-entry {
    grid-template-columns: 1fr;
  }

  .sent-email-grid {
    grid-template-columns: 1fr;
  }

  .sent-email-list {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    max-height: 260px;
  }
}
