:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef4fb;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #d7e0ea;
  --brand: #0e7490;
  --brand-2: #155e75;
  --danger: #be123c;
  --success: #15803d;
  --warning: #b45309;
  --radius: 8px;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: inherit; }
button, input, textarea, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 950;
}
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; }
.nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.nav a, .link-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  font-weight: 800;
}
.nav a:hover, .link-button:hover { color: var(--brand); }

.page {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}
.hero {
  min-height: 230px;
  display: flex;
  align-items: center;
  padding: 32px;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(14, 116, 144, .92), rgba(15, 23, 42, .94)),
    url("/static/pattern.svg");
  color: #fff;
  box-shadow: var(--shadow);
}
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 5vw, 56px);
  letter-spacing: 0;
}
.hero p {
  margin: 0;
  max-width: 720px;
  color: #dbeafe;
  line-height: 1.9;
}
.eyebrow {
  margin: 0 0 8px;
  color: #a7f3d0;
  font-weight: 900;
}
.form-list {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.form-card, .panel, .login-card, .section-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-card {
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  text-decoration: none;
}
.form-card:hover { border-color: #67e8f9; }
.form-card h2 { margin: 0; }
.form-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
  flex: 1;
}
.form-kind {
  width: max-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: #ecfeff;
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 900;
}
.empty, .notice {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--muted);
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.admin-side {
  position: sticky;
  top: 84px;
  display: grid;
  gap: 6px;
  padding: 10px;
  background: #0f172a;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.admin-side a {
  padding: 11px 12px;
  border-radius: 7px;
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 800;
}
.admin-side a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.admin-main { min-width: 0; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}
.section-title h1, .panel h2, .section-block h2 {
  margin: 0 0 6px;
}
.section-title p, .muted, .hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat span { display: block; color: var(--muted); font-weight: 800; }
.stat strong { display: block; margin-top: 10px; font-size: 34px; }
.stat.danger strong { color: var(--danger); }
.panel { padding: 16px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; }
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.search-bar input {
  min-width: 240px;
}
.cell-subtext {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  font-weight: 900;
}
.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}
.btn.plain { background: #fff; }
.btn.danger {
  border-color: #fecdd3;
  background: #fff1f2;
  color: var(--danger);
}
.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-weight: 850;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
.source-editor textarea {
  min-height: 560px;
  direction: ltr;
  text-align: left;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.55;
  white-space: pre;
  tab-size: 2;
}
input:focus, textarea:focus, select:focus {
  outline: 3px solid rgba(14, 116, 144, .18);
  border-color: var(--brand);
}
.grid {
  display: grid;
  gap: 14px;
}
.grid.two, .detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.login-card {
  width: min(420px, 100%);
  margin: 60px auto;
  padding: 22px;
}
.login-card h1 { margin: 0 0 8px; }
.login-card p { color: var(--muted); }
.login-card form { display: grid; gap: 14px; }
.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}
.flash.error {
  background: #fff1f2;
  border-color: #fecdd3;
  color: var(--danger);
}
.flash.success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--success);
}
.status {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
}
.status.sent { background: #dcfce7; color: var(--success); }
.status.failed { background: #ffe4e6; color: var(--danger); }
.status.pending, .status.skipped { background: #fef3c7; color: var(--warning); }
.editor-form {
  display: grid;
  gap: 16px;
}
.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.field-builder {
  display: grid;
  gap: 12px;
}
.field-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  display: grid;
  gap: 12px;
}
.field-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check-line input {
  width: auto;
}
.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.form-shell {
  display: grid;
  gap: 16px;
}
.form-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius);
  background: #0f172a;
  color: #fff;
  box-shadow: var(--shadow);
}
.form-head h1 { margin: 4px 0 8px; }
.form-head p { margin: 0; color: #cbd5e1; }
.back-link { color: #67e8f9; text-decoration: none; font-weight: 900; }
.section-block {
  padding: 16px;
}
.rt-form {
  display: grid;
  gap: 14px;
}
.dynamic-field b { color: var(--danger); }
.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.choice-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.choice-row input { width: auto; }
.save-state {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  color: #dbeafe;
  font-size: 12px;
  font-weight: 900;
}
.save-state.ok { background: #dcfce7; color: var(--success); }
.save-state.error { background: #ffe4e6; color: var(--danger); }
.save-state.busy { background: #fef3c7; color: var(--warning); }
.meta-list {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 12px;
  margin: 0;
}
.meta-list dt { color: var(--muted); font-weight: 900; }
.meta-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prebox {
  max-height: 520px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  padding: 12px;
  border-radius: var(--radius);
  background: #0f172a;
  color: #dbeafe;
}

@media (max-width: 820px) {
  .topbar, .section-title, .form-head {
    align-items: stretch;
    flex-direction: column;
  }
  .admin-layout, .grid.two, .detail-grid, .stats-grid {
    grid-template-columns: 1fr;
  }
  .admin-side {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .search-bar {
    align-items: stretch;
    flex-direction: column;
  }
  .search-bar input {
    min-width: 0;
  }
}
