:root {
  --primary: #2563eb;
  --secondary: #14b8a6;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --bg: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --topbar-bg: rgba(255, 255, 255, .92);
  --hero-bg: radial-gradient(circle at top left, #dbeafe, transparent 35%), linear-gradient(135deg, #fff, #f8fafc);
  --app-bg: #eef2f7;
  --soft-bg: #f1f5f9;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
}

body[data-theme="dark"] {
  --bg: #08111f;
  --text: #e5eefb;
  --muted: #9fb0c7;
  --border: #243244;
  --card: #111c2d;
  --shadow: 0 18px 45px rgba(0, 0, 0, .34);
  --topbar-bg: rgba(8, 17, 31, .92);
  --hero-bg: radial-gradient(circle at top left, rgba(37, 99, 235, .35), transparent 35%), linear-gradient(135deg, #08111f, #0f172a);
  --app-bg: #08111f;
  --soft-bg: #172235;
  --sidebar-bg: #050b16;
  --sidebar-text: #d7e3f5;
  --sidebar-active: #172235;
}

* {
  box-sizing: border-box;
  scroll-behavior: auto !important;
  overflow-anchor: none !important;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: auto !important;
  overflow-anchor: none !important;
}

/* Notification System */
#notification-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 400px;
  background: var(--card);
  color: var(--text);
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
  animation: toast-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), toast-out 0.4s 4.6s forwards;
  position: relative;
  overflow: hidden;
}

.toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.toast.success::before { background: var(--success); }
.toast.error::before { background: var(--danger); }
.toast.info::before { background: var(--primary); }

.toast.success { border-left: none; }
.toast.error { border-left: none; }
.toast.info { border-left: none; }

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(120%); opacity: 0; }
}

a {
  color: inherit;
  text-decoration: none;
}

input,
button {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 6vw;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.brand span {
  color: var(--primary);
}

.public-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  color: #334155;
}

.public-nav .btn-light {
  margin-left: 18px;
  margin-right: 18px;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--soft-bg);
}

.lang-btn {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  transition: .2s;
}

.lang-btn.active,
.lang-btn:hover {
  background: var(--card);
  color: var(--primary);
  box-shadow: 0 6px 16px rgba(15, 23, 42, .08);
}

.public-nav a {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 10px;
  padding: 10px 12px;
  transition: transform .2s, box-shadow .2s, background .2s;
}

.public-nav a::after {
  content: "";
  position: absolute;
  inset: -45%;
  z-index: -1;
  background: radial-gradient(circle, rgba(255, 255, 255, .96) 0%, rgba(37, 99, 235, .2) 30%, rgba(255, 255, 255, 0) 66%);
  opacity: 0;
  transform: scale(.35);
  transition: opacity .28s ease, transform .28s ease;
  pointer-events: none;
}

.public-nav a:active::after {
  opacity: 1;
  transform: scale(1);
}

.public-nav a:active {
  transform: scale(.97);
  background: rgba(255, 255, 255, .74);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .75), 0 8px 28px rgba(15, 23, 42, .14);
}

.btn {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s, background .2s;
}

.btn::after,
.nav-item::after {
  content: "";
  position: absolute;
  inset: -45%;
  z-index: -1;
  background: radial-gradient(circle, rgba(255, 255, 255, .95) 0%, rgba(255, 255, 255, .5) 24%, rgba(255, 255, 255, 0) 62%);
  opacity: 0;
  transform: scale(.35);
  transition: opacity .28s ease, transform .28s ease;
  pointer-events: none;
}

.btn:active::after,
.nav-item:active::after {
  opacity: 1;
  transform: scale(1);
}

.btn:active,
.nav-item:active {
  transform: scale(.97);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55), 0 8px 28px rgba(15, 23, 42, .18);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, .24);
}

.btn-primary:hover {
  transform: translateY(-1px);
  background: #1d4ed8;
}

.btn-outline {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.btn-light {
  background: #eff6ff;
  color: var(--primary);
}

.theme-toggle {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  transition: transform .2s, box-shadow .2s, background .2s;
}

.theme-toggle::after {
  content: "";
  position: absolute;
  inset: -45%;
  z-index: -1;
  background: radial-gradient(circle, rgba(255, 255, 255, .96) 0%, rgba(37, 99, 235, .2) 30%, rgba(255, 255, 255, 0) 66%);
  opacity: 0;
  transform: scale(.35);
  transition: opacity .28s ease, transform .28s ease;
}

.theme-toggle:active::after {
  opacity: 1;
  transform: scale(1);
}

.theme-toggle:active {
  transform: scale(.97);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55), 0 8px 28px rgba(15, 23, 42, .18);
}

.public-page {
  display: block;
}

.hero {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: 46px;
  align-items: center;
  padding: 78px 6vw 52px;
  min-height: 680px;
  background: var(--hero-bg);
}

.eyebrow {
  display: inline-flex;
  color: var(--primary);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 10px;
}

.hero h1 {
  font-size: clamp(40px, 5vw, 70px);
  line-height: .96;
  letter-spacing: -0.07em;
  margin: 0 0 22px;
}

.hero p {
  font-size: 19px;
  line-height: 1.7;
  color: var(--muted);
  max-width: 650px;
}

.hero-actions {
  display: flex;
  gap: 14px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.hero-preview {
  display: grid;
  gap: 18px;
  padding: 0.5cm;
}

.preview-card,
.metric,
.price-card,
.feature-card,
.integration-panel,
.cta-box,
.login-card,
.dash-card,
.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.preview-card.large {
  padding: 0.7cm;
  min-height: 370px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 0;
  padding: 0 0.2cm;
}

.preview-header b {
  min-width: 0;
  line-height: 1.35;
}

.preview-header span {
  color: var(--success);
  font-weight: 800;
  white-space: nowrap;
}

.chart-bars {
  max-height: 250px !important;
  overflow: hidden !important;

  height: 250px !important;
  display: flex;
  gap: 18px;
  align-items: end;
  padding: 0.5cm;
  background: var(--soft-bg);
  border-radius: 16px;
}

.chart-container-fixed {
  height: 350px !important;
  max-height: 350px !important;
  position: relative;
  overflow: hidden !important;
  width: 100%;
}

canvas {
  max-height: 100% !important;
  max-width: 100% !important;
}


.chart-bar-wrap {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  text-align: center;
}

.chart-bars i {
  display: block;
  width: 100%;
  background: linear-gradient(180deg, var(--primary), var(--secondary));
  border-radius: 14px 14px 0 0;
  box-shadow: 0 12px 24px rgba(37, 99, 235, .22);
}

.chart-bar-score {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.chart-bar-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.chart-note {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  padding: 0 0.2cm;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.metric {
  padding: 18px;
  text-align: center;
  display: grid;
  place-items: center;
  min-height: 94px;
}

.metric b {
  display: block;
  font-size: 26px;
}

.metric span {
  color: var(--muted);
}

.section {
  padding: 64px 6vw;
}

.section-title {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 34px;
}

.section-title h2,
.split h2,
.cta-box h2 {
  font-size: clamp(30px, 3vw, 46px);
  margin: 0;
  letter-spacing: -0.05em;
}

.card-grid,
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.feature-card,
.price-card {
  padding: 24px;
}

.feature-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: #eff6ff;
  color: var(--primary);
  font-size: 24px;
  margin-bottom: 16px;
}

.feature-card p,
.price-card p {
  color: var(--muted);
  line-height: 1.65;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  align-items: start;
}

.steps {
  display: grid;
  gap: 16px;
  padding-left: 22px;
}

.steps li {
  padding: 14px 0;
}

.steps span {
  display: block;
  color: var(--muted);
  margin-top: 5px;
}

.integration-panel {
  padding: 28px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chips span {
  padding: 10px 12px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-weight: 700;
}

.price-card.featured {
  border-color: var(--primary);
  transform: translateY(-8px);
}

.cta-box {
  text-align: center;
}

.demo-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 24px;
}

.demo-form input,
.login-card input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
}

.footer {
  padding: 24px 6vw;
  border-top: 1px solid var(--border);
  color: var(--muted);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.developer-button {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--soft-bg);
  color: var(--text);
  font-weight: 800;
  transition: transform .2s, box-shadow .2s, background .2s;
}

.developer-button::after {
  content: "";
  position: absolute;
  inset: -45%;
  z-index: -1;
  background: radial-gradient(circle, rgba(255, 255, 255, .96) 0%, rgba(37, 99, 235, .2) 30%, rgba(255, 255, 255, 0) 66%);
  opacity: 0;
  transform: scale(.35);
  transition: opacity .28s ease, transform .28s ease;
}

.developer-button:hover {
  background: var(--card);
  box-shadow: var(--shadow);
}

.developer-button:active {
  transform: scale(.97);
}

.app-shell {
  display: none;
  height: 100vh;
  overflow: hidden;
  background: var(--app-bg);
}

body.dashboard-active {
  overflow: hidden;
}

body.dashboard-active .public-page,
body.dashboard-active .topbar,
body.dashboard-active .footer {
  display: none;
}

body.dashboard-active .app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dashboard-active .app-shell.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  height: 100vh;
  padding: 22px;
  overflow-y: auto;
  position: relative;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease, width 0.3s ease;
  z-index: 100;
}

.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  padding: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-toggle-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: 0.2s;
  margin-right: 15px;
}

.sidebar-toggle-btn:hover {
  background: var(--soft-bg);
  color: var(--primary);
}

.side-brand {
  color: #fff;
  margin-bottom: 24px;
}

#sideNav {
  display: grid;
  gap: 6px;
}

.nav-item {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--sidebar-text);
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .2s, box-shadow .2s, background .2s;
}

.nav-item:hover,
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.dashboard-main {
  padding: 26px;
  overflow-y: auto;
  height: 100vh;
}

.dash-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 18px;
}

.dash-top h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.05em;
}

.dash-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);

  gap: 20px;
  margin-bottom: 30px;
}

.dash-card {
  padding: 18px;
  box-shadow: none;
  text-align: center;
}

.dash-card b {
  font-size: 26px;
  display: block;
  margin-bottom: 4px;
}

.dash-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1.35fr .65fr;
  gap: 18px;
}

.table-card {
  padding: 0;
  overflow: hidden;
  box-shadow: none;
}

.table-card h3,
.panel h3 {
  margin: 0;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
}

th,
td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: var(--soft-bg);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.status {
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.sent {
  background: #dcfce7;
  color: #166534;
}

.draft {
  background: #fef3c7;
  color: #92400e;
}

.scheduled {
  background: #dbeafe;
  color: #1d4ed8;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}

.panel-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.list-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.module-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
}

.module-card h3 {
  margin-top: 0;
}

.module-card ul { color: var(--muted); }
.builder-layout { display: grid; grid-template-columns: 220px 1fr 260px; gap: 16px; }
.builder-panel,
.builder-canvas {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
}

.email-block {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--soft-bg);
  font-weight: 700;
}

.email-preview {
  max-width: 540px;
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  background: var(--card);
}

.email-preview .banner {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  padding: 34px;
  text-align: center;
}

.email-preview .content {
  padding: 28px;
}

@media (max-width: 1050px) {

  .hero,
  .split,
  .dash-grid,
  body.dashboard-active .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .kpi-grid,
  .card-grid,
  .pricing-grid,
  .module-grid,
  .builder-layout {
    grid-template-columns: 1fr 1fr;
  }

  .demo-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .public-nav {
    display: none;
  }

  .hero {
    padding-top: 46px;
  }

  .preview-grid,
  .kpi-grid,
  .card-grid,
  .pricing-grid,
  .module-grid,
  .builder-layout,
  .demo-form {
    grid-template-columns: 1fr;
  }

  .dash-top {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
}

.toast {
  background: var(--card);
  color: var(--text);
  padding: 14px 20px;
  border-radius: 12px;
  border-left: 4px solid var(--primary);
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  font-weight: 600;
  font-size: 14px;
  animation: toastFadeIn 0.3s ease forwards, toastFadeOut 0.3s ease 2s forwards;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastFadeOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(10px) scale(0.95); }
}
/* Monthly Accordion Styles */
.month-accordion {
  margin-bottom: 12px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.month-header {
  padding: 16px 20px;
  background: var(--soft-bg);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: var(--text);
  transition: background 0.2s;
  user-select: none;
}

.month-header:hover {
  background: var(--border);
}

.month-header .arrow {
  transition: transform 0.3s;
  font-size: 12px;
  opacity: 0.6;
}

.month-accordion.active .month-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.month-accordion.active .month-header .arrow {
  transform: rotate(180deg);
}

.month-content {
  display: none;
}

.month-accordion.active .month-content {
  display: block;
}

.month-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.month-badge {
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

/* Advanced Email Builder Styles */
.builder-layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 20px;
  height: calc(100vh - 120px);
  overflow: hidden;
}

.builder-sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow-y: auto;
}

.builder-canvas-area {
  background: #f1f5f9;
  border-radius: 18px;
  padding: 20px 40px 40px 40px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  border: 2px dashed transparent;
  transition: border-color 0.3s;
}

.builder-canvas-area.drag-over {
  border-color: var(--primary);
  background: #e0e7ff;
}

.email-canvas {
  width: 100%;
  max-width: 600px;
  background: white;
  min-height: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.05);
  border-radius: 4px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.draggable-block {
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: grab;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: 0.2s;
}

.draggable-block:hover {
  background: white;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.canvas-block {
  position: relative;
  padding: 15px;
  border: 1px solid transparent;
  transition: 0.2s;
  cursor: pointer;
}

.canvas-block:hover {
  border: 1px dashed var(--primary);
  background: rgba(37, 99, 235, 0.02);
}

.canvas-block.selected {
  border: 2px solid var(--primary);
  background: rgba(37, 99, 235, 0.04);
}

.block-actions {
  position: absolute;
  top: -12px;
  right: 10px;
  display: none;
  gap: 5px;
  z-index: 10;
}

.canvas-block:hover .block-actions {
  display: flex;
}

.action-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 10px;
  cursor: pointer;
}

.action-btn.danger { background: var(--danger); }

.property-editor {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  overflow-y: auto;
}

.editor-group {
  margin-bottom: 20px;
}

.editor-group label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.editor-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--soft-bg);
  color: var(--text);
}

/* Template Gallery Styles */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.template-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.template-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.template-preview-box {
  height: 200px;
  background: var(--soft-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.template-preview-box iframe {
  width: 200%;
  height: 200%;
  border: none;
  transform: scale(0.5);
  transform-origin: top left;
  pointer-events: none;
}

.template-info {
  padding: 18px;
  flex-grow: 1;
}

.template-info h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.template-info p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.template-actions {
  display: flex;
  padding: 12px 18px;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--soft-bg);
}

.template-actions .btn {
  padding: 8px 12px;
  font-size: 12px;
  flex: 1;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 22px;
  color: var(--muted);
}

.empty-state i {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

/* Modal for Preview */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #fff;
  width: 90%;
  max-width: 900px;
  height: 80vh;
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  flex-grow: 1;
  background: #f8fafc;
}

.modal-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Landing Page Builder Styles */
body.builder-active {
  overflow: hidden;
}

.email-builder-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.builder-header {
  height: 70px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.builder-main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  overflow: hidden;
  background: #f1f5f9;
}

.builder-sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
}

.builder-sidebar h3 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
  letter-spacing: 0.05em;
}

.block-types {
  display: grid;
  gap: 12px;
}

.block-type {
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  cursor: grab;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: 0.2s;
}

.block-type:hover {
  background: white;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.block-type span {
  font-size: 20px;
}

.builder-canvas-wrap {
  overflow-y: auto;
  padding: 40px;
  display: flex;
  justify-content: center;
}

.builder-canvas {
  width: 100%;
  max-width: 900px;
  background: white;
  min-height: 100vh;
  box-shadow: 0 20px 50px rgba(0,0,0,0.1);
  border-radius: 8px;
  transition: 0.3s;
}

.canvas-block {
  position: relative;
  border: 2px solid transparent;
  transition: 0.2s;
  cursor: pointer;
}

.canvas-block:hover {
  border-color: rgba(37, 99, 235, 0.3);
}

.canvas-block.active-block {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.02);
}

.block-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  gap: 5px;
  background: var(--card);
  padding: 5px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border: 1px solid var(--border);
  z-index: 100;
}

.canvas-block:hover .block-controls {
  display: flex;
}

.block-controls button {
  background: transparent;
  border: none;
  padding: 5px 8px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
}

.block-controls button:hover {
  background: var(--soft-bg);
}

.builder-properties {
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 25px;
  overflow-y: auto;
}

.builder-properties h3 {
  font-size: 16px;
  margin-bottom: 25px;
}

[data-theme="dark"] .builder-main {
  background: #050b16;
}

[data-theme="dark"] .builder-canvas {
  background: #111c2d;
  color: #fff;
}

[data-theme="dark"] .builder-canvas p {
  color: #9fb0c7 !important;
}

/* Layered Canvas Styles */
.canvas-block.absolute { position: absolute !important; z-index: 10; cursor: move; border: 1px dashed transparent; transition: border 0.2s, box-shadow 0.2s; overflow: visible !important; }
.canvas-block.absolute.active-block { border: 2px solid var(--primary) !important; box-shadow: 0 0 20px rgba(37, 99, 235, 0.4); }
.resize-handle { position: absolute; width: 14px; height: 14px; background: var(--primary); border: 2px solid #fff; border-radius: 50%; bottom: -7px; right: -7px; cursor: nwse-resize; z-index: 1000; display: none; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.canvas-block.active-block .resize-handle { display: block; }
.canvas-block.absolute:hover { border-color: var(--primary); }
.builder-canvas { position: relative !important; overflow: hidden; }
.canvas-block .block-controls { position: absolute; top: -40px; right: 0; background: var(--card); padding: 5px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); display: none; gap: 5px; z-index: 1001; }
.canvas-block.active-block .block-controls { display: flex; }

.canvas-block .inner-image { cursor: grab; transition: transform 0.1s; transform-origin: center; }
.canvas-block .inner-image:active { cursor: grabbing; }

/* Animations */
@keyframes pulse-grow {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes glowing {
    0% { box-shadow: 0 0 5px rgba(37, 99, 235, 0.4); }
    50% { box-shadow: 0 0 20px rgba(37, 99, 235, 0.8); }
    100% { box-shadow: 0 0 5px rgba(37, 99, 235, 0.4); }
}

/* Premium Buttons */
.lp-btn-premium {
    display: inline-block !important;
    padding: 16px 40px !important;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    font-size: 18px !important;
    border-radius: 50px !important;
    border: none !important;
    cursor: pointer !important;
    text-decoration: none !important;
    transition: all 0.3s ease !important;
    animation: glowing 2s infinite !important;
    text-align: center !important;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3) !important;
}

.lp-btn-premium:hover {
    transform: translateY(-3px) scale(1.05) !important;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.5) !important;
}

/* Animated Title */
.animate-title {
    animation: pulse-grow 3s infinite ease-in-out;
    color: #1e293b;
    font-weight: 800;
    text-align: center;
}

.mf-form-container {
    background: #ffffff;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.05);
}

/* Builder Ruler & Center Guide System */
.builder-canvas-wrap {
  position: relative !important;
  overflow: auto !important;
  background: #f1f5f9 !important;
  padding-top: 40px !important;
}

.lp-ruler-h {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  font-size: 10px;
  color: var(--muted);
  background-image: linear-gradient(90deg, #e2e8f0 1px, transparent 1px);
  background-size: 50px 100%;
}

.lp-center-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  border-left: 2px dashed rgba(37, 99, 235, 0.4);
  z-index: 5;
  pointer-events: none;
}

.lp-center-label {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: bold;
  z-index: 101;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Automation Builder Styles */
.auto-node {
  position: absolute;
  width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  cursor: move;
  z-index: 10;
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.auto-node:hover {
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  border-color: var(--primary);
}

.auto-node.active-node {
  border: 2px solid var(--primary);
  box-shadow: 0 0 15px rgba(37, 99, 235, 0.3);
}

.node-header {
  padding: 10px 15px;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-header.trigger { background: #10b981; }
.node-header.action { background: #3b82f6; }
.node-header.logic { background: #f59e0b; }

.node-body {
  padding: 15px;
  font-size: 13px;
  color: var(--muted);
  min-height: 50px;
}

/* Simulation Animations */
@keyframes pulse-green {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.auto-node.node-running {
  border: 2px solid #10b981;
  animation: pulse-green 1.5s infinite;
  z-index: 100;
}

.auto-node.node-completed {
  border: 2px solid #3b82f6;
  opacity: 0.8;
}

.auto-node.node-completed::after {
  content: '✓';
  position: absolute;
  top: 5px;
  right: 5px;
  background: #10b981;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

.node-port {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid #94a3b8;
  background: white;
  border: 2px solid var(--primary);
  border-radius: 50%;
  position: absolute;
  cursor: crosshair;
  z-index: 10;
  transition: transform 0.2s, background 0.2s;
}

.node-port:hover {
  transform: scale(1.4);
  background: var(--primary);
}

.port-top { top: -6px; left: calc(50% - 6px); }
.port-bottom { bottom: -6px; left: calc(50% - 6px); }
.port-left { left: -6px; top: calc(50% - 6px); }
.port-right { right: -6px; top: calc(50% - 6px); }

.ghost-link {
  stroke: var(--primary);
  stroke-width: 2;
  stroke-dasharray: 5,5;
  fill: none;
  pointer-events: none;
}

.link-path {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 3;
  transition: stroke 0.2s, stroke-width 0.2s;
}

.link-path.link-running {
  stroke: #10b981;
  stroke-width: 5;
  stroke-dasharray: 10, 5;
  animation: dash-move 1s linear infinite;
}

@keyframes dash-move {
  to { stroke-dashoffset: -15; }
}

.link-path.selected-link {
  stroke: var(--primary);
  stroke-width: 5;
  filter: drop-shadow(0 0 5px rgba(37, 99, 235, 0.5));
}

.link-path:hover {
  stroke: var(--danger);
  stroke-width: 5;
}

/* Inbox Module Styles */
.inbox-item {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--card);
}

.inbox-item:hover {
  background: var(--soft-bg);
}

.inbox-item.unread {
  background: rgba(37, 99, 235, 0.05);
  border-left: 4px solid var(--primary);
}

.inbox-item.active {
  background: var(--soft-bg) !important;
  border-left: 4px solid var(--primary);
}

.unread-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}

/* Inbox & Chat Styles */
.inbox-item.active {
  background: #eff6ff !important;
  border-left: 4px solid var(--primary);
}

.inbox-item.unread {
  background: #fff9f0 !important;
}

.message-bubble {
  max-width: 80%;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  position: relative;
}

.message-bubble.outbound {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-bubble.inbound {
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Modal System */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  max-width: 90%;
  max-height: 90vh;
  overflow: hidden;
  animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}


/* Lightbox Modal */
.lightbox-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}

.lightbox-content {
  max-width: 90%;
  max-height: 90%;
  border-radius: 12px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
  animation: lightboxZoom 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

@keyframes lightboxZoom {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.lightbox-close {
  position: absolute;
  top: 30px;
  right: 40px;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s;
}

.lightbox-close:hover {
  transform: scale(1.1);
  color: var(--danger);
}

 @ m e d i a   ( m a x - w i d t h :   1 2 0 0 p x )   { 
     . k p i - g r i d   {   g r i d - t e m p l a t e - c o l u m n s :   r e p e a t ( 2 ,   1 f r ) ;   } 
 } 
 @ m e d i a   ( m a x - w i d t h :   6 0 0 p x )   { 
     . k p i - g r i d   {   g r i d - t e m p l a t e - c o l u m n s :   1 f r ;   } 
 } 
 
 

/* --- Mobile Responsive Sidebar Overlay & Table Scroll --- */
@media (max-width: 1050px) {
  body.dashboard-active .app-shell,
  .app-shell {
    grid-template-columns: 1fr !important;
  }

  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    height: 100vh !important;
    transform: translateX(0) !important;
    z-index: 1000 !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2) !important;
  }

  body.dashboard-active .app-shell.sidebar-collapsed .sidebar,
  .app-shell.sidebar-collapsed .sidebar {
    transform: translateX(-100%) !important;
    box-shadow: none !important;
  }

  .app-shell:not(.sidebar-collapsed)::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 999;
    transition: opacity 0.3s ease;
  }

  .sidebar-toggle-btn {
    display: flex !important;
  }

  .table-card {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .table-card table {
    min-width: 800px;
  }
}


/* --- Desktop Clickable Sidebar Divider Toggle --- */
.sidebar-divider-toggle {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 278px;
  width: 6px;
  background: rgba(0, 0, 0, 0.05);
  cursor: col-resize;
  z-index: 101;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s, width 0.2s;
  border-left: 1px solid var(--border);
}

.sidebar-divider-toggle:hover {
  background: var(--primary);
  width: 8px;
}

body[data-theme="dark"] .sidebar-divider-toggle {
  background: rgba(255, 255, 255, 0.05);
}

body[data-theme="dark"] .sidebar-divider-toggle:hover {
  background: var(--primary);
}

.sidebar-collapsed .sidebar-divider-toggle {
  left: 0;
}

@media (max-width: 1050px) {
  .sidebar-divider-toggle {
    display: none !important;
  }
}


/* --- Divider toggle button styling --- */
.divider-toggle-btn {
  position: absolute;
  top: 50px; /* Float near the top of the divider for easy reach */
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--card) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 102;
  transition: background 0.2s, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.2s;
  padding: 0;
  outline: none;
}

.divider-toggle-btn:hover {
  background: var(--soft-bg) !important;
  border-color: var(--primary) !important;
  color: var(--primary) !important;
}

.toggle-arrow {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-collapsed .toggle-arrow {
  transform: rotate(180deg);
}


/* ============================================
   COMPREHENSIVE MOBILE RESPONSIVE FIXES
   ============================================ */

/* Fix kpi-grid responsive (corrected) */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ---- Hamburger Button ---- */
.hamburger-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: 0.3s;
}

/* ---- Mobile Nav Overlay ---- */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  backdrop-filter: blur(3px);
}
.mobile-nav-overlay.open { display: block; }

.mobile-nav-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--card);
  z-index: 999;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 20px) + 90px);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
}
.mobile-nav-menu.open { transform: translateX(0); }

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.mobile-nav-brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  text-decoration: none;
}
.mobile-nav-brand span { color: var(--primary); }

.mobile-nav-close {
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text);
  line-height: 1;
}
.mobile-nav-link {
  display: block;
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  transition: background 0.2s;
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.mobile-nav-link:hover { background: var(--border); }
.mobile-nav-link.danger { color: var(--danger); border-color: var(--danger); }

.mobile-nav-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ---- Small screen public nav ---- */
@media (max-width: 768px) {
  .hamburger-btn { display: flex; }
  .public-nav { display: none !important; }

  .topbar { padding: 12px 16px; }

  /* Hero section */
  .hero {
    grid-template-columns: 1fr;
    padding: 32px 16px 28px;
    min-height: auto;
    gap: 28px;
  }
  .hero h1 { font-size: clamp(26px, 8vw, 40px); }
  .hero p { font-size: 16px; }
  .hero-actions { gap: 10px; }
  .hero-actions .btn { flex: 1; justify-content: center; }
  .hero-preview { padding: 0; }

  /* Sections */
  .section { padding: 36px 16px; }
  .card-grid, .pricing-grid { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }

  /* Footer */
  .footer {
    padding: 16px;
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
}

/* ---- Dashboard mobile fixes ---- */
@media (max-width: 1050px) {
  /* Dash top header */
  .dash-top {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .dash-top h1 { font-size: 22px !important; letter-spacing: -0.03em; }
  .dash-top .eyebrow { font-size: 11px; }

  /* Action buttons row */
  .dash-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .dash-actions .btn { font-size: 13px; padding: 9px 12px; }

  /* Main padding */
  .dashboard-main { padding: 14px; }

  /* Dash grid: single column */
  .dash-grid { grid-template-columns: 1fr; gap: 14px; }

  /* Module grid: 2 columns */
  .module-grid { grid-template-columns: 1fr 1fr; }

  /* Builder layout: stack */
  .builder-layout { grid-template-columns: 1fr !important; height: auto !important; }
  .builder-main { grid-template-columns: 1fr !important; }
  .builder-canvas-area { padding: 16px; }
  .builder-canvas-wrap { padding: 16px; }
  .property-editor { display: none; }
  .builder-properties { display: none; }

  /* Modal fix */
  .login-card {
    width: calc(100vw - 32px) !important;
    max-width: 480px !important;
  }

  /* System settings panel fix (super-admin) */
  #systemSettingsView {
    grid-template-columns: 1fr !important;
  }
  #systemSettingsView > section {
    grid-column: 1 / -1 !important;
  }

  /* Form grids in system settings */
  #smtpSettingsForm > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* ---- Very small screen (phones) ---- */
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .module-grid { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr 1fr; }

  /* Table scroll */
  th, td { padding: 10px 10px; font-size: 13px; }

  /* Toast position */
  #notification-container {
    top: 10px;
    right: 10px;
    left: 10px;
    align-items: stretch;
  }
  .toast { min-width: 0; max-width: 100%; }
  .toast-container { right: 10px; bottom: 10px; left: 10px; }

  /* Chips */
  .chips span { padding: 8px 10px; font-size: 13px; }

  /* Builder canvas area */
  .builder-canvas { min-height: 300px; }
}

/* ---- Touch device improvements ---- */
@media (hover: none) and (pointer: coarse) {
  .nav-item { padding: 16px 14px !important; min-height: 48px; }
  .btn { min-height: 44px; }
  /* Prevent iOS auto-zoom on input focus */
  input, select, textarea { font-size: 16px !important; }
  .lang-btn { padding: 10px 12px; }
  .sidebar-toggle-btn { padding: 12px; }
}

/* ---- Inbox two-pane layout mobile ---- */
@media (max-width: 768px) {
  div[style*="grid-template-columns: 340px"] {
    grid-template-columns: 1fr !important;
  }
}


/* =============================================
   INBOX / REPLIES - MOBILE RESPONSIVE
   ============================================= */

/* Mobile: show one panel at a time */
@media (max-width: 768px) {
  .inbox-wrapper {
    flex-direction: column !important;
    height: auto !important;
    min-height: calc(100vh - 130px);
    position: relative;
  }

  /* List panel */
  .inbox-wrapper #inbox-sidebar {
    width: 100% !important;
    flex-shrink: 0;
    display: flex !important;
    height: auto;
    max-height: calc(100vh - 130px);
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  /* Message panel */
  .inbox-wrapper #message-view {
    width: 100%;
    min-height: calc(100vh - 130px);
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  /* SHOW LIST state */
  .inbox-wrapper.inbox-show-list #inbox-sidebar {
    display: flex !important;
  }
  .inbox-wrapper.inbox-show-list #message-view {
    display: none !important;
  }

  /* SHOW CHAT state */
  .inbox-wrapper.inbox-show-chat #inbox-sidebar {
    display: none !important;
  }
  .inbox-wrapper.inbox-show-chat #message-view {
    display: flex !important;
    flex-direction: column;
  }

  /* Mobile back button */
  .inbox-back-btn {
    display: flex !important;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px 4px 0;
    margin-right: 8px;
    flex-shrink: 0;
  }

  /* Reply box improvements on mobile */
  #reply-box {
    font-size: 16px !important; /* Prevent iOS zoom on focus */
    min-height: 44px !important;
  }

  /* Emoji picker - reposition on mobile */
  #inbox-emoji-picker {
    bottom: 70px !important;
    right: 10px !important;
    left: 10px !important;
    grid-template-columns: repeat(6, 1fr) !important;
  }

  /* Message bubbles - max-width on mobile */
  .message-bubble {
    max-width: 85% !important;
  }

  /* Inbox item - larger touch target */
  .inbox-item {
    padding: 16px 18px !important;
    min-height: 60px;
  }
}

/* Desktop: always show both panels, hide back button */
@media (min-width: 769px) {
  .inbox-back-btn {
    display: none !important;
  }

  .inbox-wrapper #inbox-sidebar,
  .inbox-wrapper #message-view {
    display: flex !important;
  }
}

/* =============================================
   EMAIL BUILDER — PREVIEW TOGGLE & USE IN CAMPAIGN
   ============================================= */

/* Preview toolbar above canvas */
.builder-preview-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 30px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.preview-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.preview-toggle-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.preview-toggle-btn:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}

/* Desktop preview — full width (default) */
.builder-canvas-area {
  transition: padding 0.3s ease;
}

/* Phone preview — narrow canvas */
.builder-canvas-area.preview-phone {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #e5e7eb;
  padding: 24px 16px !important;
}

.builder-canvas-area.preview-phone .email-canvas {
  width: 375px !important;
  max-width: 375px !important;
  min-width: 375px !important;
  border-radius: 16px;
  box-shadow: 0 0 0 10px #1f2937, 0 0 0 12px #374151, 0 20px 40px rgba(0,0,0,0.4);
  overflow: hidden;
}

/* Desktop preview */
.builder-canvas-area.preview-desktop .email-canvas {
  width: 100% !important;
  max-width: 680px !important;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}

/* Use in Campaign button — green accent */
.btn-success {
  background: #16a34a;
  color: #fff;
  border: none;
}
.btn-success:hover {
  background: #15803d;
}

/* =============================================
   GLOBAL TABLE SCROLL + NAV BOTTOM PADDING FIXES
   ============================================= */

/* All tables inside any card/container scroll horizontally */
.table-card,
.dash-grid > section,
section.table-card {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ensure tables don't shrink below readable width */
table {
  min-width: 520px;
}

/* Inline-style table wrappers from app.js dynamic HTML */
[style*="overflow-x: auto"] table,
.month-content table {
  min-width: 600px;
}

/* Dashboard sidebar — last nav item must clear browser bottom bar */
.sidebar {
  padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 80px) !important;
}

/* Mobile hamburger nav drawer — last item must clear browser bottom bar */
.mobile-nav-menu {
  padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 100px) !important;
}

/* Super admin sidebar nav same fix */
.app-shell > .sidebar {
  padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 80px) !important;
}

/* Dashboard main content area — also needs safe area at bottom */
@media (max-width: 768px) {
  .dashboard-main {
    padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 20px) !important;
  }

  /* Prevent tables from causing page-level overflow */
  .dash-grid {
    overflow-x: hidden;
  }

  /* Each table section scrolls independently */
  .dash-grid > section,
  .table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
  }
}

/* =============================================
   CHART MOBILE SCROLL FIX
   ============================================= */

@media (max-width: 768px) {
  /* Allow charts to scroll horizontally on mobile */
  .chart-container-fixed {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    height: auto !important;
    max-height: none !important;
    min-height: 280px;
    padding-bottom: 8px;
  }

  /* Bar charts need min-width so bars are readable */
  .chart-container-fixed canvas {
    min-width: 500px !important;
    max-width: none !important;
    height: 280px !important;
  }

  /* Pie/Doughnut charts — no min-width needed, just shrink */
  .chart-container-fixed.chart-pie canvas,
  .chart-container-fixed.chart-doughnut canvas {
    min-width: unset !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 260px !important;
  }

  /* Super admin bar chart container */
  [style*="height: 400px"][style*="position: relative"] {
    height: auto !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 10px !important;
  }

  [style*="height: 400px"][style*="position: relative"] canvas {
    min-width: 500px !important;
    height: 280px !important;
  }

  /* Reports page chart sections */
  .dash-grid > section .chart-container-fixed {
    overflow-x: auto !important;
  }
}

/* Scrollbar styling for chart containers (visible on mobile) */
.chart-container-fixed::-webkit-scrollbar {
  height: 4px;
}
.chart-container-fixed::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 2px;
}
.chart-container-fixed::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
