:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --border: #d9e1ea;
  --primary: #0a74c4;
  --primary-dark: #075a99;
  --danger: #c62828;
  --ok: #1b7f3a;
  --warn-bg: #fff7e0;
  --warn-border: #f0c869;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
h1, h2 { margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary); color: #fff; padding: .75rem 1rem;
}
.brand-wrap { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.badge { background: #ffd54f; color: #3b2f00; font-size: .72rem; font-weight: 700; padding: .15rem .45rem; border-radius: 4px; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.6); }

.tabs { display: flex; gap: .25rem; padding: .5rem 1rem 0; background: #e7eef6; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  border: 1px solid transparent; border-bottom: none; background: transparent; padding: .55rem 1rem;
  border-radius: 8px 8px 0 0; cursor: pointer; font: inherit; color: var(--muted);
}
.tab.active { background: var(--bg); border-color: var(--border); color: var(--text); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .3rem; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.label-row label { margin: 0; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: inherit;
}
input[readonly] { background: #f1f4f8; color: var(--muted); }
textarea { resize: vertical; min-height: 6rem; }
#template-picker { width: auto; max-width: 60%; padding: .3rem .5rem; font-size: .9rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.row.space { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row input[type=search] { flex: 1 1 200px; width: auto; }

.btn {
  display: inline-block; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: .55rem 1rem; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: #f0f4f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #efc4c4; }
.btn.small { padding: .35rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.file-btn { position: relative; overflow: hidden; margin: 0; font-weight: 400; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.muted { color: var(--muted); }
.error { color: var(--danger); }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; padding: .5rem .7rem; margin-top: .5rem; word-break: break-all; font-size: .9rem; }
.counter { margin-top: .3rem; font-size: .9rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
.nowrap { white-space: nowrap; }

progress { width: 100%; height: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f1f5fa; font-weight: 600; white-space: nowrap; }
td.msg { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-weight: 600; text-transform: capitalize; }
.status-sent { color: var(--ok); }
.status-failed { color: var(--danger); }
.status-pending, .status-sending { color: var(--muted); }

.template-list { list-style: none; margin: 0; padding: 0; }
.template-list li { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.template-list li:last-child { border-bottom: none; }
.tpl-body { min-width: 0; }
.tpl-text { margin: .25rem 0 0; white-space: pre-wrap; word-break: break-word; color: var(--muted); }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; max-width: 420px; width: calc(100% - 2rem); }
dialog::backdrop { background: rgba(15, 30, 50, .45); }

.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 380px; }
.login-card .brand { color: var(--primary); font-size: 1.4rem; display: block; }
.login-card .btn { width: 100%; margin-top: 1rem; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  main { padding: .6rem; }
  .card { padding: .8rem; }
  .template-list li { flex-direction: column; }
}
