:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #1c2030;
  --muted: #6b7286;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --success: #15803d;
  --success-soft: #e8f6ed;
  --warning: #a16207;
  --warning-soft: #fdf6e3;
  --danger: #c2410c;
  --danger-soft: #fdeee8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 2px 8px rgba(20, 24, 40, .04);
  --sidebar: #161a2b;
  --sidebar-text: #b9bfd3;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: .5rem 0; width: 100%; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .88em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error-text { color: var(--danger); }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 1.25rem .9rem;
  display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 0; height: 100vh;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0 .6rem; display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 1rem;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--sidebar-text); padding: .55rem .7rem; border-radius: 7px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 0 .6rem; font-size: .85rem; }
.user-email { display: block; color: var(--sidebar-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: .4rem; }
.user-email:hover, .user-email.active { color: #fff; }
.badge-r-sending { background: var(--primary-soft); color: var(--primary); }
.sidebar .btn-ghost { color: var(--sidebar-text); padding-left: 0; }
.sidebar .btn-ghost:hover { color: #fff; background: none; }
.main { padding: 2rem 2.5rem 3rem; max-width: 1400px; width: 100%; display: flex; flex-direction: column; gap: 1.25rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.page-head p { margin: .2rem 0 0; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.back { display: inline-block; font-size: .88rem; margin-bottom: .35rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.stack > .card-head { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.grid-2.wide-left { grid-template-columns: 3fr 2fr; }
.row { display: flex; gap: .9rem; }
.row > * { flex: 1; min-width: 0; }
.row.align-end { align-items: flex-end; }
.row > .grow { flex: 3; }
.row > .w-port { flex: 0 0 110px; }
.row > button { flex: 0 0 auto; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; margin: 0; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="file"] { padding: .4rem; background: var(--surface-2); }
textarea.code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .82rem; line-height: 1.45; resize: vertical; tab-size: 2; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; }
.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input { width: 240px; }
.rename-form { display: flex; gap: .5rem; align-items: center; }
.h1-input { font-size: 1.5rem; font-weight: 700; border-color: transparent; padding: .1rem .4rem; margin-left: -.4rem; background: transparent; width: auto; min-width: 280px; }
.h1-input:hover, .h1-input:focus { border-color: var(--border); background: var(--surface); }
.clear-form { margin-top: 1rem; text-align: right; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
  padding: .55rem 1rem; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: #f5c9b8; }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-block { width: 100%; padding: .7rem; }
.file-btn { flex-direction: row; font-weight: 600; }

/* Flash */
.flash { padding: .75rem 1rem; border-radius: 8px; border: 1px solid; font-size: .92rem; }
.flash-success { background: var(--success-soft); border-color: #bfe5cc; color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: #f5c9b8; color: var(--danger); }
.flash-warning { background: var(--warning-soft); border-color: #f0dfa8; color: var(--warning); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .65rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: .3rem; }
.table.compact td { padding: .35rem .5rem; }

/* Badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge-draft { background: var(--surface-2); color: var(--muted); }
.badge-sending, .badge-r-pending { background: var(--primary-soft); color: var(--primary); }
.badge-paused, .badge-r-skipped { background: var(--warning-soft); color: var(--warning); }
.badge-sent, .badge-r-sent { background: var(--success-soft); color: var(--success); }
.badge-r-failed { background: var(--danger-soft); color: var(--danger); }
h1 .badge { font-size: .8rem; position: relative; top: -3px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.card .stat { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.stat-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--success); }
.stat-value.err { color: var(--danger); }
.stat-label { color: var(--muted); font-size: .85rem; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .5s; }

/* Steps */
.steps { margin: .75rem 0 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: .5rem; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.steps li.done a { display: none; }

/* Tabs / pager / segmented */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs a { padding: .3rem .65rem; border-radius: 6px; font-size: .85rem; color: var(--muted); font-weight: 500; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; font-size: .88rem; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 7px; padding: 3px; }
.segmented button { font: inherit; font-size: .82rem; font-weight: 600; border: 0; background: transparent; padding: .3rem .7rem; border-radius: 5px; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Campaign editor */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.preview-card { position: sticky; top: 1rem; }
.preview-meta { background: var(--surface-2); border-radius: 7px; padding: .6rem .8rem; font-size: .9rem; margin-bottom: .75rem; }
.preview-frame-wrap { background: var(--surface-2); border-radius: 8px; padding: .75rem; display: flex; justify-content: center; }
.preview-frame-wrap iframe { width: 100%; height: 72vh; border: 1px solid var(--border); border-radius: 6px; background: #fff; transition: width .25s; }
.preview-frame-wrap iframe.mobile { width: 375px; max-width: 100%; }
.send-row { display: flex; justify-content: space-between; gap: .6rem; }
details.help summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--primary); }
details.help[open] summary { margin-bottom: .5rem; }
.help dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: .75rem 0; font-size: .9rem; }
.help dt { color: var(--muted); }
.help dd { margin: 0; }
.help p { font-size: .88rem; margin: .5rem 0 0; }

/* Auth & public */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 2rem 1rem; gap: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.4rem; }
.auth-card .stack { margin: 1.25rem 0; }
.auth-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; margin-bottom: 1.25rem; }
.unsub-email { font-weight: 600; background: var(--surface-2); padding: .6rem; border-radius: 7px; word-break: break-all; }
.check { width: 52px; height: 52px; margin: 0 auto 1rem; border-radius: 50%; background: var(--success-soft); color: var(--success); display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; }

/* Crédits & offres */
.nav-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #6f7690; padding: 0 .7rem .3rem; font-weight: 600; }
.credit-box { display: flex; flex-direction: column; margin: 0 .2rem; padding: .7rem .8rem; border-radius: 8px; background: rgba(255, 255, 255, .06); color: var(--sidebar-text); }
.credit-box:hover { background: rgba(255, 255, 255, .1); text-decoration: none; }
.credit-value { color: #fff; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.credit-value.is-zero { color: #f59e7a; }
.credit-label { font-size: .8rem; }
.sidebar { overflow-y: auto; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.pack { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; display: flex; flex-direction: column; gap: .35rem; }
.pack .btn { margin-top: auto; }
.pack p { margin: 0 0 .5rem; }
.pack-unlimited { border-color: var(--primary); background: var(--primary-soft); }
.pack-name { font-weight: 700; }
.pack-amount { color: var(--muted); }
.pack-price { font-size: 1.6rem; font-weight: 700; margin: .25rem 0; }
.stat-link { color: inherit; }
.stat-link:hover { border-color: var(--primary); text-decoration: none; }
.stat-value.warn { color: var(--warning); }
.ok-text { color: var(--success); }
.row-disabled td { opacity: .55; }
.badge-o-pending { background: var(--warning-soft); color: var(--warning); }
.badge-o-paid { background: var(--success-soft); color: var(--success); }
.badge-o-cancelled { background: var(--surface-2); color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label.checkbox input { width: auto; }
.narrow { max-width: 720px; }
.w-credits { width: 110px !important; }
.row > .w-op { flex: 0 0 140px; }
.account-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a3360a; }
.danger-zone { border: 1px solid #f5c9b8; border-radius: 8px; padding: .75rem 1rem; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.danger-zone[open] summary { margin-bottom: .5rem; }
.pre-line { white-space: pre-line; }
input:disabled { background: var(--surface-2); color: var(--muted); }

@media (max-width: 1100px) {
  .editor-layout, .grid-2, .grid-2.wide-left { grid-template-columns: 1fr; }
  .preview-card { position: static; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .75rem 1rem; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0; }
  .main { padding: 1.25rem 1rem 2rem; }
  .row { flex-direction: column; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input { width: 100%; }
  .table { display: block; overflow-x: auto; }
}
