:root {
  --red: #d52b29;
  --red-rgb: 213, 43, 41;
  --green: #16a34a;
  --red-dark: #a91f1d;
  --primary-text: #fff;
  --link-hover: #d52b29;
  --danger: #d52b29;
  --danger-dark: #a91f1d;
  --ink: #171717;
  --muted: #70727a;
  --line: #e6e7eb;
  --bg: #f5f5f2;
  --card: #fff;
  --soft: #f0ece7;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: inherit; }
input, textarea, select, button { font: inherit; }
i[data-lucide] { visibility: hidden; display: inline-block; width: 17px; height: 17px; flex: 0 0 17px; }
svg.lucide { visibility: visible; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; color: #383838; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 10px 11px; color: var(--ink); font-weight: 400; }
textarea { resize: vertical; }

.login-body { min-height: 100vh; background: radial-gradient(circle at top left, #f5dad5, transparent 35%), #202124; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 28px; padding: 34px; box-shadow: 0 28px 90px rgba(0, 0, 0, .28); display: grid; gap: 18px; }
.login-logo { width: 210px; max-width: 100%; filter: var(--login-logo-filter, none); }
.login-card label:first-of-type { margin-top: 8px; }
.login-card label:last-of-type { margin-bottom: 8px; }
.login-card h1, .hero h1, .page-head h1 { margin: 0; }
.hint { color: var(--muted); }
.eyebrow { letter-spacing: .14em; text-transform: uppercase; color: var(--login-subtitle, var(--red)); font-size: 12px; font-weight: 800; }

.primary, .link-button, .danger, .dark, .send-box button {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.primary, .link-button { background: var(--red); color: var(--primary-text); }
.danger, .send-box button.danger { background: var(--danger); color: #fff; }
.dark, .send-box button.dark { background: #171717; color: #fff; }
.send-box button:not(.danger):not(.dark) { background: var(--red); color: var(--primary-text); }
.primary:hover, .link-button:hover, .send-box button:not(.danger):not(.dark):hover { background: var(--red-dark); }
.danger:hover, .send-box button.danger:hover { background: var(--danger-dark); }
.dark:hover, .send-box button.dark:hover { background: #000; }
.ghost { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; cursor: pointer; color: var(--ink); }
.with-icon svg, .action-button svg, .toolbox svg, .import-news-box svg, .news-import-item svg, .send-box svg { width: 16px; height: 16px; stroke-width: 2.2; flex: 0 0 auto; }

.app-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #171717; color: #fff; padding: 24px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 24px; font-weight: 900; letter-spacing: -.08em; display: grid; gap: 10px; }
.brand img { display: block; width: 176px; max-width: 100%; height: auto; filter: brightness(0) invert(1); }
.brand span { color: #fff; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; font-weight: 800; }
.brand span { color: var(--brand-subtitle, var(--red)); }
nav { display: grid; gap: 8px; }
nav a, .logout { padding: 12px 14px; border-radius: 14px; text-decoration: none; color: #d8d8d8; display: flex; align-items: center; gap: 10px; }
nav a svg, .logout svg { width: 17px; height: 17px; color: #aaa; }
nav a.active svg, nav a:hover svg, .logout:hover svg { color: #fff; }
nav a.active, nav a:hover { background: #292929; color: #fff; }
.logout { margin-top: auto; }
.sidebar-footer { color: #8d8d8d; font-size: 11px; line-height: 1.35; }
.main { padding: 30px; max-width: 1700px; width: 100%; margin: 0 auto; }

.flash { padding: 13px 16px; border-radius: 16px; margin-bottom: 18px; font-weight: 700; }
.flash.ok { background: #e7f7ec; color: #17612d; }
.flash.error { background: #ffe7e5; color: #9d1d19; }
.hero { background: linear-gradient(135deg, #fff 0, #fff 55%, #f4d5d0 100%); border-radius: 30px; padding: 32px; box-shadow: 0 18px 70px rgba(27, 27, 27, .08); }
.hero h1 { font-size: clamp(30px, 4vw, 54px); letter-spacing: -.05em; line-height: 1; max-width: 900px; margin-bottom: 22px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin: 18px 0; }
.quick-links { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 18px 0 0; }
.quick-links a { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 16px; text-decoration: none; font-weight: 850; box-shadow: 0 10px 30px rgba(27, 27, 27, .04); }
.quick-links svg { width: 18px; height: 18px; color: var(--red); }
.stats-grid div, .card { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: 0 10px 30px rgba(27, 27, 27, .04); }
.chart-card, .cost-card, .recent-newsletters-card { margin-top: 18px; }
.chart-card canvas { width: 100%; }
.chart-card { min-height: auto; }
.chart-wrap { position: relative; height: 322px; min-height: 322px; max-height: 322px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.period-form { margin: 0; }
.period-form label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.period-form select { min-width: 130px; padding: 8px 10px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; color: var(--muted); font-weight: 800; }
.status-pill { display: inline-flex; border-radius: 999px; background: #f1f2f3; padding: 5px 9px; font-size: 12px; font-weight: 800; }
.scheduled-inline { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.scheduled-inline svg { width: 14px; height: 14px; stroke-width: 2.3; }
.status-pill.status-sent { background: rgba(22, 163, 74, .14); color: var(--green); }
.status-draft { background: #f1f2f3; color: var(--ink); }
.status-scheduled { background: rgba(31, 111, 235, .12); color: #1f6feb; }
.status-opened { background: rgba(31, 111, 235, .12); color: #1f6feb; }
.status-clicked { background: rgba(138, 63, 252, .12); color: #8a3ffc; }
.status-failed { background: rgba(213, 43, 41, .12); color: #d52b29; }
.status-unsubscribed { background: rgba(245, 159, 0, .14); color: #f59f00; }
.metric { font-weight: 800; }
.metric-sent { color: var(--green); }
.metric-opened { color: #1f6feb; }
.metric-clicked { color: #8a3ffc; }
.metric-bounce { color: #d52b29; }
.metric-unsubscribed { color: #f59f00; }
.stats-grid strong { display: block; font-size: 34px; letter-spacing: -.06em; }
.stats-grid span { color: var(--muted); font-weight: 700; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.page-head.compact { margin-bottom: 12px; }
.page-head h1 { font-size: 30px; letter-spacing: -.04em; }

.grid.two { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.contacts-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.side-stack { display: grid; gap: 18px; align-items: start; }
.card { overflow: auto; }
.card h2 { margin-top: 0; }
form.card h2 { white-space: nowrap; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.template-links { display: flex; gap: 8px; flex-wrap: wrap; }
.table-search { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto; align-items: end; gap: 10px; margin-bottom: 14px; }
.table-search label { margin: 0; }
#contactsTableRegion { transition: opacity .12s ease; }
#contactsTableRegion.is-loading { opacity: .55; }
.import-form { display: grid; grid-template-columns: minmax(260px, 1fr) auto; align-items: end; gap: 10px; background: #fbfbfa; border: 1px solid var(--line); border-radius: 18px; padding: 12px; margin-bottom: 14px; }
.import-card { grid-template-columns: 1fr; align-items: stretch; margin-bottom: 0; padding: 18px; }
.import-form .hint { grid-column: 1 / -1; margin: 0; font-size: 12px; }
form.card { display: grid; gap: 14px; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: grid; gap: 7px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: auto; }
.pool-picker { max-height: 170px; overflow: auto; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 11px 10px; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
td small { display: block; color: var(--muted); margin-top: 4px; }
.table-primary-link { color: var(--ink); text-decoration: none; font-weight: 800; }
.table-primary-link small { font-weight: 400; }
a.table-primary-link:hover { color: var(--link-hover); }
.row-actions { min-width: 300px; white-space: nowrap; vertical-align: middle; font-size: 0; }
.row-actions form { margin: 0 8px 0 0; display: inline-flex; vertical-align: middle; align-items: center; line-height: 0; }
.row-actions button.action-button { height: 36px; appearance: none; }
.row-actions .action-button { margin-right: 8px; vertical-align: middle; font-size: 12px; font-weight: 500; line-height: 1; }
.row-actions .action-button:last-child { margin-right: 0; }
.contacts-table .row-actions { min-width: 150px; width: 150px; }
.contacts-table .row-actions .action-button { padding-left: 10px; padding-right: 10px; }
.action-button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; font-weight: 800; white-space: nowrap; }

.editor-layout { display: grid; grid-template-columns: 430px minmax(0, 1fr); gap: 18px; align-items: start; }
.scheduled-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; border: 1px solid rgba(245, 159, 0, .28); border-radius: 16px; background: rgba(245, 159, 0, .12); color: #b76e00; padding: 12px 14px; font-size: 14px; font-weight: 700; }
.scheduled-banner span { display: inline-flex; align-items: center; gap: 8px; }
.scheduled-banner form { margin: 0; }
.scheduled-banner .action-button { min-height: 32px; background: #fff; color: #9a5a00; border-color: rgba(245, 159, 0, .32); font-size: 12px; font-weight: 600; }
.scheduled-banner svg { width: 18px; height: 18px; stroke-width: 2.4; }
.editor-panel, .preview-panel { background: #fff; border-radius: 26px; border: 1px solid var(--line); padding: 18px; min-width: 0; }
.editor-panel { display: grid; gap: 12px; position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; }
.editor-layout.has-scheduled-banner .editor-panel { max-height: calc(100vh - 128px); }
.toolbox { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; background: var(--soft); border-radius: 18px; padding: 10px; }
.toolbox button, .block-card button { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 12px; padding: 9px; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.toolbox button { font-weight: 400; }
.toolbox button:hover, .block-card button:hover { border-color: #c8c9cf; background: #fafafa; }
.import-news-box { border: 1px solid var(--line); border-radius: 18px; background: #fbfbfa; overflow: hidden; }
.import-news-box summary { cursor: pointer; padding: 12px; font-weight: 400; display: flex; align-items: center; gap: 8px; }
.news-import-list { display: grid; gap: 10px; max-height: 360px; overflow: auto; padding: 0 12px 12px; }
.news-import-item { display: grid; grid-template-columns: 74px 1fr; gap: 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 8px; }
.news-import-item img { width: 74px; height: 74px; object-fit: cover; border-radius: 10px; background: var(--soft); }
.news-import-item div { display: grid; gap: 5px; }
.news-import-item small { color: var(--muted); font-weight: 800; }
.news-import-item strong { font-size: 13px; line-height: 1.25; }
.news-import-item button { justify-self: start; border: 0; background: var(--red); color: #fff; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 900; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.upload-control small { color: var(--muted); font-weight: 600; }
.upload-control input { padding: 9px; }
.section-divider { height: 1px; background: var(--line); margin: 6px 0 2px; }
.editor-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.editor-section-title { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.empty-block-hint { margin: 0; color: var(--muted); font-size: 13px; font-weight: 400; background: #f1f2f3; border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; align-items: center; gap: 8px; width: 100%; }
.empty-block-hint.is-hidden { display: none; }
.or-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.or-divider::before, .or-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.icon-only { width: 36px; padding-left: 0; padding-right: 0; }
.editor-section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.editor-section-actions .action-button { min-height: 32px; padding: 7px 10px; font-size: 12px; }
.newsletter-title-link { display: flex; align-items: center; gap: 12px; }
.newsletters-table td { vertical-align: middle; }
.newsletters-table th:first-child, .newsletters-table td:first-child { width: 36%; }
.newsletters-table .row-actions { height: 124px; }
.newsletter-thumb { width: 92px; height: 96px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f1f2f3; flex: 0 0 auto; position: relative; }
.newsletter-thumb iframe { width: 600px; height: 685px; border: 0; transform: scale(.148); transform-origin: top left; pointer-events: none; background: #f1f2f3; }
.block-list { display: grid; gap: 10px; }
.block-card { border: 1px solid var(--line); border-radius: 18px; padding: 12px; background: #fbfbfa; display: grid; gap: 10px; }
.block-card.dragging { opacity: .55; }
.block-card.drag-over { border-color: var(--red); box-shadow: inset 0 0 0 2px rgba(var(--red-rgb), .18); }
.block-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.block-title { font-weight: 400; border: 0; background: transparent; padding: 0; display: inline-flex; align-items: center; gap: 7px; cursor: grab; color: var(--ink); }
.block-title:active { cursor: grabbing; }
.block-body { display: grid; gap: 10px; }
.block-card.is-collapsed .block-body { display: none; }
.block-card.is-collapsed .collapse-icon { transform: rotate(-90deg); }
.collapse-icon { transition: transform .16s ease; }
.block-card.focus-pulse { animation: focusPulse 1.15s ease-out 1; }
.block-actions { display: flex; gap: 6px; }
.block-actions button { padding: 7px 9px; }
.block-actions svg { width: 14px; height: 14px; }
.preview-panel { min-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.editor-layout.has-scheduled-banner .preview-panel { min-height: calc(100vh - 128px); }
.preview-actions { display: flex; align-items: center; justify-content: space-between; font-weight: 900; margin-bottom: 12px; }
.preview-actions a { color: var(--red); text-decoration: none; }
#previewFrame { width: 100%; height: 620px; min-height: 360px; border: 0; background: #f1f2f3; border-radius: 20px; }
.send-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.send-box summary { cursor: pointer; display: inline-flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 158px; border: 1px solid var(--line); border-radius: 16px; background: #fff; padding: 12px 14px; font-weight: 800; color: var(--ink); list-style: none; box-shadow: 0 2px 10px rgba(20, 20, 20, .03); }
.send-box summary::-webkit-details-marker { display: none; }
.send-box summary span { display: inline-flex; align-items: center; gap: 8px; }
.send-box summary svg { width: 16px; height: 16px; }
.send-summary-chevron { transition: transform .16s ease; }
.send-box[open] .send-summary-chevron { transform: rotate(90deg); }
.send-box[open] summary { margin-bottom: 12px; }
.send-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.send-grid form { display: grid; gap: 8px; background: #fbfbfa; border: 1px solid var(--line); border-radius: 18px; padding: 12px; align-content: start; }
.send-grid form:last-child { grid-column: 1 / -1; }
.send-form-title { margin: 0; font-size: 14px; line-height: 1.2; }
.send-grid button { min-height: 42px; }
.scheduled-time { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 400; }
.scheduled-time svg { width: 15px; height: 15px; }

@keyframes focusPulse {
  0% { box-shadow: 0 0 0 0 rgba(var(--red-rgb), .4); border-color: var(--red); background: #fff6f5; }
  55% { box-shadow: 0 0 0 10px rgba(var(--red-rgb), 0); border-color: var(--red); background: #fff6f5; }
  100% { box-shadow: none; }
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .editor-layout, .grid.two, .send-grid { grid-template-columns: 1fr; }
  .editor-panel { position: relative; top: auto; max-height: none; }
  .preview-panel { min-height: auto; }
  #previewFrame { height: 760px; min-height: 760px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-links { grid-template-columns: repeat(2, 1fr); }
  .import-form { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main { padding: 16px; }
  .hero { padding: 24px; }
  .stats-grid { grid-template-columns: 1fr; }
  .quick-links { grid-template-columns: 1fr; }
  .inline-fields { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .sidebar { padding: 18px; }
  nav { grid-template-columns: 1fr 1fr; }
  .editor-panel, .preview-panel, .card { padding: 14px; border-radius: 20px; }
}
