:root {
  --bg: #f5f6fa; --surface: #fff; --surface-2: #f9fafb; --border: #e5e7eb; --border-strong: #d1d5db;
  --text: #111827; --muted: #6b7280; --faint: #9ca3af;
  --primary: #4f46e5; --primary-600: #4338ca; --primary-50: #eef2ff;
  --success: #059669; --success-50: #ecfdf5; --danger: #dc2626; --danger-50: #fef2f2;
  --warning: #d97706; --warning-50: #fffbeb; --info: #0284c7; --info-50: #f0f9ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --sidebar: 240px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--primary-50); color: var(--primary-600); padding: 1px 5px; border-radius: 4px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: #111827; color: #d1d5db; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; color: #fff; font-weight: 700; font-size: 17px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #a855f7); display: grid; place-items: center; }
.company-chip { margin: 0 12px 12px; padding: 10px 12px; background: #1f2937; border-radius: 8px; font-size: 12px; }
.company-chip b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-chip button { background: none; border: 0; color: #a5b4fc; padding: 0; font-size: 12px; cursor: pointer; }
.nav { padding: 4px 10px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: #d1d5db; font-weight: 500; }
.nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.nav a.active { background: #312e81; color: #fff; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid #1f2937; font-size: 12px; }
.sidebar-foot a { color: #9ca3af; }
.main { flex: 1; min-width: 0; }
.topbar { display: none; }
.content { max-width: 1200px; margin: 0 auto; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-body { padding: 20px; }
.card + .card { margin-top: 20px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: 20px; }

.stat { padding: 18px 20px; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }

/* table */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fcfcfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; color: var(--faint); margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* forms */
.form-row { margin-bottom: 16px; }
label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; font-weight: 400; }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.has-error input, .has-error select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; flex-wrap: wrap; }
.inline-form { display: inline; }
fieldset { border: 0; padding: 0; margin: 0; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 14px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-50); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #f3f4f6; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-draft { background: #f3f4f6; color: #4b5563; }
.badge-scheduled { background: var(--info-50); color: var(--info); }
.badge-sending { background: var(--primary-50); color: var(--primary); }
.badge-paused { background: var(--warning-50); color: var(--warning); }
.badge-completed, .badge-sent, .badge-ok { background: var(--success-50); color: var(--success); }
.badge-failed, .badge-err { background: var(--danger-50); color: var(--danger); }
.badge-pending { background: #f3f4f6; color: #6b7280; }
.badge-skipped { background: #fef3c7; color: #92400e; }
.badge-sending.pulse::before { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

/* alerts */
.flash-stack { margin-bottom: 18px; }
.alert { padding: 12px 16px; border-radius: 8px; border: 1px solid; margin-bottom: 10px; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--success-50); border-color: #a7f3d0; color: #065f46; }
.alert-error { background: var(--danger-50); border-color: #fecaca; color: #991b1b; }
.alert-warning { background: var(--warning-50); border-color: #fde68a; color: #92400e; }
.alert-info { background: var(--info-50); border-color: #bae6fd; color: #075985; }
.alert .close { margin-left: auto; background: none; border: 0; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }

/* progress */
.progress { height: 10px; background: #eef0f4; border-radius: 999px; overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; transition: width .4s ease; }
.progress .p-sent { background: var(--success); }
.progress .p-failed { background: var(--danger); }
.progress .p-skipped { background: #f59e0b; }
.progress-sm { height: 6px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* steps */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px dashed var(--border); align-items: flex-start; }
.steps li:last-child { border-bottom: 0; }
.step-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: #f3f4f6; color: var(--muted); flex-shrink: 0; }
.steps li.done .step-num { background: var(--success); color: #fff; }
.step-body { flex: 1; min-width: 0; }
.step-body p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* misc */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-family: ui-monospace, monospace; font-size: 12px; padding: 2px 8px; border-radius: 5px; background: var(--primary-50); color: var(--primary-600); border: 0; cursor: pointer; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { width: 240px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.pill-group { display: inline-flex; background: #f3f4f6; border-radius: 8px; padding: 3px; }
.pill-group a, .pill-group button { padding: 5px 12px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--muted); border: 0; background: none; cursor: pointer; }
.pill-group .active { background: #fff; color: var(--text); box-shadow: var(--shadow); text-decoration: none; }
.pagination { display: flex; gap: 6px; justify-content: center; padding: 16px; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: 10px; padding: 28px; text-align: center; background: var(--surface-2); cursor: pointer; transition: .15s; display: block; font-weight: 400; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-50); }
.dropzone svg { width: 34px; height: 34px; color: var(--primary); }
.dropzone input { display: none; }
.dropzone b { color: var(--primary); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.chart .bar span { display: block; width: 100%; max-width: 28px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.chart .bar:hover span { opacity: 1; }
.chart .bar small { font-size: 10.5px; color: var(--faint); }
.sender-option { display: flex; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; align-items: center; margin-bottom: 8px; font-weight: 400; }
.sender-option:hover { border-color: var(--primary); }
.sender-option input { accent-color: var(--primary); width: 16px; height: 16px; }
.sender-option:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head button { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 22px; }
.result { margin-top: 12px; font-size: 13px; }
.result.ok { color: var(--success); } .result.err { color: var(--danger); }
.preview-frame { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.scroll-x { overflow-x: auto; }
.map-table td, .map-table th { padding: 8px 12px; font-size: 13px; }
.map-table th select { font-size: 12px; padding: 5px 8px; font-weight: 500; text-transform: none; }
.col-email { background: #ecfdf5 !important; } .col-name { background: #eff6ff !important; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #e0e7ff, transparent 40%), radial-gradient(circle at 90% 90%, #f3e8ff, transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { color: var(--text); justify-content: center; padding: 0 0 20px; font-size: 20px; }

/* editor layout */
.editor-app { height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.editor-top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.editor-top .name-input { max-width: 280px; font-weight: 600; }
.editor-top .subject-input { flex: 1; min-width: 200px; }
.editor-toolbar { display: flex; gap: 6px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.editor-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.editor-toolbar select { width: auto; padding: 5px 8px; font-size: 13px; }
.editor-split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.editor-pane { min-height: 0; display: flex; flex-direction: column; }
.editor-pane + .editor-pane { border-left: 1px solid var(--border); }
.pane-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.code-wrap { flex: 1; min-height: 0; position: relative; }
.code-wrap textarea.raw { width: 100%; height: 100%; border: 0; border-radius: 0; resize: none; font-family: ui-monospace, monospace; font-size: 13px; padding: 12px; }
.code-wrap .CodeMirror { height: 100%; font-size: 13px; }
.preview-wrap { flex: 1; min-height: 0; overflow: auto; display: flex; justify-content: center; background: #e5e7eb; padding: 16px; }
.preview-wrap iframe { background: #fff; border: 0; width: 100%; height: 100%; box-shadow: var(--shadow); transition: width .25s; }
.preview-wrap.mobile iframe { width: 390px; border-radius: 20px; }
.editor-split.full-code { grid-template-columns: 1fr 0; } .editor-split.full-code .editor-pane:last-child { display: none; }
.editor-split.full-preview { grid-template-columns: 0 1fr; } .editor-split.full-preview .editor-pane:first-child { display: none; }

@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3, .grid-main, .grid-2 { grid-template-columns: 1fr; }
  .editor-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .editor-pane + .editor-pane { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #111827; color: #fff; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .content { padding: 20px 16px 40px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { width: 100%; }
}
