:root {
  color-scheme: light;
  --bg: #f2f5fa;
  --surface: #ffffff;
  --surface-soft: #f7f9fd;
  --ink: #10213d;
  --muted: #6e7c93;
  --border: #dce5f2;
  --border-strong: #c9d7ea;
  --primary: #0763e8;
  --primary-dark: #0847a7;
  --primary-soft: #edf5ff;
  --green: #16834b;
  --green-soft: #e9f8ef;
  --amber: #bd7300;
  --amber-soft: #fff3dc;
  --red: #c84040;
  --red-soft: #fff0f0;
  --shadow: 0 16px 40px rgba(26, 60, 110, 0.08);
  --shadow-sm: 0 8px 24px rgba(26, 60, 110, 0.06);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 0 0, rgba(79, 136, 227, 0.08), transparent 30rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto 34px;
}

.hero {
  min-height: 150px;
  padding: 28px 32px;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 72% -30%, rgba(97, 183, 255, 0.55), transparent 24rem),
    linear-gradient(115deg, #082e69 0%, #075bd5 100%);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  box-shadow: 0 18px 44px rgba(0, 71, 170, 0.2);
}

.eyebrow {
  font-size: 11px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: 0.17em;
  opacity: 0.72;
}
.hero h1 {
  margin: 8px 0 6px;
  font-size: clamp(28px, 3vw, 47px);
  letter-spacing: -0.035em;
  line-height: 1.02;
}
.hero p { margin: 0; opacity: 0.78; font-size: 16px; }
.hero-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  background: rgba(1, 23, 63, 0.26);
  font-size: 12px;
  font-weight: 750;
  backdrop-filter: blur(12px);
}
.source-dot { width: 8px; height: 8px; border-radius: 50%; background: #ffc23e; box-shadow: 0 0 0 4px rgba(255,194,62,.14); }
.source-badge.live .source-dot { background: #4ee892; box-shadow: 0 0 0 4px rgba(78,232,146,.14); }
.source-badge.error .source-dot { background: #ff7676; box-shadow: 0 0 0 4px rgba(255,118,118,.14); }

.button {
  border: 0;
  border-radius: 10px;
  min-height: 38px;
  padding: 9px 15px;
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: wait; opacity: .55; transform: none; }
.button-light { background: white; color: #0a4ba7; box-shadow: 0 8px 22px rgba(1, 33, 88, .17); }
.button-primary { color: white; background: linear-gradient(180deg, #1171ef, #0757cf); box-shadow: 0 8px 18px rgba(7, 91, 218, .22); }
.button-secondary { background: var(--primary-soft); color: var(--primary); border: 1px solid #d7e8ff; }
.button-soft { min-height: 34px; padding: 7px 13px; background: #f2f7ff; color: var(--primary); border: 1px solid #d8e8ff; }
.button-soft.disabled { opacity: .45; pointer-events: none; }
.full-width { width: 100%; }

.warning-banner {
  margin-top: 14px;
  padding: 13px 16px;
  border: 1px solid #ffd78f;
  border-radius: 13px;
  background: #fff8e9;
  color: #784900;
  font-size: 13px;
  line-height: 1.45;
}

.period-bar {
  margin: 15px 0 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: #e8eef7; }
.segmented button { border: 0; background: transparent; color: #65748c; border-radius: 8px; padding: 7px 10px; font-size: 12px; font-weight: 800; }
.segmented button.active { background: white; color: var(--primary); box-shadow: 0 3px 10px rgba(47, 75, 116, .11); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 0 0 16px;
}
.stat-card {
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 750; }
.stat-card strong { font-size: clamp(25px, 2.4vw, 38px); letter-spacing: -0.035em; line-height: 1; }
.stat-card small { color: #8190a5; font-size: 11px; }

.workspace {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 350px);
  gap: 16px;
  align-items: center;
  padding: 17px 18px 14px;
  border-bottom: 1px solid #eaf0f7;
}
.filter-tabs {
  display: flex;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.filter-tabs button {
  white-space: nowrap;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #66758d;
  font-size: 12px;
  font-weight: 800;
  padding: 9px 12px;
}
.filter-tabs button.active { background: #eaf3ff; color: var(--primary); box-shadow: inset 0 0 0 1px #d3e6ff; }
.search-box {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-soft);
}
.search-box:focus-within { border-color: #8dbcf9; box-shadow: 0 0 0 3px rgba(0, 100, 232, .1); background: white; }
.search-box svg { width: 18px; height: 18px; fill: none; stroke: #8190a6; stroke-width: 2; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 12px;
}
.list-header h2 { margin: 0; font-size: 21px; letter-spacing: -0.025em; }
.list-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.cards-list { padding: 0 18px 18px; display: grid; gap: 12px; }
.lead-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 5px 18px rgba(35, 63, 100, .035);
}
.lead-main { min-width: 0; }
.lead-heading {
  min-height: 76px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 15px 17px;
  border-bottom: 1px solid #e9eff7;
}
.lead-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 8px;
  border-radius: 14px;
  background: linear-gradient(145deg, #7db6ff, #d7e9ff);
}
.lead-avatar span { display: block; width: 100%; height: 100%; border-radius: 50%; background: rgba(255,255,255,.9); box-shadow: inset 0 3px 7px rgba(61, 114, 183, .18); }
.lead-identity { min-width: 0; flex: 1; }
.name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lead-name { margin: 0; font-size: 17px; letter-spacing: -0.015em; }
.lead-title { margin: 5px 0 0; color: #69788f; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-id { color: #8290a4; font-size: 11px; align-self: flex-start; padding-top: 3px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 21px; padding: 3px 7px; border-radius: 999px; font-size: 9px; font-weight: 850; letter-spacing: .01em; }
.source-type { background: #eaf3ff; color: #1469d8; }
.stage-badge { background: var(--green-soft); color: var(--green); }
.stage-badge.warn { background: var(--amber-soft); color: var(--amber); }

.lead-section { padding: 14px 17px; border-bottom: 1px solid #edf1f7; }
.lead-section:last-child { border-bottom: 0; }
.section-label { display: block; margin-bottom: 6px; color: #8290a4; font-size: 9px; font-weight: 850; letter-spacing: .12em; }
.phone-section { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.lead-phone { display: block; font-size: 16px; letter-spacing: .01em; }
.quick-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.info-section { min-height: 115px; }
.lead-info { margin: 0; color: #46566e; font-size: 13px; line-height: 1.55; white-space: pre-wrap; }

.meeting-panel {
  padding: 15px 16px;
  background: #f7f9fd;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.meeting-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 1px; }
.meeting-state-label { font-size: 13px; }
.switch { position: relative; width: 39px; height: 23px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #b7c3d3; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 17px; height: 17px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 2px 6px rgba(27, 50, 80, .25); transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }
.field { display: grid; gap: 5px; color: #74839a; font-size: 10px; font-weight: 750; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #dbe4f1;
  border-radius: 9px;
  outline: 0;
  background: white;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  padding: 9px 10px;
  resize: vertical;
}
.field input, .field select { min-height: 37px; }
.field textarea { min-height: 74px; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #8dbcf9; box-shadow: 0 0 0 3px rgba(0, 100, 232, .08); }
.meeting-actions { margin-top: auto; display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.calendar-download { color: var(--primary); font-size: 11px; font-weight: 800; text-decoration: none; }

.empty-state { padding: 48px 20px 64px; text-align: center; color: var(--muted); }
.empty-state h3 { margin: 12px 0 4px; color: var(--ink); }
.empty-state p { margin: 0; }
.empty-icon { width: 48px; height: 48px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--green-soft); color: var(--green); font-size: 24px; font-weight: 900; }

.skeleton-card { height: 290px; border-radius: var(--radius-lg); background: linear-gradient(90deg, #f2f5fa 25%, #e9eef6 37%, #f2f5fa 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.app-footer { padding: 16px 4px 0; display: flex; justify-content: center; align-items: center; gap: 12px; color: #8190a5; font-size: 11px; }
.link-button { border: 0; background: transparent; padding: 0; color: var(--primary); font-weight: 800; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 24px;
  display: grid;
  place-items: center;
  background: rgba(8, 25, 54, .76);
  backdrop-filter: blur(12px);
}
.login-card {
  width: min(420px, 100%);
  padding: 30px;
  border-radius: 22px;
  background: white;
  box-shadow: 0 28px 80px rgba(0, 16, 45, .34);
}
.login-mark { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 19px; border-radius: 16px; color: white; font-weight: 900; font-size: 23px; background: linear-gradient(145deg, #0a3271, #0866e8); }
.login-card .eyebrow { color: var(--primary); opacity: 1; }
.login-card h2 { margin: 8px 0; font-size: 27px; letter-spacing: -0.035em; }
.login-card p { margin: 0 0 20px; color: var(--muted); line-height: 1.45; }
.login-card label { display: grid; gap: 7px; margin-bottom: 14px; color: #53637b; font-size: 12px; font-weight: 750; }
.login-card input { min-height: 46px; border: 1px solid var(--border-strong); border-radius: 11px; outline: 0; padding: 0 13px; }
.login-card input:focus { border-color: #79aff5; box-shadow: 0 0 0 4px rgba(0, 100, 232, .09); }
.form-error { min-height: 18px; margin-top: 12px; color: var(--red); font-size: 12px; line-height: 1.4; }

.toast-container { position: fixed; z-index: 120; right: 18px; bottom: 18px; display: grid; gap: 9px; width: min(360px, calc(100% - 36px)); }
.toast { padding: 13px 15px; border-radius: 12px; color: white; background: #17345f; box-shadow: 0 12px 35px rgba(7, 25, 54, .25); font-size: 12px; font-weight: 700; animation: toast-in .2s ease both; }
.toast.success { background: #167549; }
.toast.error { background: #b93737; }
@keyframes toast-in { from { opacity: 0; transform: translateY(9px); } }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-card { grid-template-columns: minmax(0, 1fr) 300px; }
  .toolbar { grid-template-columns: 1fr; }
  .search-box { max-width: none; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 16px, 680px); margin: 8px auto 22px; }
  .hero { min-height: 0; padding: 20px 18px; border-radius: 17px; display: block; }
  .hero h1 { font-size: 26px; }
  .hero p { font-size: 12px; line-height: 1.4; }
  .hero-actions { margin-top: 16px; justify-content: flex-start; }
  .source-badge { min-height: 32px; padding: 6px 10px; }
  .button-light { margin-left: auto; }
  .period-bar { justify-content: flex-start; overflow-x: auto; }
  .stats-grid { gap: 8px; }
  .stat-card { min-height: 93px; padding: 13px; border-radius: 13px; }
  .stat-card strong { font-size: 26px; }
  .stat-card small { font-size: 9px; line-height: 1.3; }
  .workspace { border-radius: 17px; }
  .toolbar { padding: 12px 10px 10px; gap: 10px; }
  .filter-tabs button { padding: 8px 9px; font-size: 10px; }
  .search-box { height: 39px; }
  .list-header { padding: 14px 12px 9px; }
  .list-header h2 { font-size: 17px; }
  .cards-list { padding: 0 8px 10px; gap: 9px; }
  .lead-card { display: block; border-radius: 13px; }
  .lead-heading { min-height: 0; padding: 12px; align-items: flex-start; }
  .lead-avatar { width: 35px; height: 35px; border-radius: 11px; padding: 7px; }
  .lead-name { font-size: 14px; }
  .lead-title { font-size: 10px; white-space: normal; }
  .lead-id { font-size: 8px; }
  .badge { min-height: 18px; font-size: 7px; padding: 2px 5px; }
  .lead-section { padding: 11px 12px; }
  .phone-section { align-items: flex-end; }
  .lead-phone { font-size: 13px; }
  .quick-actions { gap: 5px; }
  .button-soft { min-height: 29px; padding: 6px 10px; font-size: 9px; }
  .lead-info { font-size: 10px; line-height: 1.45; }
  .info-section { min-height: 0; }
  .meeting-panel { border-left: 0; border-top: 1px solid var(--border); padding: 12px; gap: 9px; }
  .field input, .field select { min-height: 34px; }
  .field textarea { min-height: 62px; }
  .meeting-actions .button { min-height: 34px; }
  .app-footer { flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .button-light { margin-left: 0; }
  .source-badge { justify-content: center; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .phone-section { display: block; }
  .quick-actions { margin-top: 9px; justify-content: stretch; }
  .quick-actions .button { flex: 1; }
}

/* v2 workspace additions */
.search-hero {
  margin: 14px 0 10px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: minmax(240px, .7fr) minmax(360px, 1.3fr);
  align-items: center;
  gap: 20px;
}
.search-copy { display: grid; gap: 3px; }
.search-copy strong { font-size: 17px; letter-spacing: -.02em; }
.search-copy span { color: var(--muted); font-size: 11px; line-height: 1.35; }
.search-box-large { height: 50px; background: #f4f8fe; }
.search-box-large input { font-size: 15px; }
.clear-search { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #dfe9f7; color: #53647c; font-size: 18px; line-height: 1; }
.stat-card-alert { border-color: #ffd6d6; background: linear-gradient(180deg, #fff, #fff9f9); }

.pipeline-section {
  padding: 17px 18px 12px;
  border-bottom: 1px solid #eaf0f7;
  background: linear-gradient(180deg, #fbfdff, #f7faff);
}
.toolbar-title { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 10px; }
.toolbar-title strong { font-size: 13px; }
.toolbar-title span { color: var(--muted); font-size: 11px; }
.funnel-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: thin; }
.funnel-tabs button {
  min-width: 165px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid #dce6f4;
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: #53647d;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 4px 13px rgba(36,72,120,.04);
}
.funnel-tabs button b {
  min-width: 25px;
  height: 25px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #edf3fb;
  color: #60738e;
  font-size: 11px;
}
.funnel-tabs button.active { border-color: #84b8fa; background: #edf5ff; color: var(--primary); }
.funnel-tabs button.active b { background: var(--primary); color: white; }
.work-filters { padding: 11px 18px; border-bottom: 1px solid #eaf0f7; }
.list-actions { display: flex; align-items: flex-end; gap: 10px; }
.sort-box { display: grid; gap: 3px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .04em; }
.sort-box select { min-height: 38px; border: 1px solid var(--border); border-radius: 9px; padding: 0 10px; background: white; color: var(--ink); font-size: 11px; font-weight: 700; }
.pipeline-badge { background: #eaf3ff; color: #1469d8; }
.closed-badge { background: #eef1f5; color: #66758c; }
.card-meta-row { margin-top: 7px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: #8290a4; font-size: 10px; }
.updated-at { color: #9aa6b6; }
.avatar-letter { width: 100%; height: 100%; display: grid !important; place-items: center; font-weight: 900; color: #155bbd; font-size: 15px; }
.lead-card.is-overdue { border-color: #ffc1c1; box-shadow: 0 7px 23px rgba(195,64,64,.08); }
.lead-card.is-overdue .meeting-panel { background: #fff7f7; }
.lead-card.is-today { border-color: #9ec7ff; }
.danger-text { color: var(--red); }
.bitrix-link { background: #f5f0ff; border-color: #e4d8ff; color: #6b3fd0; }

@media (max-width: 900px) {
  .search-hero { grid-template-columns: 1fr; gap: 10px; }
  .funnel-tabs button { min-width: 150px; }
  .list-header { align-items: flex-start; }
  .list-actions { align-items: stretch; }
}

@media (max-width: 760px) {
  .search-hero { margin: 9px 0; padding: 13px; border-radius: 14px; }
  .search-copy strong { font-size: 15px; }
  .search-copy span { font-size: 10px; }
  .search-box-large { height: 44px; }
  .pipeline-section { padding: 13px 10px 9px; }
  .toolbar-title { margin-bottom: 8px; }
  .funnel-tabs { gap: 6px; }
  .funnel-tabs button { min-width: 140px; padding: 9px 10px; font-size: 10px; }
  .funnel-tabs button b { min-width: 22px; height: 22px; font-size: 9px; }
  .work-filters { padding: 8px 10px; }
  .list-header { display: grid; grid-template-columns: 1fr; }
  .list-actions { justify-content: space-between; }
  .sort-box { flex: 1; }
  .sort-box select { width: 100%; }
  .card-meta-row { font-size: 8px; }
  .quick-actions .button { flex: 1 1 42%; }
}

@media (max-width: 420px) {
  .search-copy span { display: none; }
  .period-bar { margin-top: 8px; }
  .funnel-tabs button { min-width: 132px; }
  .list-actions { display: grid; grid-template-columns: 1fr auto; }
}
