:root {
  --navy-1: #1c4b96;
  --navy-2: #2a63c4;
  --navy-3: #2458b0;
  --bg: #e8edf4;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #7b8794;
  --line: #e6ebf2;
  --blue: #2f6fed;
  --blue-soft: #9ec2ff;
  --green: #2ecc71;
  --green-text: #1fa855;
  --orange: #f5a623;
  --red: #e74c3c;
  --slate: #5d6d7e;
  --sidebar: #ffffff;
  --shadow: 0 8px 22px rgba(28, 49, 84, 0.07);
  --radius: 10px;
  --header-h: 62px;
  --sidebar-w: 228px;
  --font: "Inter", "Segoe UI", sans-serif;
}

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

html,
body {
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.topbar {
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(90deg, var(--navy-1) 0%, var(--navy-3) 42%, var(--navy-2) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding-left: 18px;
  padding-right: 22px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(15, 40, 80, 0.18);
  z-index: 20;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1;
}

.menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-backdrop {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  z-index: 1;
}

.top-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: 42px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand svg {
  display: block;
}

.top-nav {
  display: flex;
  justify-content: center;
  gap: 42px;
}

.top-nav a {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 0 10px;
  border-bottom: 3px solid transparent;
  opacity: 0.92;
}

.top-nav a.active {
  opacity: 1;
  border-bottom-color: #fff;
}

.hello {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid #dfe6ef;
  padding: 18px 0 20px;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

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

.side-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px 11px 16px;
  color: #334155;
  font-size: 14.5px;
  font-weight: 600;
  border-left: 4px solid transparent;
}

.side-nav a svg {
  width: 18px;
  height: 18px;
  stroke: #64748b;
  flex-shrink: 0;
}

.side-nav a.active {
  background: #eef1f5;
  border-left-color: #8b98a8;
  color: #1e293b;
}

.side-nav a.active svg {
  stroke: #475569;
}

.side-nav a:hover:not(.active) {
  background: #f7f9fb;
}

.btn-new {
  margin: 18px 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(46, 204, 113, 0.28);
}

.btn-new:hover {
  filter: brightness(0.96);
}

.main {
  overflow: auto;
  padding: 22px 24px 32px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px 20px 16px;
  min-height: 118px;
}

.kpi-label {
  font-size: 13.5px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: #1b2430;
}

.kpi-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--blue);
  font-size: 13.5px;
  font-weight: 600;
}

.kpi-note {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 700;
}

.kpi-note.good {
  color: var(--green-text);
}

.kpi-note.bad {
  color: var(--red);
}

.mid {
  display: grid;
  grid-template-columns: 1.85fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}

.card-head h2,
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}

.table-wrap {
  padding: 4px 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  color: #7b8794;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

td {
  font-size: 13.5px;
  font-weight: 600;
  padding: 12px;
  border-bottom: 1px solid #f0f3f7;
  color: #334155;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-block;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  line-height: 1.2;
}

.badge.completed {
  background: #2ecc71;
}

.badge.sending {
  background: #f5a623;
}

.badge.scheduled {
  background: #5d6d7e;
}

.badge.pending {
  background: #94a3b8;
}

.schedule {
  padding: 6px 16px 16px;
}

.schedule-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 4px;
}

.schedule-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #eef4ff;
  color: var(--navy-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.schedule-icon.warm {
  background: #fff4e5;
  color: #d97706;
}

.schedule-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 3px;
}

.schedule-sub {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

.bottom {
  display: grid;
  grid-template-columns: 1.85fr 1fr;
  gap: 18px;
}

.chart-card {
  padding-bottom: 14px;
}

.chart-wrap {
  height: 230px;
  padding: 4px 16px 8px;
}

.donuts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 12px 20px;
}

.donut {
  text-align: center;
}

.donut p {
  font-size: 13.5px;
  font-weight: 800;
  margin-bottom: 8px;
}

.donut p.bounce {
  color: var(--red);
}

.donut p.unsub {
  color: #f5a623;
}

.donut canvas {
  max-width: 128px;
  max-height: 128px;
  margin: 0 auto;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding-bottom: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: #64748b;
}

.swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}

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

.page-head h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--navy-2);
  color: #fff;
}

.btn-ghost {
  background: #fff;
  color: #334155;
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
}

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

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

.field label {
  font-size: 12.5px;
  font-weight: 700;
  color: #64748b;
}

.field input,
.field select,
.field textarea {
  border: 1px solid #d9e1ec;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-danger:hover {
  filter: brightness(0.97);
}

.template-card {
  padding: 18px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-card .btn-danger {
  margin-top: auto;
  align-self: flex-start;
}

.template-card h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.template-card p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

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

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.active,
.status-dot.sent {
  background: var(--green);
}

.status-dot.opened,
.status-dot.clicked {
  background: #2f6fed;
}

.status-dot.bounced {
  background: var(--red);
}

.status-dot.pending {
  background: var(--orange);
}

.status-dot.unsubscribed {
  background: var(--orange);
}

.settings-card {
  max-width: 640px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: none;
}

.auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1c4b96, #2a63c4);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  overflow: auto;
}

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

.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 28px 26px 22px;
  box-shadow: 0 24px 60px rgba(8, 28, 68, 0.28);
}

.auth-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.auth-card .lede {
  color: var(--muted);
  font-size: 13.5px;
  margin-bottom: 18px;
}

.auth-switch {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.auth-error {
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
}

.auth-switch button {
  background: none;
  border: 0;
  color: var(--blue);
  font-weight: 700;
  cursor: pointer;
}

.app.locked .shell,
.app.locked .top-nav,
.app.locked .hello,
.app.locked .btn-new {
  visibility: hidden;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1;
}

.btn-logout {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 0;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.check-list {
  max-height: 240px;
  overflow: auto;
  border: 1px solid #d9e1ec;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.check-list label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13.5px;
  font-weight: 600;
  color: #334155;
}

.check-list label.is-taken {
  opacity: 0.72;
  font-weight: 500;
}

.check-list .taken-tag {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
  margin-top: 2px;
}

.dropzone {
  border: 1.5px dashed #c5d0e0;
  border-radius: 10px;
  padding: 18px;
  background: #f8fafc;
}

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

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
}

.team-list {
  padding: 0 20px 18px;
}

.team-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.invite-url {
  font-size: 12.5px;
  word-break: break-all;
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}

.empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.sendgrid-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 8px;
}

.sendgrid-pill.live {
  background: #e8f8ee;
  color: #157a3a;
}

.sendgrid-pill.dry {
  background: #fff4e5;
  color: #b45309;
}

.google-setup {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.google-setup p {
  margin: 8px 0;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-row input[type='search'],
#c-recipient-search {
  flex: 1;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}

#c-recipient-search {
  margin-bottom: 10px;
}

.list-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.list-option {
  min-width: 140px;
}

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

  .mid,
  .bottom,
  .template-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .top-nav {
    gap: 18px;
  }
}

@media (max-width: 900px) {
  .menu-btn {
    display: flex;
  }

  .top-nav {
    display: none;
  }

  .hello {
    display: none;
  }

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

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top));
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 24px rgba(15, 23, 42, 0.12);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .app.menu-open .sidebar {
    transform: none;
  }

  .app.menu-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app.menu-open .main {
    overflow: hidden;
  }

  .main {
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
  }

  .kpi {
    min-height: 0;
    padding: 14px 14px 12px;
  }

  .kpi-value {
    font-size: 26px;
  }

  .page-head h1 {
    font-size: 20px;
  }

  .side-nav a,
  .btn-new,
  .btn,
  .btn-logout {
    min-height: 44px;
  }

  .field input,
  .field select,
  .field textarea,
  .auth-card input {
    font-size: 16px;
  }

  .auth-card {
    padding: 22px 18px 18px;
  }

  .topbar {
    padding-left: 8px;
    padding-right: 12px;
  }

  .brand {
    font-size: 18px;
  }

  table {
    min-width: 620px;
  }

  .chart-wrap {
    height: 200px;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions .btn {
    flex: 1;
  }
}

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 40, 80, 0.35);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.modal-card {
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
}

.step-line {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

@media (max-width: 420px) {
  .kpis,
  .donuts {
    grid-template-columns: 1fr;
  }
}
