:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #17202a;
  --muted: #667085;
  --primary: #216fed;
  --primary-dark: #1756bc;
  --success: #0f8a5f;
  --danger: #c9342f;
  --warning: #a15c00;
  --sidebar: #142033;
  --sidebar-active: #263a59;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

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

.layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 18px 14px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  padding: 10px 12px 20px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d7ddea;
  padding: 11px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.nav a.active,
.nav a:hover {
  background: var(--sidebar-active);
  color: #fff;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.content {
  padding: 22px 24px 48px;
}

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

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

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

.grid {
  display: grid;
  gap: 14px;
}

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

.broadcast-grid {
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  align-items: start;
}

.broadcast-grid form {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

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

.form-grid .wide {
  grid-column: span 2;
}

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

.btn {
  border: 0;
  border-radius: 7px;
  padding: 9px 13px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}

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

.btn.secondary {
  background: #eef2f7;
  color: var(--text);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  padding: 6px 9px;
  min-height: 30px;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

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

th {
  background: #f7f9fc;
  color: #48556a;
  font-weight: 600;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  color: #354052;
  background: #eef2f7;
  white-space: nowrap;
}

.badge.sent,
.badge.resent,
.badge.reserve_sent,
.badge.bound,
.badge.ok {
  background: #e7f7ef;
  color: var(--success);
}

.badge.failed,
.badge.invalid,
.badge.disabled {
  background: #fdecec;
  color: var(--danger);
}

.badge.unbound,
.badge.pending,
.badge.reserve_available {
  background: #fff3df;
  color: var(--warning);
}

.alert {
  background: #eaf3ff;
  color: #12498f;
  border: 1px solid #bdd7ff;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  gap: 16px;
}

.inline-form {
  display: inline;
}

.pagination {
  margin-top: 12px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
}

.template-editor {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.message-cell {
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

  .sidebar {
    position: static;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
  }

  .nav a {
    white-space: nowrap;
  }

  .stats,
  .broadcast-grid,
  .form-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .form-grid .full {
    grid-column: auto;
  }

  .topbar {
    padding: 0 14px;
  }

  .content {
    padding: 16px;
  }
}
