/* === Layout === */
.app {
  display: grid;
  grid-template-columns: var(--gh-sidebar-current, 240px) minmax(0, 1fr);
  min-height: 100vh;
  --gh-sidebar-expanded: 240px;
  --gh-sidebar-collapsed: 72px;
  --gh-sidebar-current: var(--gh-sidebar-expanded);
  transition: grid-template-columns 0.34s cubic-bezier(0.4, 0, 0.2, 1);
}

.app.app--sidebar-collapsed {
  --gh-sidebar-current: var(--gh-sidebar-collapsed);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  transition:
    padding 0.34s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.18s ease;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 16px 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  transition:
    gap 0.28s ease,
    padding 0.34s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  position: relative;
  padding: 0;
  margin: 0;
  border: none;
  transition: justify-content 0.28s ease;
}

.sidebar__brand img { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.sidebar__brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.24s ease, max-width 0.34s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 200px;
  opacity: 1;
}

.sidebar__brand-name span { color: var(--accent-700); }

.sidebar__rail-btn {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.16s ease,
    color 0.16s ease,
    transform 0.14s ease;
}

.sidebar__rail-btn:hover {
  background: color-mix(in srgb, var(--surface-2) 88%, var(--accent-50));
  color: var(--accent-700);
}

.sidebar__rail-btn:active {
  transform: scale(0.94);
}

.sidebar__rail-btn:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--surface-2) 85%, var(--accent-50));
  box-shadow: 0 0 0 2px var(--accent-50), 0 0 0 1px var(--accent-200);
}

@supports not (color: color-mix(in lab, red, red)) {
  .sidebar__rail-btn:hover {
    background: var(--surface-2);
  }
  .sidebar__rail-btn:focus-visible {
    background: var(--surface-2);
  }
}

.sidebar__rail-chevron {
  display: inline-block;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.22em;
  margin-right: 0.06em;
  user-select: none;
}

.app.app--sidebar-collapsed .sidebar__top {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 2px 0 14px;
  margin-bottom: 12px;
}

.app.app--sidebar-collapsed .sidebar__brand {
  flex: none;
  width: 100%;
  justify-content: center;
  align-items: center;
  gap: 0;
}

.app.app--sidebar-collapsed .sidebar__brand-name {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
  max-width: none;
}

.app.app--sidebar-collapsed .sidebar__brand img {
  display: block;
  margin-inline: auto;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar__link {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  transition: background .15s, color .15s, padding .28s ease, gap .28s ease, justify-content .28s ease;
}
.sidebar__link:hover { background: var(--surface-2); color: var(--text); }
.sidebar__link--active {
  background: var(--accent-50);
  color: var(--accent-700);
}
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }

.app.app--sidebar-collapsed .sidebar__link {
  justify-content: center;
  gap: 0;
  padding: 11px 8px;
}

.app.app--sidebar-collapsed .sidebar__link span {
  position: absolute;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
}
.sidebar__footer { padding-top: 12px; border-top: 1px solid var(--border); }

.app.app--sidebar-collapsed .sidebar {
  padding: 16px 6px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar__title { font-size: 18px; font-weight: 600; }
.topbar__right { display: flex; align-items: center; gap: 12px; }
.topbar__bell {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--text-muted);
  background: var(--surface-2);
  transition: background .15s, color .15s;
}
.topbar__bell:hover { color: var(--text); background: var(--accent-50); }
.topbar__bell.is-active { color: var(--accent-700); background: var(--accent-50); }
.topbar__badge-slot { position: absolute; top: -2px; right: -2px; }
.topbar__badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  font-size: 11px; font-weight: 700;
  background: var(--danger);
  color: white;
  border-radius: 999px;
  border: 2px solid var(--bg-2);
}
.list-row--unread { border-left: 3px solid var(--accent); background: var(--accent-50); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.user-chip:hover {
  border-color: var(--accent-200, var(--accent));
  background: var(--surface);
}
.user-chip:active { transform: translateY(1px); }
.user-chip:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-50);
}
.user-chip__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}
.user-chip__avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* ───── Профиль пользователя ───── */
.profile-form { max-width: 720px; display: flex; flex-direction: column; gap: 20px; }
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.profile-card__head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar-pick {
  position: relative;
  display: block;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  cursor: pointer;
  margin: 0;
  outline: none;
}
.profile-avatar-pick:focus-visible .profile-avatar-pick__ring {
  box-shadow: 0 0 0 3px var(--accent-50, rgba(143, 200, 100, 0.35));
}

.profile-avatar-pick__ring {
  position: relative;
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--border);
  box-sizing: border-box;
  flex-shrink: 0;
}

.profile-avatar-pick__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-avatar-pick__img--hidden {
  display: none;
}

.profile-avatar-pick__initials {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 600;
}

.profile-avatar-pick__overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.48);
  color: rgba(255, 255, 255, 0.95);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.profile-avatar-pick:hover .profile-avatar-pick__overlay,
.profile-avatar-pick:focus-within .profile-avatar-pick__overlay {
  opacity: 1;
}

.profile-avatar-pick .profile-avatar-pick__input {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  width: 72px;
  height: 72px;
  font-size: 0 !important;
  padding: 0;
  border: none;
}

.profile-card__name { font-size: 18px; font-weight: 600; color: var(--text); }
.profile-card__sub { font-size: 13px; margin-top: 2px; }
.profile-card__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 14px 18px;
}
.profile-grid__full { grid-column: 1 / -1; }

.profile-actions { display: flex; justify-content: flex-end; }
.content {
  padding: 24px;
}

/* Страницы с канбаном: нижняя зона до низа окна, скролл внутри колонок */
.content:has(.kanban) {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 16px;
}
.content:has(.kanban) > .page-header,
.content:has(.kanban) > .filters {
  flex-shrink: 0;
}

/* Канбан сразу в .content (проекты, задачи …) */
.content:has(.kanban) > .kanban {
  flex: 1;
  min-height: 0;
}

/* CRM заявки: канбан внутри #leads-workspace-pane */
.content:has(.leads-pane-kanban) > #leads-workspace-pane.leads-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.content:has(.leads-pane-kanban) .leads-pane-kanban {
  flex: 1;
  min-height: 0;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  text-decoration: none;
  background: transparent;
  color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn--primary:hover { background: var(--accent-600); border-color: var(--accent-600); color: #fff; }
.btn--ghost {
  border-color: var(--border);
  color: var(--text-muted);
  background: var(--bg-2);
}
.btn--ghost:hover { border-color: var(--border-strong); color: var(--text); }
.btn--danger {
  background: var(--danger); color: white; border-color: var(--danger);
}
.btn--danger:hover { background: #DC2626; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--icon {
  padding: 6px;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.btn--icon:hover { background: var(--surface-2); color: var(--text); }
.btn svg { width: 16px; height: 16px; }

/* === Inputs === */
.gh-input, .gh-select, .gh-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-2);
  font: inherit;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.gh-textarea { font-family: inherit; resize: vertical; min-height: 80px; }
.gh-input:focus, .gh-select:focus, .gh-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-50);
}
.gh-file {
  width: 100%; padding: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font: inherit;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field__label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.field__error { color: var(--danger); font-size: 12px; }
.row { display: grid; gap: 14px; }
.row--2 { grid-template-columns: 1fr 1fr; }
.row--3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 720px) { .row--2, .row--3 { grid-template-columns: 1fr; } }

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card__title { font-weight: 600; font-size: 15px; }
.card__body { padding: 18px; }
.card__body--tight { padding: 12px; }

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.metric__label { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.metric__value { margin-top: 6px; font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.metric__hint { margin-top: 4px; font-size: 12px; color: var(--text-soft); }

/* === Badges === */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge--accent { background: var(--accent-50); color: var(--accent-700); border-color: var(--accent-100); }
.badge--source { background: var(--surface-2); }
.badge--source .dot { width: 8px; height: 8px; border-radius: 50%; }
.badge--stage { font-weight: 600; }

/* === Tables === */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  font-weight: 600;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

/* === Tabs === */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  padding: 0 4px;
  margin-bottom: 18px;
}
.tabs__item {
  padding: 10px 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tabs__item:hover { color: var(--text); }
.tabs__item--active {
  color: var(--accent-700);
  border-bottom-color: var(--accent);
}

/* === Page header === */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
}
.page-header h1 {
  font-size: 22px; font-weight: 700; margin: 0;
  letter-spacing: -.01em;
}
.page-header__actions { display: flex; gap: 8px; align-items: center; }

/* === Filters bar === */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
  background: var(--surface);
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.filters .gh-input, .filters .gh-select { width: auto; min-width: 160px; }

/* === Login === */
.auth {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--accent-50) 0%, transparent 60%),
    var(--bg);
  padding: 24px;
}
.auth__card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.auth__brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 22px;
}
.auth__brand img { width: 40px; height: 40px; border-radius: 10px; }
.auth__brand-name { font-size: 20px; font-weight: 700; }
.auth__brand-name span { color: var(--accent-700); }
.auth__title { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
.auth__sub { color: var(--text-muted); margin: 0 0 20px; }
.auth__error {
  background: #FEF2F2; color: #B91C1C;
  border: 1px solid #FECACA; border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 14px; font-size: 13px;
}

/* === Empty state === */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* === Lists === */
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 8px;
}
.list-row__main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list-row__main .icon { color: var(--text-soft); flex-shrink: 0; }
.list-row__name { font-weight: 500; color: var(--text); }
.list-row__meta { color: var(--text-soft); font-size: 12px; }

/* === Comments / messages === */
.comment {
  display: flex; gap: 12px; padding: 12px; border-radius: var(--radius); background: var(--surface-2);
  margin-bottom: 8px;
}
.comment__avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: white;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.comment__author { font-weight: 600; }
.comment__time { color: var(--text-soft); font-size: 12px; margin-left: 6px; }
.comment__text { color: var(--text); white-space: pre-wrap; word-wrap: break-word; }

/* === Util === */
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.right { text-align: right; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 960px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .app.app--sidebar-collapsed {
    --gh-sidebar-current: var(--gh-sidebar-expanded);
  }
  .sidebar__rail-btn {
    display: none;
  }
  .app.app--sidebar-collapsed .sidebar {
    padding: 20px 12px;
  }
  .app.app--sidebar-collapsed .sidebar__top {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 0 2px 16px 6px;
    margin-bottom: 16px;
  }
  .app.app--sidebar-collapsed .sidebar__brand {
    justify-content: flex-start;
    flex: 1;
    width: auto;
    gap: 10px;
  }
  .app.app--sidebar-collapsed .sidebar__brand-name {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    clip-path: none;
    white-space: nowrap;
    border: 0;
    opacity: 1;
    pointer-events: auto;
    max-width: 200px;
  }
  .app.app--sidebar-collapsed .sidebar__brand img {
    margin-inline: 0;
    display: inline-block;
  }
  .app.app--sidebar-collapsed .sidebar__link {
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }
  .app.app--sidebar-collapsed .sidebar__link span {
    position: static;
    clip: auto;
    clip-path: none;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    white-space: normal;
  }
}
