:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #16202a;
  --muted: #687586;
  --line: #dde3ec;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --success-bg: #e7f8f0;
  --success-text: #087443;
  --error-bg: #fee4e2;
  --error-text: #b42318;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

a:hover {
  text-decoration: underline;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.92rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.85rem;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  color: var(--text);
  font-weight: 700;
}

.topbar nav {
  display: flex;
  gap: 1rem;
}

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
  display: grid;
  gap: 1.2rem;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-box {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(22, 32, 42, 0.08);
}

.auth-box h1,
.panel h1,
.panel h2 {
  margin: 0;
}

.stack {
  display: grid;
  gap: 1rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.85rem;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.button:hover {
  background: #f8fafc;
  text-decoration: none;
}

.button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button.primary {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

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

.button.ghost {
  background: transparent;
}

.alert {
  margin: 0;
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
}

.alert.success {
  color: var(--success-text);
  background: var(--success-bg);
}

.alert.error {
  color: var(--error-text);
  background: var(--error-bg);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric {
  display: grid;
  gap: 0.35rem;
  padding: 1rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.84rem;
}

.metric strong {
  font-size: 1.7rem;
}

.panel {
  overflow: hidden;
}

.panel > form,
.panel-heading {
  padding: 1rem;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: capitalize;
  background: #eef2f7;
  color: #344054;
}

.badge.active,
.badge.delivered {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge.inactive,
.badge.failed {
  background: var(--error-bg);
  color: var(--error-text);
}

.badge.partial {
  background: #fff4d6;
  color: #8a5a00;
}

.search {
  display: grid;
  grid-template-columns: minmax(220px, 320px) auto;
  gap: 0.6rem;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 0.5rem;
}

.message-preview {
  max-width: 360px;
  max-height: 180px;
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  font: 0.84rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.failure-row td {
  color: var(--danger);
  background: #fff8f7;
}

.empty {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .topbar nav {
    flex-wrap: wrap;
  }

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

  .panel {
    overflow-x: auto;
  }

  .panel-heading,
  .search,
  .inline-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}
