* { box-sizing: border-box; }

:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe5ef;
  --line-soft: #edf1f7;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #d9f4ef;
  --accent: #2563eb;
  --warning: #b45309;
  --danger: #b42318;
  --success: #15803d;
  --shadow: 0 16px 40px rgba(23, 32, 51, .08);
}

body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 260px),
    var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-strong); }

/* ---------- Header ---------- */
header#topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 64px;
  padding: 0 24px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 16px;
  color: var(--ink);
  white-space: nowrap;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 10px 24px rgba(15,118,110,.2);
}
.brand-sub { color: var(--muted); font-weight: 600; }

#nav {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
#nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  color: #475467;
  border-radius: 8px;
  font-weight: 650;
}
#nav a:hover { background: var(--panel-soft); color: var(--ink); }
#nav a.active { background: var(--primary-soft); color: var(--primary-strong); }

#usermenu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 5px 8px 5px 5px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
}
.user-btn:hover { border-color: #cdd6e3; box-shadow: 0 8px 22px rgba(23,32,51,.07); }
.user-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: 48px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 240px;
  padding: 6px;
  z-index: 60;
}
.user-dropdown .info { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.user-dropdown .info b { display: block; }
.user-dropdown button {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: #344054;
}
.user-dropdown button:hover { background: var(--panel-soft); color: var(--ink); }

main {
  max-width: 1180px;
  margin: 28px auto 48px;
  padding: 0 20px;
}

h1 { font-size: 24px; line-height: 1.2; margin: 0 0 8px; letter-spacing: 0; }
h2 { font-size: 17px; line-height: 1.3; margin: 24px 0 12px; letter-spacing: 0; }
p { margin: 0 0 12px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 650;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}
.page-subtitle { color: var(--muted); margin: 0; max-width: 760px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; margin-bottom: 14px; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-strong); color: #fff; }
.btn.ghost { background: #fff; color: #344054; border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-soft); color: var(--ink); border-color: #cdd6e3; }
.btn.danger { background: #fff1f0; color: var(--danger); border-color: #ffd6d2; }
.btn.danger:hover { background: #ffe6e2; color: var(--danger); }
.btn.small { min-height: 30px; padding: 5px 10px; font-size: 12px; }
.btn:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(15,118,110,.18);
  outline-offset: 2px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 1px rgba(23,32,51,.02);
}
.card h2:first-child { margin-top: 0; }

.login-box {
  max-width: 430px;
  margin: 84px auto;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  margin-bottom: 18px;
}
.login-box input { margin-bottom: 12px; }

input, textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid #cdd6e3;
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 84px; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); outline: none; }
label { display: block; font-weight: 700; font-size: 13px; margin: 12px 0 5px; color: #344054; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field-hint { color: var(--muted); font-size: 12px; margin-top: 5px; }

.apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; }
.app-card {
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  position: relative;
  min-height: 144px;
}
.app-card:hover { transform: translateY(-1px); border-color: #cdd6e3; box-shadow: 0 14px 30px rgba(23,32,51,.08); }
.app-card b { display: block; font-size: 16px; margin-bottom: 6px; }
.app-card .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.app-card .count { font-size: 28px; line-height: 1; font-weight: 800; margin-top: 18px; color: var(--primary-strong); }
.app-card .count small { display: block; margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px 16px;
}
.stat .label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat .value { font-size: 26px; line-height: 1.1; font-weight: 800; margin-top: 7px; color: var(--ink); overflow-wrap: anywhere; }

.charts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; }
.chart-card canvas { max-width: 100%; }

.tabs {
  display: flex;
  gap: 6px;
  margin: 16px 0 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs a {
  flex: 0 0 auto;
  padding: 10px 12px;
  color: #667085;
  border-bottom: 2px solid transparent;
  font-weight: 700;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--primary-strong); border-bottom-color: var(--primary); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: top; }
th {
  color: #667085;
  font-weight: 800;
  background: #fbfcfe;
  position: sticky;
  top: 64px;
  z-index: 1;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fbfa; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.table-wrap table { min-width: 760px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge.sent, .badge.active { background: #dcfce7; color: #166534; }
.badge.sending, .badge.queued { background: #fef3c7; color: #92400e; }
.badge.scheduled { background: #dbeafe; color: #1e40af; }
.badge.failed { background: #fee2e2; color: #b91c1c; }
.badge.canceled, .badge.disabled, .badge.expired, .badge.unsubscribed { background: #eef2f7; color: #475467; }
.badge.admin { background: #fce7f3; color: #9d174d; }
.badge.staff { background: #ccfbf1; color: #0f766e; }

pre.code {
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.copy-wrap { position: relative; }
.copy-wrap .btn { position: absolute; top: 10px; right: 10px; }

.muted { color: var(--muted); font-size: 13px; }
.error {
  color: var(--danger);
  margin-top: 8px;
  font-weight: 650;
}
.success {
  color: var(--success);
  margin-top: 8px;
  font-weight: 650;
}
.notice {
  background: #f7fbfa;
  border: 1px solid #cce9e3;
  color: #175b54;
  border-radius: 8px;
  padding: 12px 14px;
}
.empty-state {
  border: 1px dashed #cdd6e3;
  border-radius: 8px;
  background: #fbfcfe;
  padding: 24px;
  color: var(--muted);
}
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .48);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--panel);
  border-radius: 8px;
  padding: 24px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 24px 70px rgba(17,24,39,.28);
}
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

@media (max-width: 860px) {
  header#topbar {
    align-items: stretch;
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
    gap: 10px;
  }
  .brand { width: calc(100% - 120px); }
  #usermenu { margin-left: auto; order: 1; }
  #nav {
    width: 100%;
    order: 2;
    overflow-x: auto;
    padding-top: 2px;
  }
  main { margin-top: 22px; padding: 0 16px; }
  .charts { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page-head { display: block; }
  .page-head .btn { margin-top: 12px; }
  .user-name { display: none; }
  th { top: 112px; }
}

@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .login-box { margin: 34px auto; padding: 22px; }
  .stats-grid { grid-template-columns: 1fr; }
  .apps-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
  .copy-wrap .btn { position: static; margin-top: 10px; }
}
