/* Newsletter Pro - custom responsive UI (no framework, no CDN) */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .04);
  --radius: 12px;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #172033;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --sidebar: #020617;
  --sidebar-text: #cbd5e1;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; color: #fff; padding: .5rem .5rem 1.25rem; }
.brand-mark { font-size: 1.4rem; }
.nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav-item { color: var(--sidebar-text); padding: .65rem .75rem; border-radius: 8px; display: block; font-weight: 500; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-divider { height: 1px; background: rgba(255,255,255,.12); margin: .75rem .25rem; }
.sidebar-footer { padding-top: 1rem; }

/* Main / topbar */
.main { flex: 1; min-width: 0; }
.topbar {
  height: 60px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.3rem; color: var(--text); cursor: pointer; }
.user-chip { display: flex; align-items: center; gap: .5rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.user-name { font-weight: 500; }
.logout { margin-left: .5rem; font-size: 1.1rem; }
.lang-link { font-weight: 600; }
.content { padding: 1.5rem; max-width: 1500px; margin: 0 auto; }

/* Cards & grids */
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.hint { color: var(--muted); font-size: .85rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.stat-card { position: relative; }
.stat-label { color: var(--muted); font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 2rem; font-weight: 700; margin-top: .35rem; }
.stat-icon { position: absolute; right: 1rem; top: 1rem; font-size: 1.5rem; opacity: .6; }
.action-card { display: block; padding: 1rem; font-weight: 600; color: var(--text); }
.action-card:hover { border-color: var(--primary); text-decoration: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--panel-2); }
.row-actions { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }
.dots { display: inline-flex; gap: .3rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .3rem; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }
.quota-bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; width: 140px; margin-bottom: .3rem; }
.quota-bar span { display: block; height: 100%; background: var(--primary); }
.badge { padding: .15rem .5rem; border-radius: 99px; font-size: .72rem; font-weight: 600; display: inline-block; }
.badge-ok, .badge-sent, .badge-confirmed, .badge-completed { background: #dcfce7; color: #166534; }
.badge-err, .badge-failed, .badge-bounced, .badge-cancelled, .badge-down { background: #fee2e2; color: #991b1b; }
.badge-pending, .badge-scheduled, .badge-unconfirmed, .badge-draft { background: #fef3c7; color: #92400e; }
.badge-muted { background: var(--panel-2); color: var(--muted); }
.badge-paused, .badge-sending { background: #dbeafe; color: #1e40af; }
[data-theme="dark"] .badge-ok, [data-theme="dark"] .badge-sent, [data-theme="dark"] .badge-confirmed, [data-theme="dark"] .badge-completed { background: #14532d; color: #bbf7d0; }
[data-theme="dark"] .badge-err, [data-theme="dark"] .badge-failed, [data-theme="dark"] .badge-bounced { background: #7f1d1d; color: #fecaca; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .85rem; border-radius: 8px; border: 1px solid transparent; font-size: .85rem;
  font-weight: 600; cursor: pointer; line-height: 1.2; background: var(--panel-2); color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-sm { padding: .32rem .55rem; font-size: .78rem; }
.btn-block { width: 100%; margin-top: .5rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.link { font-size: .85rem; }

/* Forms */
.form-card { display: flex; flex-direction: column; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .85rem; }
input, select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit; font-size: .9rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; }
.check-label { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
.check-label input[type="checkbox"], .check-label input[type="radio"] { width: auto; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.check-inline { display: flex; align-items: center; gap: .4rem; }
.fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin: 0; }
.fieldset legend { font-weight: 700; padding: 0 .4rem; font-size: .9rem; }
.fieldset legend.legend-with-actions { display: flex; align-items: center; gap: .5rem; width: 100%; }
.legend-title { flex: 1; }
.mode-switch { display: inline-flex; gap: .25rem; }
.mode-switch .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.form-actions { display: flex; gap: .5rem; align-items: center; }
.filter-bar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-bar input { max-width: 320px; }
.filter-bar select { max-width: 200px; }
.bulk-bar { display: flex; gap: .5rem; margin-bottom: .75rem; }
.bulk-bar select { max-width: 220px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; padding-top: 1rem; }

/* Editor */
.editor-toolbar { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .5rem; }
.editor-toolbar button, .editor-toolbar select { width: auto; padding: .35rem .6rem; }
.editor {
  min-height: 280px; border: 1px solid var(--border); border-radius: 8px; padding: 1rem;
  background: var(--panel); overflow-y: auto; line-height: 1.6;
}
.editor:empty:before { content: attr(data-placeholder); color: var(--muted); }
.editor img { max-width: 100%; }
.editor-pane[hidden] { display: none; }
.html-source {
  width: 100%; min-height: 280px; resize: vertical; line-height: 1.5; font-size: .85rem;
  border: 1px solid var(--border); border-radius: 8px; padding: 1rem; background: var(--panel); color: var(--text);
}
.preview-frame-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
#emailPreview { display: block; width: 100%; min-height: 520px; border: 0; background: #fff; }

/* SMTP capability detection */
.detect-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.detect-panel { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.15rem; margin: 0 0 1.25rem; }
.detect-panel[hidden] { display: none; }
.detect-panel h3 { font-size: 1rem; margin-bottom: .85rem; }
.detect-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .85rem 1.25rem; }
.detect-grid > div { display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; }
.detect-recommend { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 1rem; }
.detect-recommend > div { display: flex; flex-direction: column; gap: .2rem; }
.detect-raw { margin-top: .85rem; font-size: .85rem; }
.detect-raw summary { cursor: pointer; color: var(--muted); }
.detect-raw .log-view { margin-top: .6rem; max-height: 220px; }

/* Auth */
.bare-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, var(--bg), var(--panel-2)); }
.auth-wrap { display: grid; place-items: center; min-height: 70vh; }
.auth-card { width: min(420px, 94vw); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.3rem; margin-bottom: 1.25rem; }
.auth-card h1 { margin-bottom: 1rem; }
.auth-card label { margin-bottom: .85rem; }
.auth-foot { margin-top: 1rem; text-align: center; }

/* Alerts / toasts / modal */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.toast { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 100; padding: .85rem 1.2rem; border-radius: 10px; color: #fff; background: var(--success); box-shadow: var(--shadow); max-width: 380px; animation: slidein .2s ease-out; }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 90; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--panel); border-radius: 12px; padding: 1.5rem; width: min(420px, 92vw); box-shadow: var(--shadow); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* Misc */
.cron-widget { display: flex; flex-direction: column; gap: .6rem; }
.cron-line { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px dashed var(--border); padding-bottom: .4rem; }
.cron-stats, .log-view { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; overflow: auto; font-size: .78rem; max-height: 460px; white-space: pre-wrap; word-break: break-word; }
.key-box { display: block; padding: .75rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; word-break: break-all; margin-bottom: .75rem; }
.dns-record { display: flex; align-items: center; gap: .5rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: .6rem; margin-bottom: 1rem; }
.dns-record code { flex: 1; word-break: break-all; font-size: .82rem; }
.test-form { display: flex; gap: .4rem; margin-top: .5rem; }
.test-form input { max-width: 180px; }
.live-events { max-height: 420px; overflow: auto; }
.live-events table { font-size: .78rem; }
.live-events td { vertical-align: top; }
.live-events td:nth-child(4) { min-width: 220px; }

@media (max-width: 1000px) {
  .cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; width: 236px; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: block; }
  .cards-4, .form-grid, .check-grid { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
  .user-name { display: none; }
}
