:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --ink: #111817;
  --muted: #66736f;
  --line: #d9e2de;
  --accent: #168f82;
  --accent-dark: #0f675e;
  --amber: #c9802d;
  --danger: #b4443f;
  --shadow: 0 22px 70px rgba(25, 41, 37, 0.14);
  --radius: 8px;
  --sidebar: 292px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  padding: 26px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  background: #071012;
  color: #f7fbf8;
  font-weight: 800;
  box-shadow: inset 0 -4px 0 rgba(39, 182, 163, 0.5);
}

.brand strong,
.sidebar-footer strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.brand span,
.sidebar-footer span,
.panel p,
.drawer-header p,
.modal-header p,
.loading-card p {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: #31413d;
  font-size: 14px;
  font-weight: 650;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

.icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: var(--accent);
  font-size: 15px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.sidebar-footer div:last-child {
  min-width: 0;
}

.sidebar-footer strong,
.sender-pill span:nth-child(2) {
  overflow: hidden;
  max-width: 190px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(22, 143, 130, 0.12);
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-label {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--ink);
  line-height: 1.12;
}

h1 {
  font-size: 34px;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
}

.topbar-actions,
.action-row,
.modal-actions,
.settings-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sender-pill,
.button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.sender-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 310px;
  min-height: 42px;
  padding: 0 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
}

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

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

.button.secondary:hover,
.button.ghost:hover,
.sender-pill:hover {
  background: var(--surface-2);
}

.button.ghost {
  background: transparent;
}

.button.wide {
  width: 100%;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  font-size: 24px;
  line-height: 1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(17, 24, 23, 0.03);
}

.form-panel,
.side-panel,
.hidden-section {
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.panel-heading.compact {
  margin-bottom: 14px;
}

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

.simple-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label > span,
.website-control > span,
.email-meta span,
.body-editor span {
  color: #384844;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(22, 143, 130, 0.12);
}

.website-control {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

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

.segment {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.segment.active,
.segment:hover {
  border-color: rgba(22, 143, 130, 0.45);
  background: #eef8f6;
  color: var(--accent-dark);
}

.action-row {
  justify-content: space-between;
  margin-top: 8px;
}

#formHint {
  max-width: 520px;
  margin: 0;
}

.lead-list {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.lead-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
  text-align: left;
}

.lead-item strong {
  font-size: 14px;
}

.lead-item span {
  color: var(--muted);
  font-size: 12px;
}

.templates-box {
  display: grid;
  gap: 9px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.template-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}

.template-card.active,
.template-card:hover {
  border-color: rgba(22, 143, 130, 0.45);
  background: #eef8f6;
}

.template-card span,
.template-preview-grid p,
.history-table span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.hidden-section {
  max-width: 1020px;
}

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

.template-preview-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.template-list {
  display: grid;
  gap: 10px;
}

.template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.template-row p {
  margin: 5px 0 0;
}

.template-editor {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.template-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.history-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 120px;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
}

.history-row:last-child {
  border-bottom: 0;
}

.history-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 15, 14, 0.42);
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: min(450px, 100vw);
  height: 100vh;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.settings-drawer.open {
  transform: translateX(0);
}

.drawer-header,
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.settings-form {
  overflow: auto;
  padding-right: 2px;
}

.divider {
  height: 1px;
  margin: 8px 0 18px;
  background: var(--line);
}

.warning-note {
  margin: 14px 0 0;
  padding: 12px;
  border-left: 3px solid var(--amber);
  background: #fff8ef;
  color: #6f4b1f;
  font-size: 13px;
  line-height: 1.45;
}

.modal-backdrop {
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
}

.loading-card,
.review-modal {
  width: min(900px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.loading-card {
  width: min(520px, 100%);
  padding: 28px;
  text-align: center;
}

.spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  margin-bottom: 14px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-track {
  overflow: hidden;
  height: 9px;
  margin-top: 20px;
  border-radius: 999px;
  background: var(--surface-2);
}

#progressBar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #72b168);
  transition: width 220ms ease;
}

.review-modal {
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 22px;
}

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

.email-meta label:first-child {
  grid-column: 1 / -1;
}

.body-editor textarea {
  min-height: 310px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
}

.modal-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #071012;
  color: white;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(22, 143, 130, 0.14), transparent 44%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 24px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

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

@media (max-width: 760px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .action-row,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .sender-pill {
    width: 100%;
    max-width: none;
  }

  .form-grid,
  .settings-grid,
  .simple-template-row,
  .template-preview-grid,
  .template-manager,
  .email-meta {
    grid-template-columns: 1fr;
  }

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

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

  h1 {
    font-size: 28px;
  }

  .history-row {
    grid-template-columns: 1fr;
  }
}
