:root {
  --blue: #0f5195;
  --blue-dark: #0a3d73;
  --sky: #75b7e1;
  --sky-light: #c4dfef;
  --orange: #f89622;
  --bg: #f0f2f4;
  --text: #252321;
  --muted: #5b6673;
  --white: #fff;
  --red: #b42318;
  --green: #157347;
  --border: 1px solid rgba(117, 183, 225, 0.38);
  --shadow: 0 16px 48px rgba(15, 81, 149, 0.1);
  --radius-sm: 14px;
  --radius-md: 22px;
  --radius-lg: 30px;
  --pill: 999px;
  --font: 'Manrope', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.55; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); }
[hidden] { display: none !important; }

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(circle at 8% 10%, rgba(117, 183, 225, 0.18), transparent 25%),
    radial-gradient(circle at 92% 84%, rgba(196, 223, 239, 0.55), transparent 28%);
}

.topbar {
  min-height: 82px;
  padding: 12px clamp(18px, 4vw, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--blue); text-decoration: none; }
.brand > span:last-child { display: grid; }
.brand b { font-size: 19px; font-weight: 800; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark {
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  border-radius: 16px 16px 16px 4px;
  background: var(--orange);
  color: var(--white);
  font-size: 25px;
  font-weight: 800;
  transform: rotate(-3deg);
  box-shadow: 0 8px 22px rgba(248, 150, 34, 0.25);
}
.large-mark { width: 70px; height: 70px; font-size: 34px; }
.status-pill, .mode-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: var(--pill); background: #e7f3eb; color: var(--green); font-size: 13px; font-weight: 700; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 5px rgba(21, 115, 71, 0.1); }
.mode-pill { background: #fff3e1; color: #9a5900; }
.mode-pill.live { background: #e7f3eb; color: var(--green); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.setup-shell { width: min(1180px, calc(100% - 36px)); margin: 54px auto; display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 44px; align-items: start; }
.setup-intro { padding: 30px 10px; }
.setup-intro h1, .page-heading h1, .login-card h1 { margin: 8px 0 14px; color: var(--blue); font-size: clamp(32px, 4.5vw, 58px); line-height: 1.06; letter-spacing: -0.04em; }
.setup-intro > p { max-width: 620px; color: var(--muted); font-size: 18px; }
.eyebrow { display: block; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.route-line { margin: 32px 0; display: flex; align-items: center; gap: 10px; color: var(--blue); font-size: 12px; font-weight: 800; }
.route-line i { flex: 1; min-width: 28px; border-top: 2px dashed var(--sky); position: relative; }
.route-line i::after { content: ''; position: absolute; right: -2px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }
.info-stack { display: grid; gap: 12px; }
.info-stack article { padding: 18px 20px; display: grid; gap: 4px; border: var(--border); border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.66); }
.info-stack strong { color: var(--blue); }
.info-stack span { color: var(--muted); font-size: 14px; }

.panel { background: var(--white); border: var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.setup-panel { padding: clamp(24px, 4vw, 46px); }
.setup-panel h2, .settings-card h2, .compact-panel h2, .lead-dialog h2 { margin: 5px 0 18px; color: var(--blue); font-size: clamp(23px, 3vw, 32px); line-height: 1.15; }
.state-box { min-height: 280px; padding: 36px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.state-box h1, .state-box h2 { margin: 5px 0; color: var(--blue); }
.state-box p { color: var(--muted); }
.state-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: #e7f3eb; color: var(--green); font-size: 25px; font-weight: 800; }
.error-icon { background: #feeceb; color: var(--red); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--sky-light); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 7px; margin: 18px 0; }
.field > span, .compact-field > span { color: var(--blue-dark); font-size: 13px; font-weight: 800; }
.field small { color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea, .compact-field select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #c7d8e5;
  border-radius: var(--radius-sm);
  background: #fbfdff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .compact-field select:focus { border-color: var(--sky); background: var(--white); box-shadow: 0 0 0 4px rgba(117, 183, 225, 0.18); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-grid-3 { display: grid; grid-template-columns: 1.5fr .7fr 1fr; gap: 16px; align-items: end; }
.checkbox-field { min-height: 48px; display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; font-weight: 600; }
.checkbox-field input { width: 19px; height: 19px; accent-color: var(--blue); }
.button, .secondary-button, .text-button, .icon-button, .nav-button { border: 0; cursor: pointer; }
.button { min-height: 48px; padding: 12px 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--pill); background: var(--orange); color: var(--white); font-weight: 800; text-decoration: none; box-shadow: 0 10px 24px rgba(248, 150, 34, 0.25); }
.button:hover { background: #e98715; }
.button:disabled, .secondary-button:disabled { opacity: .55; cursor: wait; }
.full-width { width: 100%; }
.secondary-button { min-height: 42px; padding: 9px 17px; border: 1px solid var(--sky-light); border-radius: var(--pill); background: #edf7fd; color: var(--blue); font-weight: 800; }
.secondary-button:hover { background: #dceefa; }
.text-button { min-height: 40px; padding: 8px 10px; background: transparent; color: var(--blue); font-weight: 800; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #edf7fd; color: var(--blue); font-size: 22px; }
.fine-print { margin: 14px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.form-message { margin: 14px 0; padding: 12px 15px; border-radius: var(--radius-sm); font-weight: 700; }
.error-message { color: var(--red); background: #feeceb; border: 1px solid #fac9c5; }
.success-message { color: var(--green); background: #e7f3eb; border: 1px solid #b9dfc7; }
.error-text { color: var(--red) !important; }
.good-text { color: var(--green) !important; }
.muted-link { display: block; margin-top: 18px; color: var(--muted); text-align: center; font-size: 13px; }

.login-shell { min-height: calc(100vh - 82px); display: grid; place-items: center; padding: 30px 18px; }
.login-card { width: min(460px, 100%); padding: 38px; }
.login-card h1 { font-size: 36px; }
.login-card > p { color: var(--muted); }
.admin-shell { min-height: calc(100vh - 82px); display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { padding: 28px 18px; display: flex; flex-direction: column; gap: 8px; background: #fff; border-right: var(--border); }
.nav-button { width: 100%; min-height: 48px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; border-radius: 14px; background: transparent; color: var(--muted); text-align: left; font-weight: 700; }
.nav-button span { width: 26px; color: var(--sky); text-align: center; }
.nav-button:hover { background: #f1f7fb; color: var(--blue); }
.nav-button.active { background: var(--blue); color: var(--white); box-shadow: 0 10px 25px rgba(15, 81, 149, 0.2); }
.nav-button.active span { color: var(--orange); }
.sidebar-note { margin-top: auto; padding: 18px; display: grid; gap: 6px; border-radius: 18px; background: #edf7fd; color: var(--blue); }
.sidebar-note span { color: var(--muted); font-size: 12px; }
.admin-content { min-width: 0; padding: clamp(24px, 4vw, 54px); }
.view-section { max-width: 1320px; margin: 0 auto; }
.page-heading { margin-bottom: 28px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.page-heading h1 { margin-bottom: 7px; font-size: clamp(34px, 4vw, 52px); }
.page-heading p { margin: 0; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card { padding: 22px; display: grid; gap: 3px; border: var(--border); border-radius: var(--radius-md); background: var(--white); box-shadow: 0 8px 28px rgba(15, 81, 149, 0.06); }
.metric-card span { color: var(--blue); font-size: 13px; font-weight: 800; }
.metric-card strong { color: var(--blue-dark); font-size: 38px; line-height: 1.15; }
.metric-card small { color: var(--muted); }
.warning-card strong { color: var(--orange); }
.content-grid { margin-top: 20px; display: grid; grid-template-columns: 1.4fr .8fr; gap: 20px; }
.compact-panel, .settings-card, .table-panel { padding: 24px; }
.panel-heading { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-heading > div { display: flex; align-items: center; gap: 12px; }
.panel-heading > div:has(.eyebrow) { display: block; }
.panel-heading h2 { margin: 4px 0; font-size: 24px; }
.lead-list { display: grid; }
.lead-row { width: 100%; padding: 14px 4px; display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 12px; border: 0; border-bottom: 1px solid #e5edf3; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.lead-row:hover { background: #f8fbfd; }
.lead-row span:nth-child(2) { display: grid; }
.lead-row small { color: var(--muted); }
.lead-row strong { color: var(--blue); }
.lead-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--sky); }
.lead-dot.delivered, .lead-dot.sent { background: var(--green); }
.lead-dot.failed { background: var(--red); }
.lead-dot.partial { background: var(--orange); }
.channel-list, .delivery-list { display: grid; gap: 12px; }
.channel-list article, .delivery-list article { padding: 14px; display: flex; align-items: center; gap: 12px; border-radius: 16px; background: #f7fafc; }
.channel-list article > div, .delivery-list article > div { min-width: 0; display: grid; }
.channel-list small, .delivery-list small { color: var(--muted); overflow-wrap: anywhere; }
.channel-icon { flex: 0 0 42px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--sky-light); color: var(--blue); font-size: 13px; font-weight: 800; }
.empty-state { min-height: 110px; padding: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); text-align: center; }

.table-panel { overflow: hidden; }
.filter-row { margin-bottom: 16px; display: flex; gap: 12px; }
.compact-field { min-width: 190px; display: grid; gap: 5px; }
.compact-field select { min-height: 42px; }
.table-scroll { overflow-x: auto; }
.lead-table { width: 100%; min-width: 780px; border-collapse: collapse; }
.lead-table th, .lead-table td { padding: 14px 12px; border-bottom: 1px solid #e3ebf1; text-align: left; vertical-align: middle; }
.lead-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.lead-table td { font-size: 14px; }
.lead-status { display: inline-flex; padding: 5px 9px; border-radius: var(--pill); background: #e8f2f8; color: var(--blue); font-size: 11px; font-weight: 800; white-space: nowrap; }
.lead-status.delivered, .lead-status.sent { background: #e7f3eb; color: var(--green); }
.lead-status.failed { background: #feeceb; color: var(--red); }
.lead-status.partial { background: #fff3e1; color: #9a5900; }

#settingsForm { display: grid; gap: 20px; padding-bottom: 90px; }
.settings-card { box-shadow: 0 10px 34px rgba(15, 81, 149, 0.06); }
.step-badge { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 12px; background: var(--blue); color: var(--white); font-weight: 800; }
.hint { padding: 6px 10px; border-radius: var(--pill); background: #edf7fd; color: var(--blue); font-size: 12px; font-weight: 700; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--blue); font-size: 13px; font-weight: 800; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { width: 42px; height: 24px; padding: 3px; display: flex; border-radius: var(--pill); background: #c8d4dc; transition: background .15s; }
.switch > span::after { content: ''; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.15); transition: transform .15s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(18px); }
.inline-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.inline-status { color: var(--muted); font-size: 13px; }
.site-settings { display: grid; gap: 14px; }
.site-card { padding: 18px; border: 1px solid #d6e4ed; border-radius: 20px; background: #f9fcfe; }
.site-card-head { display: flex; align-items: center; justify-content: space-between; color: var(--blue); }
.secret-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.site-options { display: flex; flex-wrap: wrap; gap: 22px; }
.site-options .checkbox-field { min-height: auto; }
.sticky-save { position: sticky; bottom: 18px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid rgba(117, 183, 225, .5); border-radius: 22px; background: rgba(255,255,255,.96); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.sticky-save span { color: var(--muted); font-size: 13px; }

.lead-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--text); box-shadow: 0 30px 90px rgba(10, 61, 115, .3); overflow: auto; }
.lead-dialog::backdrop { background: rgba(10, 45, 76, .46); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; z-index: 2; padding: 24px 26px 16px; display: flex; justify-content: space-between; background: #fff; border-bottom: 1px solid #e6edf2; }
.dialog-head h2 { margin-bottom: 0; }
#leadDetails { padding: 22px 26px; }
#leadDetails h3 { color: var(--blue); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-grid > div { padding: 12px 14px; display: grid; gap: 3px; border-radius: 14px; background: #f5f9fc; }
.detail-grid span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.detail-grid b { overflow-wrap: anywhere; white-space: pre-wrap; }
.delivery-list .lead-status { margin-left: auto; }
.dialog-actions { position: sticky; bottom: 0; padding: 16px 26px 22px; display: flex; justify-content: flex-end; gap: 10px; background: #fff; border-top: 1px solid #e6edf2; }
.danger-button { min-height: 44px; padding: 10px 16px; border: 1px solid #c7443e; border-radius: 14px; background: #fff; color: #a52e29; font-weight: 800; cursor: pointer; }
.danger-button:hover { background: #fff1f0; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: min(420px, calc(100% - 44px)); padding: 14px 18px; border-radius: 16px; background: var(--blue); color: #fff; font-weight: 700; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }
.center-page { display: grid; place-items: center; padding: 20px; }
.center-page .panel { width: min(480px, 100%); }

@media (max-width: 1050px) {
  .setup-shell { grid-template-columns: 1fr; max-width: 760px; }
  .setup-intro { padding-bottom: 0; }
  .admin-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .nav-button { justify-content: center; }
  .nav-button span { width: auto; }
  .nav-button { font-size: 0; }
  .nav-button span { font-size: 18px; }
  .sidebar-note { display: none; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { min-height: 70px; padding: 10px 14px; }
  .brand small { display: none; }
  .brand-mark { width: 43px; height: 43px; }
  .status-pill { display: none; }
  .mode-pill { max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .setup-shell { width: min(100% - 24px, 620px); margin: 24px auto 40px; gap: 18px; }
  .setup-intro { padding: 8px 4px; }
  .setup-intro h1 { font-size: 38px; }
  .setup-intro > p { font-size: 16px; }
  .route-line { align-items: flex-start; }
  .field-row, .field-grid-3 { grid-template-columns: 1fr; gap: 0; }
  .admin-shell { display: block; padding-bottom: 74px; }
  .sidebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: 66px; padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, 1fr); border: 0; border-top: var(--border); box-shadow: 0 -8px 24px rgba(15, 81, 149, .1); }
  .nav-button { min-height: 50px; display: grid; place-items: center; gap: 0; font-size: 10px; }
  .nav-button span { font-size: 16px; }
  .admin-content { padding: 24px 12px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 38px; }
  .page-heading p { font-size: 14px; }
  .metric-grid { gap: 10px; }
  .metric-card { padding: 16px; }
  .metric-card strong { font-size: 30px; }
  .compact-panel, .settings-card, .table-panel { padding: 18px 14px; border-radius: 22px; }
  .panel-heading { align-items: flex-start; }
  .panel-heading > div { align-items: flex-start; }
  .panel-heading h2 { font-size: 21px; }
  .lead-row { grid-template-columns: 10px minmax(0, 1fr); }
  .lead-row > strong { grid-column: 2; }
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; }
  .compact-field { min-width: 0; }
  .inline-actions { align-items: stretch; }
  .inline-actions .secondary-button { flex: 1 1 100%; }
  .sticky-save { bottom: 78px; align-items: stretch; flex-direction: column; }
  .sticky-save .button { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions > * { width: 100%; }
}

@media (max-width: 430px) {
  .topbar-actions .text-button { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card span { font-size: 11px; }
  .filter-row { grid-template-columns: 1fr; }
  .site-options { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
