:root {
  --bg: #f6f6f9;
  --panel: #ffffff;
  --panel-alt: #f0f0f7;
  --text: #27272f;
  --muted: #71717e;
  --line: #e1e1e8;
  --primary: #6246ea;
  --primary-dark: #4f35d3;
  --primary-soft: #eeebff;
  --success: #168a5b;
  --success-soft: #e5f7ef;
  --danger: #c83d4d;
  --danger-soft: #fdecef;
  --warning: #a96706;
  --warning-soft: #fff2d9;
  --shadow: 0 12px 35px rgba(34, 31, 53, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #ebe7ff, var(--bg) 54%); }
.login-card { width: min(420px, 100%); background: var(--panel); padding: 36px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.login-card h1 { margin: 16px 0 4px; font-size: 25px; }
.login-card p { margin: 0 0 28px; color: var(--muted); }
.login-card label { display: grid; gap: 7px; margin: 16px 0; font-weight: 600; font-size: 14px; }
.login-card .button { width: 100%; margin-top: 10px; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 13px; background: var(--primary); color: #fff; font-weight: 800; letter-spacing: -.04em; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: #202026; color: #fff; padding: 20px 14px; }
.brand { display: flex; gap: 11px; align-items: center; color: #fff; text-decoration: none; padding: 0 8px 22px; }
.brand strong, .brand small { display: block; }
.brand small { color: #aaa9b5; margin-top: 2px; font-size: 11px; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 11px; color: #d8d7df; padding: 11px 12px; text-decoration: none; border-radius: 8px; font-size: 14px; }
.nav a span { width: 20px; text-align: center; font-size: 17px; }
.nav a:hover { background: #2d2d35; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav-caption { color: #7f7e89; text-transform: uppercase; font-weight: 700; font-size: 10px; letter-spacing: .09em; padding: 22px 12px 7px; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 10px 4px; border-top: 1px solid #37373f; color: #c8c7cf; font-size: 12px; }
.link-button { border: 0; background: none; color: #b9abff; cursor: pointer; padding: 4px; }

.main { min-width: 0; }
.topbar { min-height: 91px; display: flex; align-items: center; gap: 16px; padding: 20px 32px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; }
.content { padding: 28px 32px 50px; max-width: 1500px; width: 100%; }

.button { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 9px 14px; border-radius: 7px; cursor: pointer; font-weight: 650; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; }
.button:hover { border-color: #b9b7c4; }
.button.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.danger { color: var(--danger); border-color: #efbcc3; background: #fff; }
.button.small { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.button:disabled { opacity: .55; cursor: wait; }
.icon-button { border: 0; background: transparent; cursor: pointer; border-radius: 6px; font-size: 22px; padding: 5px 8px; }
.icon-button:hover { background: var(--panel-alt); }
.mobile-only { display: none; }

.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 4px rgba(32,32,38,.02); }
.stat-card { padding: 19px; }
.stat-card small { color: var(--muted); font-weight: 600; }
.stat-card strong { display: block; font-size: 28px; margin-top: 9px; }
.stat-card .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.card { overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 19px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; font-size: 16px; }
.card-body { padding: 19px; }
.section-gap { margin-top: 22px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty strong { color: var(--text); display: block; margin-bottom: 7px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 11px 14px; color: var(--muted); background: #fafafd; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #faf9ff; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 700; background: var(--panel-alt); color: var(--muted); white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
label.field small { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; border: 1px solid #d8d7df; background: #fff; border-radius: 7px; padding: 9px 11px; color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 95px; resize: vertical; }
input[readonly] { background: #f7f7fa; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 13px; }
.checkbox input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; padding-top: 17px; border-top: 1px solid var(--line); }
.form-error { color: var(--danger); font-size: 12px; min-height: 17px; margin-top: 8px; }
.help { padding: 12px 14px; border-radius: 8px; background: var(--primary-soft); color: #4d3c9e; font-size: 13px; line-height: 1.5; }
.code-line { display: flex; align-items: center; gap: 8px; }
.code-line code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #f4f3f8; border: 1px solid var(--line); padding: 8px 10px; border-radius: 6px; font-size: 12px; }
pre.json { margin: 0; max-height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word; border-radius: 7px; background: #202026; color: #e7e6ed; padding: 16px; font-size: 12px; line-height: 1.5; }

.mapping-list { display: grid; gap: 10px; }
.mapping-row { display: grid; grid-template-columns: 1.1fr .75fr 1.4fr auto; gap: 8px; align-items: end; border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: #fafafd; }
.mapping-row label { font-size: 11px; color: var(--muted); font-weight: 700; display: grid; gap: 4px; }

.modal { width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 40px); border: 0; padding: 0; border-radius: 12px; box-shadow: 0 25px 70px rgba(20,18,32,.28); }
.modal::backdrop { background: rgba(20,18,32,.53); backdrop-filter: blur(2px); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; background: #fff; border-bottom: 1px solid var(--line); padding: 18px 22px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.modal-body { padding: 22px; }

.toast-root { position: fixed; z-index: 100; right: 18px; top: 18px; display: grid; gap: 8px; }
.toast { width: min(390px, calc(100vw - 36px)); padding: 12px 14px; border-radius: 8px; background: #27272f; color: #fff; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .18s ease-out; }
.toast.error { background: #a93040; }
.toast.success { background: #177b55; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters label { min-width: 190px; font-size: 11px; color: var(--muted); font-weight: 700; display: grid; gap: 5px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.detail-list { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 9px 14px; font-size: 13px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; word-break: break-word; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mapping-row { grid-template-columns: 1fr 1fr; }
  .mapping-row .remove-cell { grid-column: 2; justify-self: end; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; left: -260px; width: 245px; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 20px 0 60px rgba(0,0,0,.24); }
  .mobile-only { display: inline-block; }
  .topbar { padding: 16px; min-height: 76px; }
  .topbar h1 { font-size: 21px; }
  .content { padding: 18px 14px 40px; }
  .stats-grid, .form-grid, .two-columns { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .page-actions .button span.optional { display: none; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list dt { margin-top: 8px; }
}

/* Simplified landing routing */
.route-builder { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) auto minmax(0,1fr) auto minmax(0,1fr); gap: 14px; align-items: end; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(135deg,#fbfaff,#f6f8ff); }
.route-arrow { align-self: center; color: var(--primary); font-size: 24px; font-weight: 800; padding-top: 18px; }
.route-step { display: inline-grid; place-items: center; width: 23px; height: 23px; margin-right: 5px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 11px; }
.destination-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fafafd; }
.destination-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.destination-head .muted { font-size: 12px; margin-top: 4px; }
.destination-card #google-settings { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.switch { display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: relative; width: 44px; height: 24px; border-radius: 999px; background: #c8c7d0; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Submission analytics */
.chart-scroll { width: 100%; overflow-x: auto; }
.submission-chart { display: block; width: 100%; min-width: 720px; height: auto; }
.chart-grid { stroke: #e7e6ed; stroke-width: 1; }
.chart-axis { fill: #83818e; font-size: 11px; font-family: inherit; }
.chart-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-line-1 { stroke: #6c50eb; fill: #6c50eb; }
.chart-line-2 { stroke: #16845b; fill: #16845b; }
.chart-line-3 { stroke: #d06d2f; fill: #d06d2f; }
.chart-line-4 { stroke: #3281c4; fill: #3281c4; }
.chart-line-5 { stroke: #c34975; fill: #c34975; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

@media (max-width: 900px) {
  .route-builder { grid-template-columns: 1fr; }
  .route-arrow { transform: rotate(90deg); justify-self: center; padding: 0; }
}
.chart-line.chart-line-1,.chart-line.chart-line-2,.chart-line.chart-line-3,.chart-line.chart-line-4,.chart-line.chart-line-5{fill:none}

/* Tilda → amoCRM field mapping */
.compact-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mapping-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.mapping-table { min-width: 760px; }
.mapping-table th { background: #f6f5fa; }
.mapping-table td { padding: 9px; }
.mapping-table input, .mapping-table select { min-width: 170px; }
.mapping-table td:last-child { width: 48px; text-align: center; }
.icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; font-size: 20px; }
.icon-button.danger { color: var(--danger); }
.icon-button:hover { background: var(--danger-soft); }
@media (max-width: 1050px) { .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .compact-grid { grid-template-columns: 1fr; } }
