:root {
  --bg: #e9eaee;
  --surface: #ffffff;
  --ink: #17181c;
  --muted: #8a8f99;
  --line: #eef0f3;
  --lime: #c9f24d;
  --teal: #159c9c;
  --purple-soft: #e7e0fc;
  --purple: #a78bfa;
  --blue-soft: #d9e8fd;
  --green-soft: #d2f4e2;
  --green: #34d399;
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 22px;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
}

.app {
  display: flex;
  min-height: calc(100vh - 44px);
  background: var(--surface);
  border-radius: 28px;
  overflow: hidden;
}

/* ---------- sidebar ---------- */

.sidebar {
  width: 236px;
  flex-shrink: 0;
  padding: 26px 18px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 26px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--lime);
  display: grid;
  place-items: center;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border-radius: 13px;
  color: #6c717c;
  font-weight: 500;
  cursor: default;
}

.nav-item svg {
  width: 18px;
  height: 18px;
}

.nav-item.is-active {
  background: var(--lime);
  color: var(--ink);
  font-weight: 600;
}

.nav-item[data-soon] {
  opacity: 0.5;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.who strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.who small {
  color: var(--muted);
  font-size: 11px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--purple-soft);
  color: #5b45a8;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.avatar-lg {
  width: 38px;
  height: 38px;
}

/* ---------- main ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 30px 34px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.pill-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: #555b66;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd0d8;
}

.pill-status.is-on .dot {
  background: var(--green);
}

.pill-status.is-off .dot {
  background: #f59e0b;
}

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

.col-main,
.col-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* ---------- stat cards ---------- */

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

.stat {
  padding: 17px 18px;
  border-radius: 18px;
}

.stat-purple {
  background: var(--purple-soft);
}

.stat-green {
  background: var(--green-soft);
}

.stat-blue {
  background: var(--blue-soft);
}

.stat-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #4a4f59;
}

.stat-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.75);
  display: grid;
  place-items: center;
}

.stat-icon svg {
  width: 13px;
  height: 13px;
}

.stat strong {
  display: block;
  margin: 12px 0 4px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.8px;
}

.stat small {
  color: #6a707b;
  font-size: 11px;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  background: #f4f5f7;
  color: #5c626d;
  font-size: 11px;
  font-weight: 500;
}

.chip-green {
  background: var(--green-soft);
  color: #1b7a55;
}

/* ---------- chart ---------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 168px;
}

.chart-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
}

.chart-bars {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
}

.bar {
  width: 11px;
  min-height: 4px;
  border-radius: 6px;
  background: var(--purple);
  transition: height 0.3s ease;
}

.bar-green {
  background: var(--green);
}

.chart-label {
  font-size: 11px;
  color: var(--muted);
}

.legend {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sq {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
}

.sq-green {
  background: var(--green);
}

.sq-purple {
  background: var(--purple);
}

/* ---------- table ---------- */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 0 12px 12px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--muted);
}

.table td {
  padding: 13px 12px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

.table td small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.table .empty td {
  text-align: center;
  color: var(--muted);
  padding: 26px 12px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.badge-pending {
  background: #fef3c7;
  color: #a16207;
}

.badge-confirmed {
  background: var(--green-soft);
  color: #1b7a55;
}

.badge-cancelled {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-sent {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.badge-queued {
  background: #f4f5f7;
  color: #5c626d;
}

.badge-failed {
  background: #fee2e2;
  color: #b91c1c;
}

/* ---------- promo / test form ---------- */

.promo {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.promo h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.promo p {
  margin: 6px 0 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
}

.promo-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.promo-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
}

.promo-form input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.promo-form input:focus {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 0;
}

.promo-form button {
  margin-top: 6px;
  padding: 11px 14px;
  border: 0;
  border-radius: 11px;
  background: var(--lime);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.promo-form button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.promo-note {
  margin: 12px 0 0;
  font-size: 11.5px;
  min-height: 16px;
  color: rgba(255, 255, 255, 0.9);
}

/* ---------- rows + feed ---------- */

.rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #555b66;
}

.row code {
  font-size: 11px;
  color: var(--ink);
  background: #f4f5f7;
  padding: 4px 8px;
  border-radius: 7px;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 260px;
  overflow-y: auto;
}

.feed li {
  display: flex;
  gap: 10px;
  font-size: 12px;
  line-height: 1.45;
}

.feed i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--purple);
}

.feed .i-sent {
  background: #3b82f6;
}

.feed .i-confirmed {
  background: var(--green);
}

.feed .i-cancelled,
.feed .i-error {
  background: #ef4444;
}

.feed .i-reply {
  background: #f59e0b;
}

.feed time {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
}

.feed-empty {
  color: var(--muted);
}

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  body {
    padding: 12px;
  }

  .app {
    flex-direction: column;
    border-radius: 22px;
  }

  .sidebar {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 20px 16px 26px;
  }

  .stats {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- buttons ---------- */

.btn {
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.btn-lime {
  background: var(--lime);
  color: var(--ink);
  font-weight: 600;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--line);
  color: #555b66;
}

.btn-ghost:hover {
  background: #f7f8f9;
}

.btn-danger {
  color: #b91c1c;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- automations page ---------- */

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

.auto-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auto-card.is-off {
  opacity: 0.55;
}

.auto-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.auto-head h2 {
  margin: 0 0 7px;
  font-size: 15px;
  font-weight: 600;
}

.auto-actions {
  display: flex;
  gap: 7px;
}

.auto-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auto-step {
  display: flex;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 13px;
  background: #f7f8f9;
  font-size: 12.5px;
}

.auto-step p {
  margin: 0;
  color: #4a4f59;
  line-height: 1.6;
}

.auto-step i {
  font-style: normal;
  color: #a16207;
  font-size: 11px;
  font-weight: 600;
}

.step-label {
  flex-shrink: 0;
  width: 42px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding-top: 2px;
}

.msg {
  display: block;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: pre-wrap;
}

.steps {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: #555b66;
  line-height: 1.9;
}

.hint {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* ---------- modal editor ---------- */

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 22, 26, 0.45);
  overflow-y: auto;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.field > span {
  font-size: 12px;
  font-weight: 600;
  color: #3f444d;
}

.field small {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.field textarea {
  resize: vertical;
  line-height: 1.6;
}

.logic-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.logic-toggle small {
  color: var(--muted);
  font-size: 11px;
}

.logic {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: #6c717c;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.logic.is-on {
  background: var(--lime);
  border-color: var(--lime);
  color: var(--ink);
}

.rule {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.2fr auto;
  gap: 7px;
  margin-bottom: 8px;
}

.rule select,
.rule input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  min-width: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.form-error {
  margin: 0;
  color: #b91c1c;
  font-size: 12px;
  text-align: right;
}

@media (max-width: 1080px) {
  .automations-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .rule {
    grid-template-columns: 1fr 1fr;
  }
}
