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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3147;
  --text: #e2e8f0;
  --muted: #7c85a2;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* NAV */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  letter-spacing: -0.3px;
}
.nav-links { display: flex; gap: 24px; }
.nav-links a { color: var(--muted); font-size: 13px; }
.nav-links a:hover, .nav-links a.active { color: var(--text); text-decoration: none; }

/* LAYOUT */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }
.container.narrow { max-width: 700px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 600; }
.back-link { color: var(--muted); font-size: 13px; display: block; margin-bottom: 4px; }

/* INBOX LAYOUT */
.inbox-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.thread-list-panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.panel-header h2 { font-size: 15px; font-weight: 600; }

.thread-detail-panel {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* THREAD LIST */
.thread-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.thread-item:hover { background: var(--surface); }
.thread-item.active { background: var(--surface2); }
.thread-item.unread .thread-subject { font-weight: 600; color: #fff; }

.thread-sender-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.thread-body { flex: 1; min-width: 0; }
.thread-top { display: flex; justify-content: space-between; gap: 8px; }
.thread-subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.thread-snippet { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-account { font-size: 11px; margin-top: 2px; }

.unread-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* THREAD DETAIL */
.thread-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.thread-header h2 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }

.messages-list { flex: 1; padding: 16px 24px; display: flex; flex-direction: column; gap: 16px; }

.message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.message.outbound { background: #1e2640; border-color: #2d3a60; }

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.message-from { font-weight: 600; font-size: 13px; }
.message-time { margin-left: auto; font-size: 11px; color: var(--muted); }

.message-body { padding: 14px; }
.msg-iframe { width: 100%; border: none; min-height: 80px; background: #fff; border-radius: 4px; }
.msg-text { white-space: pre-wrap; font-size: 13px; color: var(--text); font-family: inherit; }

.reply-box {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.reply-box textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 13px;
  resize: vertical;
}
.reply-actions { margin-top: 10px; display: flex; justify-content: flex-end; }

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #000; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* BADGES */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-gray { background: var(--surface2); color: var(--muted); }
.badge-blue { background: #1e3a5f; color: #60a5fa; }
.badge-green { background: #1a3a2a; color: #34d399; }
.badge-yellow { background: #3a2e1a; color: #fbbf24; }
.badge-red { background: #3a1a1a; color: #f87171; }

/* CARDS */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.card-info { display: flex; align-items: center; gap: 12px; flex: 1; }
.card-info strong { display: block; font-size: 14px; }
.card-meta { color: var(--muted); font-size: 12px; }
.card-actions { margin-left: auto; }

.account-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

/* FORMS */
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 4px; text-transform: uppercase; letter-spacing: 0.5px; }
input[type="text"], input[type="email"], textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 13px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
select option { background: var(--surface); }

.add-form { display: flex; gap: 10px; align-items: center; }
.add-form input { width: 260px; }

/* TABLES */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: var(--surface); }
.error-cell { color: var(--danger); font-size: 11px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* STEPS WIZARD */
.steps {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.step {
  flex: 1;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.step:last-child { border-right: none; }
.step.active { color: #fff; background: var(--primary); }
.step.done { color: var(--success); background: #1a3a2a; }

.step-panel { display: block; }
.step-panel.hidden { display: none; }
.step-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.step-panel h2 { font-size: 17px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.hint code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* TOKEN CHIPS */
.token-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  color: #a5b4fc;
  cursor: pointer;
  transition: background 0.1s;
}
.chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* INPUT TABS */
.input-tabs { display: flex; gap: 0; margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; width: fit-content; }
.input-tab { padding: 7px 20px; font-size: 13px; font-weight: 500; background: var(--surface); border: none; color: var(--muted); cursor: pointer; }
.input-tab.active { background: var(--primary); color: #fff; }
.input-tab:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* DROP ZONE */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s;
  margin: 16px 0;
}
.drop-zone.drag-over { border-color: var(--primary); background: #1e1f3a; }
.drop-zone p { margin: 8px 0; }

/* PREVIEW CARDS */
.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.7;
}
.preview-body { color: var(--muted); margin-top: 4px; font-style: italic; }

/* CAMPAIGN META */
.campaign-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* PROGRESS BAR */
.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 6px;
  height: 10px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 6px;
  transition: width 0.4s;
}
.progress-bar-wrap span {
  position: absolute;
  right: 6px;
  top: -2px;
  font-size: 10px;
  color: var(--muted);
}

/* ALERTS */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-success { background: #1a3a2a; color: #34d399; border: 1px solid #2a5a3a; }
.alert-error { background: #3a1a1a; color: #f87171; border: 1px solid #5a2a2a; }
.alert.hidden { display: none; }

/* MISC */
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 0; }
.error { color: var(--danger); }
.loading { color: var(--muted); padding: 20px; text-align: center; }
.load-more { text-align: center; padding: 12px; border-top: 1px solid var(--border); }
.toggle-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }

/* SEQUENCE BUILDER */
.seq-section-label {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stop-reply-row {
  margin: 14px 0 4px;
}
.stop-reply-row .toggle-label {
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stop-reply-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.seq-step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.seq-step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.seq-step-num {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  min-width: 50px;
}

.seq-step-timing {
  font-size: 12px;
}

.seq-delay-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  flex: 1;
}

.delay-input {
  width: 60px !important;
  padding: 3px 8px !important;
  font-size: 13px !important;
  text-align: center;
}
.delay-unit {
  width: auto !important;
  padding: 3px 6px !important;
  font-size: 13px !important;
}

.seq-remove-btn {
  margin-left: auto;
}

/* SEQUENCE STEPS OVERVIEW (detail page) */
.steps-overview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.steps-overview.hidden { display: none; }

.steps-overview-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
}

.overview-step {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 140px;
}
.overview-step-num { font-size: 10px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.5px; }
.overview-step-subject { font-size: 12px; margin: 3px 0; }
.overview-step-delay { font-size: 11px; }
.overview-arrow { color: var(--muted); font-size: 18px; padding: 0 4px; }

/* STEP PROGRESS DOTS */
.step-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.step-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  cursor: default;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.step-dot:hover { transform: scale(1.3); }
.step-dot.sent    { background: var(--success); border-color: var(--success); }
.step-dot.pending { background: var(--surface2); border-color: var(--muted); }
.step-dot.failed  { background: var(--danger); border-color: var(--danger); }
.step-dot.stopped { background: var(--warning); border-color: var(--warning); }

@media (max-width: 768px) {
  .inbox-layout { grid-template-columns: 1fr; }
  .thread-detail-panel { display: none; }
  .inbox-layout.show-detail .thread-list-panel { display: none; }
  .inbox-layout.show-detail .thread-detail-panel { display: flex; }
}
