:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #e3e8ef;
  --line-strong: #cbd5e1;
  --text: #172033;
  --muted: #667085;
  --faint: #8a94a6;
  --orange: #f97316;
  --orange-dark: #ea580c;
  --blue: #2563eb;
  --green: #059669;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(17, 24, 39, 0.08);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px clamp(16px, 4vw, 36px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 -3px 0 var(--orange);
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-name span {
  color: var(--orange);
}

.brand-lockup p,
.panel-head p,
.recipients-head p,
.metric span,
.hint,
.auth-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.user-menu a,
.panel-head a,
.resend-form button,
.danger-link {
  border: 0;
  background: transparent;
  color: var(--orange);
  font-weight: 700;
  text-decoration: none;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto 56px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.compose-panel,
.side-panel,
.auth-card,
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px 20px;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 1.75rem;
  line-height: 1;
}

.compose-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 18px;
  align-items: start;
}

.compose-panel,
.side-panel {
  overflow: hidden;
}

.compose-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
}

.panel-head,
.recipients-head,
.send-bar,
.modal-head,
.import-row,
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head h1,
.panel-head h2,
.recipients-head h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

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

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-row button,
.secondary-btn,
.file-btn,
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 13px;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.preset-row button:hover,
.secondary-btn:hover,
.file-btn:hover,
.segmented button.active {
  border-color: var(--orange);
  color: var(--orange);
  background: #fff7ed;
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

label span,
.editor-toolbar > span {
  color: #344054;
  font-size: 0.84rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 11px 12px;
  font-size: 0.94rem;
}

textarea {
  resize: vertical;
  min-height: 112px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 0;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.14);
}

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.segmented button {
  border: 0;
  padding: 6px 10px;
}

.smart-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #f8fbff;
}

.smart-panel strong {
  display: block;
  color: #172033;
  font-size: 0.95rem;
}

.smart-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.check-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  color: #344054;
  font-size: 0.88rem;
  font-weight: 650;
}

.check-row input {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  margin-top: 2px;
  accent-color: var(--orange);
}

.readiness-list {
  display: grid;
  gap: 7px;
}

.readiness-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.readiness-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--line-strong);
}

.readiness-item.good {
  color: var(--green);
}

.readiness-item.good .readiness-dot {
  background: var(--green);
}

.readiness-item.warn {
  color: #b45309;
}

.readiness-item.warn .readiness-dot {
  background: #f59e0b;
}

.import-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.recipient-list {
  min-height: 92px;
  max-height: 260px;
  overflow: auto;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.recipient-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-bottom: 7px;
}

.recipient-chip:last-child {
  margin-bottom: 0;
}

.recipient-chip strong,
.log-table strong {
  display: block;
  font-size: 0.9rem;
}

.recipient-chip span,
.log-table span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-recipient {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: #fee2e2;
  color: var(--red);
  font-weight: 800;
}

.send-bar {
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.from-line {
  color: var(--muted);
  font-size: 0.84rem;
}

.primary-btn {
  border: 1px solid var(--orange);
  background: var(--orange);
  color: #ffffff;
  border-radius: 7px;
  padding: 11px 18px;
  font-weight: 800;
}

.primary-btn:hover {
  background: var(--orange-dark);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.log-table-wrap {
  max-height: 720px;
  overflow: auto;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.log-table th,
.log-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.log-table th {
  position: sticky;
  top: 0;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.log-table td {
  font-size: 0.84rem;
}

.status {
  display: inline-flex;
  width: max-content;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status.sent {
  color: var(--green);
  background: #ecfdf3;
}

.status.failed {
  color: var(--red);
  background: #fef2f2;
}

.status.skipped {
  color: #b45309;
  background: #fffbeb;
}

.empty-state,
.empty-cell {
  padding: 22px;
  color: var(--faint);
  text-align: center;
  font-size: 0.9rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.62);
}

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

.modal {
  width: min(760px, 96vw);
  max-height: 88vh;
  overflow: hidden;
}

.modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head button {
  border: 0;
  background: var(--panel-soft);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--muted);
  font-weight: 700;
}

#previewFrame {
  display: block;
  width: 100%;
  height: min(650px, 72vh);
  border: 0;
  background: #ffffff;
}

.progress-modal {
  padding-bottom: 16px;
}

.progress-track {
  height: 10px;
  margin: 16px;
  border-radius: 99px;
  background: #eef2f7;
  overflow: hidden;
}

#progressFill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--orange), var(--blue));
  transition: width 0.25s ease;
}

.progress-meta {
  padding: 0 16px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.send-log {
  margin: 0 16px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.send-log-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.84rem;
}

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

.send-log-row small {
  display: block;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.done-actions {
  display: flex;
  justify-content: flex-end;
  padding: 14px 16px 0;
}

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

.auth-card {
  width: min(430px, 100%);
  padding: 34px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

.auth-note {
  margin-top: 18px;
}

.otp-input {
  text-align: center;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 8px;
}

.resend-form {
  margin-top: 14px;
  text-align: center;
}

.alert {
  border-radius: 7px;
  padding: 11px 13px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 650;
}

.alert-error {
  color: var(--red);
  border: 1px solid #fecaca;
  background: #fef2f2;
}

.alert-info {
  color: var(--blue);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
}

@media (max-width: 1120px) {
  .compose-layout {
    grid-template-columns: 1fr;
  }

  .log-table-wrap {
    max-height: 420px;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .panel-head,
  .recipients-head,
  .send-bar,
  .editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .compose-panel {
    padding: 16px;
  }

  .auth-card {
    padding: 26px 20px;
  }
}
