/* ==========================================================================
   Воронка CRM — app shell (sidebar + views)
   ========================================================================== */

body.app-body { background: var(--surface-2); overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* --- Sidebar --------------------------------------------------------- */
.side {
  display: flex; flex-direction: column;
  background: var(--forest-900);
  color: #c9dbd2;
  padding: 1.1rem .75rem;
  z-index: 40;
}
.side__brand {
  display: flex; align-items: center; gap: .65rem;
  font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; letter-spacing: -.02em;
  color: #fff; padding: .35rem .6rem 1.4rem;
}
.side__brand .brand__mark { width: 28px; height: 28px; box-shadow: 0 0 0 1px rgba(255,255,255,.12); border-radius: 8px; }
.side__nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: .75rem;
  padding: .66rem .7rem; border-radius: var(--r-sm);
  color: #b4cbbf; font-weight: 500; font-size: .94rem;
  transition: background .15s var(--ease), color .15s var(--ease);
  width: 100%; text-align: left;
}
.nav-item svg { width: 19px; height: 19px; flex: none; opacity: .8; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.is-active { background: rgba(255,255,255,.1); color: #fff; font-weight: 600; }
.nav-item.is-active::before {
  content: ""; position: absolute; left: -.75rem; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--saffron);
}
.nav-item.is-active svg { opacity: 1; color: var(--saffron); }
.nav-item__badge {
  margin-left: auto; font-size: .72rem; font-weight: 700;
  background: var(--saffron); color: var(--ink);
  border-radius: var(--r-full); padding: .1em .5em; min-width: 21px; text-align: center;
}
.side__spacer { flex: 1; }
.side__foot { display: flex; flex-direction: column; gap: 2px; padding-top: .8rem; border-top: 1px solid rgba(255,255,255,.08); }
.side__foot .nav-item { font-size: .88rem; color: #8fab9d; }
.side :focus-visible { outline-color: var(--saffron); }

/* --- Main region ----------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  padding: 1.5rem 1.6rem 1rem; flex: none;
}
.topbar__title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; letter-spacing: -.03em; color: var(--forest); }
.topbar__sub { font-size: .92rem; color: var(--muted); }
.burger { display: none; }

.view { flex: 1; overflow: auto; min-height: 0; }

/* ======================= KANBAN ===================================== */
.board { display: flex; gap: .9rem; padding: .2rem 1.6rem 1.4rem; height: 100%; align-items: flex-start; }
.col {
  flex: 0 0 264px; max-width: 264px;
  display: flex; flex-direction: column; max-height: 100%;
  border-radius: var(--r-lg);
  background: var(--surface-3);
}
.col__head {
  display: grid; grid-template-columns: 1fr auto; row-gap: .15rem;
  padding: .9rem .95rem .75rem;
  border-top: 3px solid var(--_c, var(--slate));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.col__head h3 { font-size: .92rem; font-weight: 600; color: var(--ink); letter-spacing: 0; }
.col__count { font-size: .8rem; font-weight: 600; color: var(--muted); }
.col__sum { grid-column: 1 / -1; font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; letter-spacing: -.02em; color: var(--ink); }
.col__list { padding: 0 .55rem .6rem; overflow-y: auto; flex: 1; min-height: 60px; display: flex; flex-direction: column; gap: .5rem; }
.col__list::-webkit-scrollbar { width: 8px; }
.col__list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.card {
  background: var(--surface);
  border-radius: var(--r);
  padding: .85rem .9rem .8rem;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow .15s var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card:active { cursor: grabbing; }
.card__title { font-weight: 600; font-size: .94rem; line-height: 1.3; }
.card__company { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.card__foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .8rem; }
.card__amount { font-weight: 700; font-size: .95rem; color: var(--forest); }
.card__avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .66rem; font-weight: 700; color: #fff; flex: none; }

/* SortableJS states */
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: var(--shadow-lg); }
.sortable-drag { transform: rotate(1.5deg); }
.col__list.drop-hint { background: color-mix(in srgb, var(--brand-100) 45%, transparent); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ======================= INBOX ====================================== */
.inbox {
  display: grid; grid-template-columns: 330px 1fr; height: calc(100% - 1.4rem);
  margin: .2rem 1.6rem 1.4rem; min-height: 0;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.convs { border-right: 1px solid var(--line-2); overflow-y: auto; min-height: 0; }
.conv {
  position: relative;
  display: flex; gap: .75rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line-2);
  cursor: pointer; transition: background .12s var(--ease); width: 100%; text-align: left;
}
.conv:hover { background: var(--surface-2); }
.conv.is-active { background: var(--brand-050); }
.conv.is-active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.conv__av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: #fff; flex: none; }
.conv__body { min-width: 0; flex: 1; }
.conv__row { display: flex; align-items: baseline; gap: .5rem; }
.conv__name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv__time { margin-left: auto; font-size: .74rem; color: var(--muted); flex: none; }
.conv__last { display: block; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv__meta { display: flex; align-items: center; gap: .4rem; margin-top: .35rem; }
.chan { display: inline-flex; align-items: center; gap: .35em; font-size: .72rem; font-weight: 500; color: var(--muted); }
.chan::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--_ch, var(--slate)); }
.chan--wa { --_ch: #1f8a64; }
.chan--tg { --_ch: #3b7dd8; }
.chan--ig { --_ch: #b8545a; }
.chan--site { --_ch: #9aa59e; }
.conv__unread { margin-left: auto; font-size: .72rem; font-weight: 700; color: var(--ink); background: var(--saffron); border-radius: var(--r-full); padding: .05em .5em; min-width: 20px; text-align: center; }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface-2); }
.thread__head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line-2); flex: none; }
.thread__head .conv__av { width: 38px; height: 38px; }
.thread__title { font-weight: 600; line-height: 1.25; }
.thread__body { flex: 1; overflow-y: auto; padding: 1.4rem; display: flex; flex-direction: column; gap: .6rem; min-height: 0; }
.msg { max-width: min(68%, 520px); padding: .6rem .9rem; border-radius: 14px; font-size: .93rem; line-height: 1.45; }
.msg time { display: block; font-size: .7rem; margin-top: .25rem; opacity: .6; }
.msg--in { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.msg--out { align-self: flex-end; background: var(--forest); color: #fff; border-bottom-right-radius: 4px; }
.msg--out time { opacity: .75; text-align: right; }
.thread__composer { display: flex; gap: .6rem; padding: .8rem 1rem; background: var(--surface); border-top: 1px solid var(--line-2); flex: none; }
.thread__composer input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: var(--r);
  padding: .7em 1em; font-size: .94rem; background: var(--surface-2);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.thread__composer input:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--brand-050); }
.icon-btn { width: 42px; height: 42px; border-radius: var(--r); display: grid; place-items: center; background: var(--forest); color: #fff; flex: none; transition: background .15s var(--ease); }
.icon-btn:hover { background: var(--ink); }
.icon-btn--plain { background: var(--surface-2); color: var(--ink); }
.icon-btn--plain:hover { background: var(--surface-3); }
.thread__empty { margin: auto; text-align: center; color: var(--muted); padding: 2rem; }

/* ======================= CLIENTS ==================================== */
.clients { padding: .2rem 1.6rem 1.6rem; }
.ctable {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden;
  font-size: .92rem;
}
.ctable th {
  text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted);
  padding: .85rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.ctable td { padding: .8rem 1rem; border-bottom: 1px solid var(--line-2); color: var(--ink-2); vertical-align: middle; }
.ctable tbody tr:last-child td { border-bottom: 0; }
.ctable tbody tr { transition: background .12s var(--ease); }
.ctable tbody tr:hover { background: var(--surface-2); }
.ctable a:hover { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.t-num { text-align: right !important; white-space: nowrap; }
.t-sum { font-weight: 700; color: var(--forest) !important; }
.who { display: flex; align-items: center; gap: .75rem; }
.who__av { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; color: #fff; flex: none; }
.who__name { display: block; font-weight: 600; color: var(--ink); }
.who__company { display: block; font-size: .82rem; color: var(--muted); }

@media (max-width: 760px) {
  .ctable, .ctable tbody, .ctable tr, .ctable td { display: block; }
  .ctable thead { display: none; }
  .ctable tr { padding: .9rem 1rem; border-bottom: 1px solid var(--line-2); }
  .ctable tbody tr:last-child { border-bottom: 0; }
  .ctable td { padding: .2rem 0; border: 0; display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; }
  .ctable td:first-child { padding-bottom: .6rem; }
  .ctable td[data-label]::before { content: attr(data-label); color: var(--muted); }
}

/* ======================= DASHBOARD ================================== */
.dash { padding: .2rem 1.6rem 1.6rem; display: flex; flex-direction: column; gap: 1rem; }
.tiles { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 1rem; }
.tile { background: var(--surface); border-radius: var(--r-lg); padding: 1.2rem 1.25rem; box-shadow: var(--shadow-sm); }
.tile__label { font-size: .86rem; color: var(--muted); }
.tile__value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; letter-spacing: -.03em; margin-top: .5rem; color: var(--ink); line-height: 1.1; }
.tile__note { font-size: .82rem; color: var(--muted); margin-top: .4rem; }
.tile--lead { background: var(--forest); box-shadow: none; }
.tile--lead .tile__label, .tile--lead .tile__note { color: #b4cbbf; }
.tile--lead .tile__value { color: #fff; }
.tile--lead .tile__note { color: var(--saffron); }
@media (max-width: 1100px) { .tiles { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .tile--lead { grid-column: 1 / -1; } }
@media (max-width: 480px) { .tile__value { font-size: 1.5rem; } }

.panels { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.panel { background: var(--surface); border-radius: var(--r-lg); padding: 1.3rem 1.35rem; box-shadow: var(--shadow-sm); }
.panel h3 { font-size: 1rem; margin-bottom: 1.2rem; }
@media (max-width: 900px) { .panels { grid-template-columns: 1fr; } }

/* Funnel bars — single hue, identity carried by label + dot */
.funnel { display: flex; flex-direction: column; gap: .7rem; }
.funnel__row { display: grid; grid-template-columns: 138px 1fr 7.5rem; align-items: center; gap: .9rem; }
.funnel__label { font-size: .88rem; color: var(--ink-2); display: flex; align-items: center; gap: .5rem; }
.funnel__count { margin-left: auto; color: var(--muted); font-size: .8rem; }
.funnel__track { background: var(--surface-2); border-radius: var(--r-sm); height: 28px; overflow: hidden; }
.funnel__fill { height: 100%; border-radius: var(--r-sm); min-width: 3px; background: var(--forest); transition: width .6s var(--ease); }
.panel:nth-child(2) .funnel__fill { background: var(--brand); }
.panel:nth-child(2) .funnel__row { grid-template-columns: 110px 1fr 2rem; }
.funnel__val { font-size: .86rem; font-weight: 600; color: var(--ink); text-align: right; }
@media (max-width: 560px) {
  .funnel__row, .panel:nth-child(2) .funnel__row { grid-template-columns: 1fr auto; row-gap: .35rem; }
  .funnel__track { grid-column: 1 / -1; grid-row: 2; }
  .funnel__count { margin-left: .25rem; }
}

/* --- Toast ----------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: .8em 1.3em; border-radius: var(--r);
  font-size: .9rem; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease); z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Responsive: off-canvas sidebar --------------------------------- */
.scrim { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: 0 auto 0 0; width: 250px;
    transform: translateX(-100%); transition: transform .25s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .side { transform: translateX(0); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(10,48,37,.45); opacity: 0; pointer-events: none; transition: opacity .25s var(--ease); z-index: 39; }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .topbar { align-items: center; padding: .9rem 1rem .8rem; gap: .25rem .7rem; }
  .topbar__title { font-size: 1.25rem; }
  .topbar__sub { flex-basis: 100%; padding-left: calc(40px + .7rem); margin-top: -.2rem; font-size: .85rem; }
  .burger { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-sm); color: var(--forest); background: var(--surface); box-shadow: var(--shadow-sm); }
  .board { padding: .2rem 1rem 1rem; scroll-snap-type: x mandatory; }
  .col { flex-basis: 82vw; max-width: 82vw; scroll-snap-align: start; }
  .inbox { grid-template-columns: 1fr; margin: .2rem 1rem 1rem; height: calc(100% - 1rem); }
  .inbox.show-thread .convs { display: none; }
  .inbox:not(.show-thread) .thread { display: none; }
  .msg { max-width: 85%; }
  .clients, .dash { padding: .2rem 1rem 1rem; }
}
@media (min-width: 861px) { .thread__back { display: none; } }
