:root {
  --bg: #f5f6fa; --card: #fff; --text: #1d2433; --muted: #6b7385; --line: #e4e7ef;
  --primary: #2f5bea; --primary-d: #2148c4; --primary-l: #eaf0ff;
  --ok: #16a34a; --ok-l: #e8f7ee; --warn: #c27c0e; --warn-l: #fff5e1; --err: #d93636; --err-l: #fdecec;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Heebo', system-ui, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; font-size: 18px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 8px 14px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--primary-l); color: var(--primary); }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; }
.pill { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.pill.low { background: var(--warn-l); color: var(--warn); border-color: transparent; }
.pill.zero { background: var(--err-l); color: var(--err); border-color: transparent; }

.view { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head .sub { color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- controls ---------- */
.btn { font: inherit; border: 1px solid transparent; background: var(--primary); color: #fff; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.btn:hover { background: var(--primary-d); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--text); }
.btn.danger { background: #fff; color: var(--err); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--err-l); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 16px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ''; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.secondary.busy::after, .btn.danger.busy::after { border-color: var(--muted); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-l); border-color: var(--primary); }
input[dir=ltr] { text-align: left; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 500; margin-bottom: 5px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- cards & tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 18px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { max-width: 200px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #fafbfd; font-weight: 500; color: var(--muted); font-size: 13px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbff; }
td.ltr { direction: ltr; text-align: right; }
td.acts { white-space: nowrap; text-align: left; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.chip { display: inline-block; background: var(--primary-l); color: var(--primary); padding: 1px 9px; border-radius: 99px; font-size: 12px; margin: 1px 2px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; }
.badge.draft { background: var(--bg); color: var(--muted); }
.badge.sending, .badge.pending { background: var(--warn-l); color: var(--warn); }
.badge.sent { background: var(--ok-l); color: var(--ok); }
.badge.failed { background: var(--err-l); color: var(--err); }
.badge.cancelled { background: #eee; color: #777; }
.badge.paused { background: #efe9ff; color: #6a3fd1; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.gcard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: .15s; box-shadow: var(--shadow); }
.gcard:hover { border-color: var(--primary); transform: translateY(-1px); }
.gcard .name { font-weight: 700; font-size: 17px; }
.gcard .count { color: var(--muted); font-size: 14px; }

/* ---------- stepper ---------- */
.stepper { display: flex; gap: 6px; margin-bottom: 18px; }
.stepper button { flex: 1; font: inherit; background: #fff; border: 1px solid var(--line); padding: 12px; border-radius: var(--radius); cursor: pointer; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 10px; justify-content: center; }
.stepper button .n { width: 26px; height: 26px; border-radius: 50%; background: var(--bg); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.stepper button.active { border-color: var(--primary); color: var(--primary); background: var(--primary-l); }
.stepper button.active .n { background: var(--primary); color: #fff; }
.stepper button.done .n { background: var(--ok); color: #fff; }

.preview-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.inbox-preview { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; background: #fafbfd; }
.inbox-preview .from { font-weight: 700; }
.inbox-preview .subj { font-weight: 500; }
.inbox-preview .pre { color: var(--muted); }

.progress { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; display: flex; }
.progress > div { height: 100%; transition: width .4s; }
.progress .p-sent { background: var(--ok); }
.progress .p-failed { background: var(--err); }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert.info { background: var(--primary-l); color: #213c94; }
.alert.warn { background: var(--warn-l); color: #7a4d06; }
.alert.err { background: var(--err-l); color: #8f1f1f; }
.alert.ok { background: var(--ok-l); color: #0f6631; }

.group-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.radio-cards label { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.radio-cards label:has(input:checked) { border-color: var(--primary); background: var(--primary-l); }
.radio-cards small { display: block; color: var(--muted); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 6vh 16px; overflow-y: auto; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: pop .18s; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfd; border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; cursor: pointer; color: var(--muted); transition: .15s; }
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-l); color: var(--primary); }
.drop b { color: var(--text); }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1d2433; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; animation: pop .2s; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* ---------- login ---------- */
.auth-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth { width: 100%; max-width: 400px; }
.auth h1 { text-align: center; margin: 0 0 6px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth .switch { text-align: center; margin-top: 14px; color: var(--muted); }
.auth .btn { width: 100%; justify-content: center; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .row, .row3, .radio-cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .view { padding: 18px 14px 50px; }
  .stepper button { font-size: 13px; padding: 10px 6px; }
}
