*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #00B341;
  --primary-dark: #009130;
  --primary-light: #E8F5E9;
  --green: #00B341;
  --red: #FF5252;
  --purple: #43A047;
  --bg: #FFFFFF;
  --card-bg: #F7FBF7;
  --card-hover: #EEF7EE;
  --text: #1A1A1A;
  --text-muted: #5F6F5F;
  --border: #E8E8E8;
  --icon-surface: #E8F5E9;
  --icon-surface-2: #ffffff;
  --icon-accent: #00B341;
  --icon-accent-2: #43A047;
  --icon-accent-3: #66BB6A;
  --icon-muted: #A5D6A7;
  --icon-on-accent: #ffffff;
  --icon-warn: #E65100;
  --icon-border: #C8E6C9;
  --cal-border: #E8F5E9;
  --cal-has-events-bg: #F1F8E9;
  --cal-plan-bg: #FFF8E1;
  --cal-plan-border: #FFE082;
  --cal-paid-bg: #E8F5E9;
  --cal-paid-border: #81C784;
  --cal-overdue-bg: #FFEBEE;
  --cal-overdue-border: #C62828;
  --cal-late-bg: #FFF176;
  --cal-late-border: #F9A825;
  --cal-client-pending-bg: #FFF8E1;
  --cal-client-pending-border: #F57C00;
  --cal-investor-pending-bg: #F3E5F5;
  --cal-investor-pending-border: #7B1FA2;
  --cal-paid-amount: #2E7D32;
  --cal-overdue-amount: #C62828;
  --cal-late-amount: #E65100;
  --cal-event-plan-bg: #FFFDE7;
  --cal-event-fact-bg: #E8F5E9;
  --cal-badge-plan-bg: #FFF3CD;
  --cal-badge-plan-color: #F57F17;
  --toast-bg: #1a1a1a;
  --toast-color: #ffffff;
  --toast-border: transparent;
  --head-overdue-bg: #FFF5F5;
  --head-overdue-color: #C62828;
  --head-overdue-border: #EF5350;
  --head-today-bg: #F1FAF4;
  --head-today-color: #1B5E20;
  --head-today-border: var(--primary);
  --head-this-week-bg: #F3F8FC;
  --head-this-week-color: #1565C0;
  --head-this-week-border: #64B5F6;
  --head-next-week-bg: #F0F7FA;
  --head-next-week-color: #00695C;
  --head-next-week-border: #4DB6AC;
  --head-no-deadline-bg: #F5F6F7;
  --head-no-deadline-color: #546E7A;
  --head-no-deadline-border: #90A4AE;
  --head-later-bg: #F8F6FC;
  --head-later-color: #5E35B1;
  --head-later-border: #9575CD;
  --head-done-bg: #F3F4F3;
  --head-done-color: #616161;
  --head-done-border: #9E9E9E;
  --search-bg: #f8fbf8;
  --search-border: #dce8dc;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 12px 40px rgba(0, 179, 65, 0.18);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ??????? ????? */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  animation: blobFloat 12s ease-in-out infinite;
}

.blob-1 {
  width: 500px;
  height: 500px;
  background: #C8E6C9;
  top: -150px;
  right: -100px;
}

.blob-2 {
  width: 400px;
  height: 400px;
  background: #DCEDC8;
  bottom: -100px;
  left: -100px;
  animation-delay: -4s;
}

.blob-3 {
  width: 300px;
  height: 300px;
  background: #E8F5E9;
  top: 50%;
  left: 50%;
  animation-delay: -8s;
}

@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
}

/* ?????? */
.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ????? */
.header {
  background: var(--bg);
  border-bottom: 1px solid #E8F5E9;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.92);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.logo-dots {
  display: flex;
  gap: 3px;
}

.logo-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: block;
}

.logo-dots i:nth-child(1) { background: #00B341; }
.logo-dots i:nth-child(2) { background: #43A047; }
.logo-dots i:nth-child(3) { background: #66BB6A; }
.logo-dots i:nth-child(4) { background: #A5D6A7; }

.more-menu-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.more-menu-btn:hover,
.more-menu-btn.is-open {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.more-menu-btn.is-open .logo-dots i {
  transform: scale(1.08);
}

.more-menu {
  position: fixed;
  top: var(--more-menu-top, 64px);
  left: 0;
  width: 220px;
  min-width: 200px;
  max-width: min(220px, 72vw);
  height: calc(100dvh - var(--more-menu-top, 64px));
  max-height: calc(100dvh - var(--more-menu-top, 64px));
  background: var(--card-bg);
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  padding: 10px 8px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 10050;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: more-menu-fade-in 0.18s ease;
  touch-action: manipulation;
  transform: none;
  box-sizing: border-box;
}

body.more-menu-active {
  overflow: hidden;
}

@keyframes more-menu-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.more-menu[hidden] {
  display: none !important;
}

.more-menu-balance {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--primary-light) 70%, var(--card-bg));
  border: 1px solid var(--icon-border);
}

.more-menu-balance-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.more-menu-balance strong {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
}

.more-menu-balance small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.more-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.more-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  color: var(--text);
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
}

.more-menu-item:hover {
  background: color-mix(in srgb, var(--primary-light) 55%, transparent);
}

.more-menu-item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.more-menu-item-text strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.more-menu-empty {
  padding: 10px 12px;
  font-size: 13px;
}

.more-menu-item-text small {
  font-size: 11px;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .more-menu {
    width: min(200px, 72vw);
    min-width: 168px;
    padding: 8px 6px;
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .more-menu-item {
    padding: 7px 8px;
  }

  .more-menu-item-text strong {
    font-size: 12px;
  }

  .more-menu-item-text small {
    font-size: 10px;
  }
}

.header-balance-hidden {
  display: none !important;
}

.logo-text {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.onpoint-brand-img {
  display: block;
  height: 28px;
  width: auto;
  max-height: 28px;
  max-width: 110px;
  object-fit: contain;
  pointer-events: none;
  flex-shrink: 0;
}

.logo-onpoint-mark,
.logo-onpoint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  flex: 0 0 auto;
  flex-shrink: 0;
  line-height: 0;
  max-height: 36px;
  overflow: hidden;
}

.logo-onpoint-btn {
  cursor: pointer;
  font: inherit;
  transition: transform 0.12s;
}

.logo-onpoint-btn:hover .onpoint-brand-img {
  opacity: 0.85;
}

.logo-onpoint-btn.is-active .onpoint-brand-img,
.logo-onpoint-btn.is-open .onpoint-brand-img {
  opacity: 1;
}

.logo-onpoint-btn:active {
  transform: scale(0.97);
}

.header-msgr-btn {
  position: relative;
}

.header-msgr-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red, #FF5252);
  border: 2px solid var(--card-bg);
}

.header-nav {
  display: flex;
  gap: 24px;
  margin-left: auto;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color var(--transition);
}

.nav-link:hover {
  color: var(--primary);
}

/* ?????? */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  transition: all var(--transition);
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 179, 65, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.btn-ghost:hover {
  background: var(--card-bg);
  color: var(--text);
}

.btn-categories {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  flex-shrink: 0;
}

.btn-categories:hover {
  background: var(--primary-dark);
}

.btn-full {
  width: 100%;
  padding: 14px 24px;
  border-radius: var(--radius-lg);
  font-size: 16px;
}

/* Search */
.search-bar {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  background: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 14px;
  gap: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.search-bar:focus-within {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--search-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}

.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.7;
  transition: color 0.2s, opacity 0.2s;
}

.search-bar:focus-within .search-icon {
  color: var(--primary);
  opacity: 1;
}

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  background: transparent;
  color: var(--text);
  min-width: 0;
  line-height: 1.4;
}

.search-bar input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.btn-search {
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  min-height: 38px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.search-bar .btn-search:hover {
  transform: none;
  box-shadow: none;
}

.search-bar .btn-search:active {
  transform: scale(0.98);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-crm-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-muted);
  border: none;
}

.btn-icon:hover {
  background: #FFEBEE;
  color: #C62828;
}

.btn-home-strip {
  display: none;
  width: 100%;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 2px solid #C8E6C9;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.btn-home-strip svg {
  width: 18px;
  height: 18px;
}

.btn-search-text {
  display: inline;
}

.btn-search svg {
  display: none;
  width: 18px;
  height: 18px;
}

.user-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

/* ????? ????? */
.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.login-card {
  background: var(--bg);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: cardAppear 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardAppear {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.login-card-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  animation: iconBounce 2s ease-in-out infinite;
}

@keyframes iconBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.login-card-icon svg {
  width: 100%;
  height: 100%;
}

.login-title {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.field-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  padding: 0 16px;
  transition: all var(--transition);
}

.field-input-wrap:focus-within {
  border-color: var(--primary);
  background: var(--bg);
  box-shadow: 0 0 0 4px rgba(0, 179, 65, 0.1);
}

.field-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.field-input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  padding: 14px 0;
}

.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.login-hint {
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-hint code {
  background: var(--card-bg);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: 'Consolas', monospace;
  color: var(--primary);
  font-weight: 600;
}

/* ??????? */
.dashboard-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  width: 100%;
}

/* ?????????? */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 40px;
}

.stats-row-toolbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 4px;
}

.header-dash.mode-crm .header-balance,
.header-dash.mode-minimal .header-balance,
.header-dash.mode-crm .search-bar-main,
.header-dash.mode-minimal .search-bar-main,
.header-dash.mode-crm .header-msgr-btn,
.header-dash.mode-minimal .header-msgr-btn {
  display: none !important;
}

.home-crm-head {
  grid-column: 1 / -1;
  margin-bottom: 8px;
}

.home-crm-head .section-title {
  margin: 0 0 4px;
}

.stat-card.home-crm-stat .stat-value {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
}

.home-minimal {
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 24px 32px;
  max-width: 560px;
  margin: 0 auto;
}

.home-minimal .section-title {
  margin-bottom: 12px;
}

.home-mode-minimal .categories-section,
#home-view.home-mode-minimal .categories-section {
  display: none;
}

.badge-crm {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent, #3b82f6);
}

/* ─── Таблица пользователей ─── */
.users-table-wrap .data-table-wrap {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--card-bg);
}

.users-table-wrap .data-table th {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 6%, var(--card-bg));
  border-bottom: 1px solid var(--border);
}

.users-table-wrap .data-table td {
  vertical-align: middle;
  padding-top: 14px;
  padding-bottom: 14px;
}

.users-table-wrap .users-row.is-me {
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}

.users-table-wrap .users-row.is-me .user-avatar {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 45%, transparent);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark);
  background: color-mix(in srgb, var(--primary) 18%, var(--card-bg));
}

.user-role-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.user-role-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.user-role-owner {
  background: color-mix(in srgb, var(--primary) 20%, var(--card-bg));
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 32%, transparent);
}

.user-role-admin {
  background: color-mix(in srgb, #7c4dff 18%, var(--card-bg));
  color: #6d28d9;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #7c4dff 28%, transparent);
}

.user-role-user {
  background: color-mix(in srgb, var(--text-muted) 12%, var(--card-bg));
  color: var(--text-muted);
  box-shadow: inset 0 0 0 1px var(--border);
}

.user-role-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
}

.user-mode-switch {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-muted) 8%, var(--card-bg));
  border: 1px solid var(--border);
}

.user-mode-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.user-mode-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.user-mode-btn.is-active.mode-micr {
  background: color-mix(in srgb, var(--primary) 22%, var(--card-bg));
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 35%, transparent);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.user-mode-btn.is-active.mode-crm {
  background: color-mix(in srgb, #3b82f6 18%, var(--card-bg));
  color: #2563eb;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #3b82f6 30%, transparent);
}

.user-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.user-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}

.user-status.is-active {
  color: var(--text);
}

.user-status.is-active i {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

body.theme-dark .user-avatar {
  color: #86efac;
  background: rgba(74, 222, 128, 0.14);
}

body.theme-dark .user-role-owner {
  background: rgba(74, 222, 128, 0.16);
  color: #86efac;
}

body.theme-dark .user-role-admin {
  background: rgba(124, 77, 255, 0.18);
  color: #c4b5fd;
}

body.theme-dark .user-mode-switch {
  background: #121820;
}

body.theme-dark .user-mode-btn.is-active.mode-micr {
  background: rgba(74, 222, 128, 0.18);
  color: #86efac;
}

body.theme-dark .user-mode-btn.is-active.mode-crm {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

body.theme-dark .user-status.is-active i {
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.2);
}

.btn-export-excel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 14px;
}

.btn-export-excel svg {
  width: 18px;
  height: 18px;
}

.section-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.badge-muted {
  opacity: 0.65;
}

.stat-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  min-height: 120px;
  overflow: hidden;
  display: block;
  transition: all var(--transition);
  animation: statSlide 0.5s ease backwards;
  animation-delay: calc(var(--delay) * 0.1s);
}

@keyframes statSlide {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.stat-card-clickable {
  cursor: pointer;
}

.stat-card-clickable:active {
  transform: translateY(-2px);
}

.stat-label {
  display: block;
  font-size: 16px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.3;
  max-width: 70%;
  position: relative;
  z-index: 2;
  margin-bottom: 6px;
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  max-width: 72%;
  position: relative;
  z-index: 2;
}

.stat-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 100%;
  height: 100%;
}

.stat-card-icon {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 90px;
  height: 90px;
  z-index: 1;
  pointer-events: none;
  transition: transform var(--transition);
}

.stat-card:hover .stat-card-icon {
  transform: scale(1.08) rotate(-4deg);
}

.stat-card-icon svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.08));
}

/* ????????? */
.section-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.category-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  min-height: 120px;
  cursor: pointer;
  overflow: hidden;
  border: 2px solid transparent;
  transition: all var(--transition);
  animation: cardSlide 0.5s ease backwards;
  animation-delay: calc(var(--i) * 0.06s);
}

@keyframes cardSlide {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.category-card:hover {
  background: var(--card-hover);
  border-color: var(--primary);
  transform: translateY(-6px);
  box-shadow: var(--shadow-hover);
}

.category-card:active {
  transform: translateY(-2px);
}

.category-card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  max-width: 60%;
  position: relative;
  z-index: 2;
}

.category-card-count {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
}

.category-card-icon {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 90px;
  height: 90px;
  transition: transform var(--transition);
  z-index: 1;
}

.category-card:hover .category-card-icon {
  transform: scale(1.12) rotate(-5deg);
}

.category-card-icon svg,
.category-card-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.1));
}

/* ?????? ?????? */
.data-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.data-panel[hidden] {
  display: none;
}

.data-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

.data-panel-content {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
  animation: panelSlide 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes panelSlide {
  from { opacity: 0; transform: scale(0.85) translateY(30px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.data-panel-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--card-bg);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  color: var(--text-muted);
}

.data-panel-close:hover {
  background: #E0E0E0;
  color: var(--text);
  transform: rotate(90deg);
}

.data-panel-close svg {
  width: 18px;
  height: 18px;
}

.data-panel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.data-panel-icon {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.data-panel-icon svg {
  width: 100%;
  height: 100%;
}

.data-panel-header h3 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.data-panel-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.data-panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.data-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.data-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.data-field input,
.data-field textarea,
.data-field select {
  font-family: inherit;
  font-size: 15px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
  background: var(--card-bg);
  color: var(--text);
}

.data-field input:focus,
.data-field textarea:focus,
.data-field select:focus {
  border-color: var(--primary);
}

.data-field textarea {
  resize: vertical;
  min-height: 80px;
}

.data-panel-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid #E8F5E9;
}

/* ???????? ????? */
.test-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 6px 12px;
  border-radius: 20px;
  margin-bottom: 20px;
}

.test-empty {
  text-align: center;
  padding: 20px 16px 24px;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.test-empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  opacity: 0.7;
}

.test-empty-icon svg {
  width: 100%;
  height: 100%;
}

.test-empty-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.test-empty-text {
  font-size: 14px;
  color: var(--text-muted);
}

.test-empty-text strong {
  color: var(--primary);
}

.test-table-wrap {
  overflow-x: auto;
  margin-bottom: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid #E8F5E9;
}

.test-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.test-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
  white-space: nowrap;
}

.test-table td {
  padding: 10px 12px;
  border-top: 1px solid #E8F5E9;
  color: var(--text-muted);
}

.test-row-empty td {
  text-align: center;
  font-style: italic;
  color: var(--text-muted);
  padding: 16px;
}

.test-row-demo td {
  opacity: 0.4;
}

.test-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.test-input {
  background: var(--card-bg) !important;
  color: var(--text-muted) !important;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .test-fields {
    grid-template-columns: 1fr;
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--toast-bg) !important;
  color: var(--toast-color) !important;
  border: 1px solid var(--toast-border);
  padding: 14px 28px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  z-index: 10000;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

body.theme-dark .toast {
  background: var(--toast-bg) !important;
  color: var(--toast-color) !important;
  border: 1px solid var(--toast-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(74, 222, 128, 0.15);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Chat popup notifications (MICR + CRM) */
.chat-notify-stack {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 10050;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 12px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.chat-notify-popup {
  pointer-events: auto;
  width: min(360px, calc(100vw - 32px));
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow, 0 16px 48px rgba(0, 0, 0, 0.28));
  opacity: 0;
  transform: translateX(calc(100% + 24px)) scale(0.96);
  transition: opacity 0.32s ease, transform 0.36s cubic-bezier(0.22, 1.1, 0.36, 1);
}

.chat-notify-popup.is-visible {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.chat-notify-popup.is-leaving {
  opacity: 0;
  transform: translateX(calc(100% + 24px)) scale(0.96);
}

.chat-notify-popup-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card-hover);
}

.chat-notify-popup--micr .chat-notify-popup-head {
  background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 14%, var(--card-hover)), var(--card-hover));
}

.chat-notify-popup--crm .chat-notify-popup-head {
  background: linear-gradient(90deg, color-mix(in srgb, #2563eb 14%, var(--card-hover)), var(--card-hover));
}

.chat-notify-popup-brand {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--primary, #2d6a4f);
  color: #fff;
}

.chat-notify-popup--crm .chat-notify-popup-brand {
  background: #2563eb;
}

.chat-notify-popup-head-title {
  flex: 1;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.chat-notify-popup-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
}

.chat-notify-popup-close:hover {
  opacity: 1;
  color: var(--text);
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.chat-notify-popup-body {
  display: flex;
  gap: 12px;
  padding: 14px 14px 10px;
  align-items: flex-start;
}

.chat-notify-popup-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--primary, #2d6a4f), #40916c);
}

.chat-notify-popup--crm .chat-notify-popup-avatar {
  background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.chat-notify-popup-content {
  min-width: 0;
  flex: 1;
}

.chat-notify-popup-lead {
  margin: 0 0 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.chat-notify-popup-name {
  display: block;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 6px;
  color: var(--text);
}

.chat-notify-popup-msg {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--text) 7%, var(--card-bg));
  color: var(--text);
  border: 1px solid var(--border);
  word-break: break-word;
}

.chat-notify-popup-foot {
  display: flex;
  justify-content: flex-end;
  padding: 0 14px 14px;
}

.chat-notify-popup-open {
  min-width: 120px;
}

body.theme-dark .chat-notify-popup {
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(74, 222, 128, 0.14);
}

body.theme-dark .chat-notify-popup--micr .chat-notify-popup-head {
  background: linear-gradient(90deg, rgba(74, 222, 128, 0.14), rgba(26, 34, 45, 0));
}

body.theme-dark .chat-notify-popup--crm .chat-notify-popup-head {
  background: linear-gradient(90deg, rgba(96, 165, 250, 0.16), rgba(26, 34, 45, 0));
}

body.theme-dark .chat-notify-popup-brand {
  background: var(--icon-accent);
  color: var(--icon-on-accent);
}

body.theme-dark .chat-notify-popup--crm .chat-notify-popup-brand {
  background: #60a5fa;
  color: #0f1419;
}

body.theme-dark .chat-notify-popup-avatar {
  background: linear-gradient(135deg, #2d6a4f, var(--icon-accent));
  color: var(--icon-on-accent);
}

body.theme-dark .chat-notify-popup--crm .chat-notify-popup-avatar {
  background: linear-gradient(135deg, #2563eb, #93c5fd);
  color: #0f1419;
}

body.theme-dark .chat-notify-popup-msg {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .chat-notify-popup-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 640px) {
  .chat-notify-stack {
    right: 10px;
    bottom: 12px;
    left: 10px;
    max-width: none;
    align-items: stretch;
  }

  .chat-notify-popup {
    width: 100%;
  }
}

/* ??????? � ???????? */
@media (max-width: 1024px) {
  .categories-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .calendar-layout {
    grid-template-columns: 1fr;
  }
  .calendar-side {
    position: static;
    max-height: none;
  }
}

/* ??????? � ????????? ? ????? ?????? */
@media (max-width: 768px) {
  .header {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .header-inner {
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  #login-screen .header-nav {
    display: none;
  }

  .header-dash .header-inner {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .header-dash .search-bar {
    min-width: 0;
    width: 100%;
    padding: 3px 3px 3px 12px;
    border-radius: var(--radius-lg);
  }

  .header-dash .search-bar input {
    font-size: 16px;
  }

  .header-dash #home-btn:not([hidden]) {
    display: inline-flex;
  }

  .btn-search-text {
    display: none;
  }

  .btn-search svg {
    display: block;
  }

  .btn-search {
    padding: 10px 12px;
    min-width: 44px;
  }

  .user-badge {
    padding: 6px 10px;
    font-size: 12px;
  }

  .dashboard-main {
    padding: 16px 14px 88px;
  }

  .login-main {
    padding: 24px 16px;
    align-items: flex-start;
    padding-top: 32px;
  }

  .login-card {
    padding: 28px 20px;
    border-radius: var(--radius-lg);
  }

  .login-title {
    font-size: 22px;
  }

  .stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 24px;
  }

  .stat-card {
    padding: 16px 18px;
    min-height: 108px;
  }

  .stat-label {
    font-size: 15px;
  }

  .stat-value {
    font-size: 18px;
  }

  .stat-value-sm {
    font-size: 18px !important;
  }

  .stat-info-sub {
    font-size: 11px;
    line-height: 1.3;
  }

  .stat-card-icon {
    width: 72px;
    height: 72px;
  }

  .section-title {
    font-size: 18px;
    margin-bottom: 14px;
  }

  .categories-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .category-card {
    padding: 14px 16px;
    min-height: 100px;
  }

  .category-card-title {
    font-size: 13px;
    max-width: 75%;
    line-height: 1.25;
  }

  .category-card-count {
    font-size: 11px;
  }

  .category-card-icon {
    width: 64px;
    height: 64px;
  }

  .section-header h2 {
    font-size: 22px;
  }

  .section-header.row-between {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .section-header.row-between > .btn,
  .section-header.row-between > .filter-tabs {
    width: 100%;
  }

  .filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .filter-tabs::-webkit-scrollbar {
    display: none;
  }

  .filter-tabs .tab {
    flex-shrink: 0;
    padding: 11px 18px;
    min-height: 42px;
    font-size: 14px;
  }

  .panel-card {
    padding: 18px 16px;
    border-radius: var(--radius-md);
  }

  .balance-item strong {
    font-size: 20px;
  }

  .manual-form-grid {
    grid-template-columns: 1fr;
  }

  .schedule-form-compact {
    gap: 10px;
  }

  .schedule-form-row {
    flex-wrap: wrap;
  }

  .schedule-form-row > .data-field {
    flex: 1 1 calc(50% - 5px);
    min-width: 140px;
  }

  .schedule-form-row > .schedule-form-actions {
    flex: 1 1 100%;
  }

  .schedule-form-actions .btn {
    width: 100%;
    height: auto;
  }

  .schedule-plan-panel {
    max-width: none;
  }

  .manual-full {
    grid-column: auto;
  }

  .manual-form-actions {
    flex-direction: column-reverse;
  }

  .manual-form-actions .btn {
    width: 100%;
  }

  .period-filter {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .period-filter input,
  .period-filter .btn {
    width: 100%;
  }

  .cal-add-form {
    padding: 18px 16px;
  }

  .calendar-main,
  .calendar-side {
    padding: 16px;
    border-radius: var(--radius-lg);
  }

  .cal-nav h3 {
    font-size: 17px;
  }

  .cal-summary {
    grid-template-columns: 1fr 1fr;
  }

  .cal-event-top {
    flex-wrap: wrap;
    gap: 6px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .metric-value {
    font-size: 18px;
  }

  .bar-chart {
    height: 140px;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .bar-item {
    min-width: 28px;
  }

  .bar-label {
    font-size: 9px;
  }

  .data-table-wrap {
    margin: 0 -4px;
    border-radius: var(--radius-md);
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    font-size: 12px;
    min-width: 640px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 12px;
  }

  .data-field input,
  .data-field textarea,
  .data-field select,
  .manual-form input,
  .manual-form select,
  .field-input-wrap input,
  .phone-row input {
    font-size: 16px;
  }

  .phone-row {
    grid-template-columns: 1fr;
  }

  .phone-row .btn {
    width: 100%;
    justify-self: start;
  }

  .doc-item {
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateX(0) translateY(100px);
    text-align: center;
  }

  .toast.show {
    transform: translateX(0) translateY(0);
  }
}

@media (max-width: 480px) {
  .categories-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card {
    padding: 14px 16px;
    min-height: 100px;
  }

  .stat-label {
    font-size: 14px;
  }

  .stat-value {
    font-size: 16px;
  }

  .stat-value-sm {
    font-size: 16px !important;
  }

  .stat-card-icon {
    width: 64px;
    height: 64px;
  }

  .category-card {
    min-height: 92px;
  }

  .balance-panel,
  .info-grid,
  .cal-summary {
    grid-template-columns: 1fr;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .cal-grid {
    gap: 3px;
  }

  .cal-cell {
    min-height: 40px;
    padding: 4px 2px;
    border-radius: 10px;
  }

  .cal-day {
    font-size: 11px;
  }

  .cal-cell.today .cal-day {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .cal-dots .dot {
    width: 4px;
    height: 4px;
  }

  .cal-count {
    width: 14px;
    height: 14px;
    font-size: 8px;
    top: 2px;
    right: 2px;
  }

  .cal-weekdays span {
    font-size: 10px;
    padding: 4px 0;
  }

  .btn {
    min-height: 44px;
  }

  .btn-ghost {
    min-height: 40px;
  }

  .blob-1 {
    width: 280px;
    height: 280px;
  }

  .blob-2 {
    width: 220px;
    height: 220px;
  }

  .blob-3 {
    width: 180px;
    height: 180px;
  }
}

/* ????????? ?????????? � ??? hover-???????? */
@media (hover: none) {
  .category-card:hover,
  .stat-card:hover,
  .metric-card:hover,
  .cal-cell:hover {
    transform: none;
    box-shadow: none;
  }

  .category-card:active {
    transform: scale(0.98);
    border-color: var(--primary);
  }

  .cal-cell:active {
    border-color: var(--primary);
    background: var(--primary-light);
  }
}

/* Section views */
.back-btn {
  margin-bottom: 20px;
  padding: 10px 16px;
}

.section-header {
  margin-bottom: 24px;
}

.section-header h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.section-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.stat-value-sm {
  font-size: 22px !important;
}

.stat-info-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
  max-width: 70%;
  position: relative;
  z-index: 2;
}

.data-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 700px;
}

.data-table th {
  text-align: left;
  padding: 14px 16px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:hover {
  background: #F7FBF7;
}

.data-table .highlight,
.data-table tr.highlight {
  background: #E8F5E9 !important;
  animation: highlightPulse 1.5s ease;
}

@keyframes highlightPulse {
  0%, 100% { background: #E8F5E9; }
  50% { background: #C8E6C9; }
}

.row-overdue {
  background: #FFF8F8;
}

.amount-income {
  color: var(--primary);
  font-weight: 700;
}

.amount-expense {
  color: #C62828;
  font-weight: 700;
}

.cell-overdue {
  background: rgba(198, 40, 40, 0.08);
}

body.theme-dark .cell-overdue {
  background: rgba(255, 82, 82, 0.12);
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
}

.badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  background: var(--card-bg);
  border-radius: var(--radius-lg);
}

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.metric-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: transform var(--transition), box-shadow var(--transition);
}

.metric-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.metric-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.metric-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.metric-positive { color: var(--primary); }
.metric-negative { color: #C62828; }

.chart-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.chart-card h3 {
  font-size: 16px;
  margin-bottom: 20px;
  font-weight: 700;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 180px;
  padding-top: 20px;
}

.bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(180deg, #66BB6A, #00B341);
  border-radius: 8px 8px 4px 4px;
  position: relative;
  min-height: 4px;
  transition: height 0.5s ease;
  margin-top: auto;
}

.bar:hover .bar-tip { opacity: 1; }

.bar-tip {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

.bar-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  font-weight: 600;
}

/* Payment Calendar */
.calendar-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.calendar-main {
  background: var(--bg);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--cal-border);
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.cal-nav h3 {
  font-size: 20px;
  font-weight: 800;
}

.cal-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.cal-sum {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cal-sum span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.cal-sum strong {
  font-size: 16px;
  font-weight: 800;
}

.cal-sum.income strong { color: var(--primary); }
.cal-sum.expense strong { color: #C62828; }
.cal-sum.net strong { color: #1B5E20; }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 8px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-cell {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  font-family: inherit;
  transition: background 0.45s ease, border-color 0.45s ease, transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  min-height: 56px;
}

.cal-cell:hover {
  border-color: var(--primary);
  transform: scale(1.05);
  z-index: 2;
  box-shadow: var(--shadow-hover);
}

.cal-cell.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}

.cal-cell.today .cal-day {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-cell.has-events {
  background: var(--cal-has-events-bg);
}

.cal-empty {
  background: transparent;
  cursor: default;
  border: none;
}

.cal-empty:hover {
  transform: none;
  box-shadow: none;
}

.cal-day {
  font-size: 14px;
  font-weight: 700;
}

.cal-dots {
  display: flex;
  gap: 3px;
}

.cal-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: block;
}

.dot.income { background: var(--primary); }
.dot.expense { background: #EF5350; }

.cal-count {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-side {
  background: var(--bg);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--cal-border);
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.calendar-side h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 16px;
}

.cal-events-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cal-event {
  position: relative;
  padding: 14px;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--primary);
  background: var(--card-bg);
  transition: transform 0.2s, background 0.45s ease, border-color 0.45s ease;
}

.cal-event-deletable {
  padding-right: 42px;
}

.cal-event:hover {
  transform: translateX(4px);
}

.cal-event-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.cal-event-amount {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.25;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.cal-event.cal-entity-client.status-pending .cal-event-amount { color: #E65100; }
.cal-event.cal-entity-investor.status-pending .cal-event-amount { color: #7B1FA2; }

.cal-event-date {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1.4;
}

.cal-event-split {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.cal-event-text {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.cal-event-fact {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.cal-event-comment {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.cal-event.income { border-left-color: var(--primary); }
.cal-event.expense { border-left-color: #EF5350; }

.cal-event.cal-entity-client.status-pending {
  background: var(--cal-client-pending-bg);
  border-left-color: var(--cal-client-pending-border);
}

.cal-event.cal-entity-investor.status-pending {
  background: var(--cal-investor-pending-bg);
  border-left-color: var(--cal-investor-pending-border);
}

.cal-event.status-paid {
  background: var(--cal-paid-bg);
  border-left-color: var(--cal-paid-border);
}

.cal-event.status-overdue {
  background: var(--cal-overdue-bg);
  border-left-color: var(--cal-overdue-border);
}

.cal-event.status-late {
  background: var(--cal-late-bg);
  border-left-color: var(--cal-late-border);
}

.cal-event.status-paid .cal-event-amount { color: var(--cal-paid-amount); }
.cal-event.status-overdue .cal-event-amount { color: var(--cal-overdue-amount); }
.cal-event.status-late .cal-event-amount { color: var(--cal-late-amount); }
.cal-event.status-paid .cal-event-fact { color: var(--cal-paid-amount); }
.cal-event.status-late .cal-event-fact { color: var(--cal-late-amount); }

.cal-event .manual-badge.plan {
  background: var(--cal-badge-plan-bg);
  color: var(--cal-badge-plan-color);
}

.cal-event .manual-badge.fact {
  background: #C8E6C9;
  color: #1B5E20;
}

.cal-event .manual-badge.overdue {
  background: #FFCDD2;
  color: #B71C1C;
}

.cal-event .manual-badge.late {
  background: #FFCA28;
  color: #E65100;
}

.cal-event .badge-client-cal {
  background: #FFE0B2;
  color: #E65100;
}

.cal-event .badge-investor-cal {
  background: #E1BEE7;
  color: #6A1B9A;
}

.sch-whole-debt-row .checkbox-inline {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
}

.sch-whole-debt-row input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
}

.schedule-plan-panel {
  max-width: none;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.schedule-plan-panel h3 {
  font-size: 14px;
  margin-bottom: 10px;
}

.schedule-form-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.schedule-form-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 10px;
}

.schedule-form-row > .data-field {
  flex: 1 1 0;
  min-width: 0;
}

.schedule-form-row > .schedule-form-actions {
  flex: 0 0 auto;
}

.schedule-form-compact .data-field span {
  font-size: 11px;
  margin-bottom: 4px;
}

.schedule-form-compact input,
.schedule-form-compact select {
  padding: 8px 10px;
  font-size: 13px;
}

.schedule-form-compact .sch-whole-debt-row .checkbox-inline {
  font-size: 12px;
  line-height: 1.35;
}

.schedule-form-actions {
  display: flex;
  align-items: flex-end;
  margin-top: 0;
}

.schedule-form-actions .btn {
  width: auto;
  max-width: none;
  min-width: 0;
  padding: 8px 14px;
  font-size: 13px;
  white-space: nowrap;
  height: 37px;
}

.schedule-plan-hint {
  font-size: 12px;
  margin-top: 6px !important;
  line-height: 1.35;
}

.summary-card-debt strong {
  color: #C62828;
}

.summary-card-next-pay,
.summary-card-debt {
  text-align: center;
}

.summary-card-next-pay .summary-card-value-row {
  justify-content: center;
}

body.theme-dark .summary-card-debt strong {
  color: #ff8a80;
}

/* Manual calendar add form */
.cal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cal-add-form {
  background: var(--bg);
  border: 2px solid var(--primary);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-hover);
  animation: fadeIn 0.3s ease;
}

.cal-add-form h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 16px;
}

.manual-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.manual-full {
  grid-column: 1 / -1;
}

.manual-form .data-field span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.manual-form input,
.manual-form select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
  background: var(--card-bg);
  color: var(--text);
}

.manual-form input:focus,
.manual-form select:focus {
  border-color: var(--primary);
}

.manual-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #E8F5E9;
}

.manual-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}

.cal-event-manual {
  position: relative;
  padding-right: 36px;
}

.cal-event-has-actions {
  position: relative;
  padding-right: 36px;
}

.cal-event-both-actions {
  padding-right: 64px;
}

.cal-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: #E3F2FD;
  color: #1565C0;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  padding: 0;
}

.cal-event-both-actions .cal-edit {
  right: 36px;
}

.cal-edit:hover {
  background: #1565C0;
  color: #fff;
  transform: scale(1.1);
}

.cal-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: #FFEBEE;
  color: #C62828;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  padding: 0;
}

.cal-delete:hover {
  background: #C62828;
  color: #fff;
  transform: scale(1.1);
}

/* calendar-layout responsive moved to main adaptive block */

/* v5 � ????? ??????? */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.balance-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.balance-item {
  background: var(--primary-light);
  border: 2px solid var(--icon-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}
.balance-item span { display: block; font-size: 13px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.balance-item strong { font-size: 24px; font-weight: 800; color: var(--primary); }
.panel-card { background: var(--bg); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.panel-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.client-profile-head h3 { margin-bottom: 0; }
.client-profile-lock {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  color: var(--text-muted);
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.client-profile-lock:hover {
  color: var(--icon-accent, #2d6a4f);
  background: var(--icon-surface, rgba(45, 106, 79, 0.08));
}
.client-profile-lock[aria-pressed="true"] {
  color: #fff;
  border-color: var(--icon-accent, #3ecf8e);
  background: var(--icon-accent, #2d6a4f);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.client-profile-lock[aria-pressed="true"]:hover {
  color: #fff;
  background: var(--primary, #3ecf8e);
  border-color: var(--primary, #3ecf8e);
}
.client-profile-lock-svg {
  width: 18px;
  height: 18px;
  display: block;
}
.client-profile-edit { margin-top: 4px; }
.filter-tabs, .cal-tabs { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.flow-filter-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: thin; max-width: 100%; }
/* Расходы и поступления: вкладки + шапка таблицы липнут под верхней панелью */
.flow-page {
  --flow-offset: 80px;
}
.flow-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 16px;
  margin-bottom: 24px;
  padding-block: 12px;
  border-block: 1px solid var(--border);
}
.flow-totals span {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.flow-totals strong {
  font-size: 22px;
  overflow-wrap: anywhere;
}
.flow-page .flow-table td {
  white-space: normal;
  overflow-wrap: anywhere;
}
.flow-page .flow-sticky-panel {
  position: sticky;
  top: var(--flow-offset);
  z-index: 92;
  background: color-mix(in srgb, var(--card-bg) 96%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}
.flow-page .flow-sticky-panel .flow-filter-tabs {
  margin-bottom: 0;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
}
.flow-page .flow-head-table,
.flow-page .flow-table-body-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.flow-page .flow-head-table {
  border-radius: 0;
}
.flow-page .flow-head-table .flow-table {
  margin-bottom: 0;
}
.flow-page .flow-head-table .flow-table th {
  position: static;
  border-bottom: 2px solid var(--border);
}
.flow-page .flow-table-body-wrap {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow);
}
.flow-page .flow-table-body-wrap .flow-table td:first-child,
.flow-page .flow-head-table .flow-table th:first-child {
  padding-left: 16px;
}
@media (max-width: 768px) {
  .flow-page {
    --flow-offset: 128px;
  }
}
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.badge-cat-other { background: #ECEFF1; color: #455A64; }
[data-theme="dark"] .badge-cat-other { background: #37474F; color: #CFD8DC; }

.badge-cat-work { background: #FFF3E0; color: #E65100; }
.badge-cat-lawyers { background: #E3F2FD; color: #1565C0; }
.badge-cat-founders { background: #FCE4EC; color: #C2185B; }
.badge-cat-investor { background: #E8F5E9; color: #2E7D32; }
.badge-cat-client { background: #F1F8E9; color: #558B2F; }
.investor-card { padding: 16px; border: 1px solid var(--border, #E8E8E8); border-radius: var(--radius-lg, 12px); }
.filter-tabs .tab {
  padding: 12px 22px;
  min-height: 44px;
  border: 2px solid #E8E8E8;
  background: var(--bg);
  border-radius: var(--radius-xl);
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  cursor: pointer;
  transition: all .2s;
}
.filter-tabs .tab.active, .filter-tabs .tab:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.summary-card { background: var(--card-bg); border-radius: var(--radius-md); padding: 16px; border: 1px solid var(--border); }
.summary-card span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.summary-card strong { font-size: 18px; font-weight: 800; }
.summary-card-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.summary-card-edit {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--primary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.summary-card-edit:hover {
  background: var(--primary-light);
  border-color: var(--icon-border);
  transform: scale(1.05);
}
.summary-card-rating-edit {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-card-rating-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: inherit;
  font-size: 12px;
}
.summary-card-rating-edit-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.summary-card-rating-edit-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}
.summary-card-rating-editable #client-rating-view {
  cursor: pointer;
}
.summary-card-rating-editable #client-rating-view:hover strong {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn { background: none; border: none; color: var(--primary); font-weight: 700; font-size: inherit; cursor: pointer; font-family: inherit; padding: 0; text-align: left; }
.link-btn:hover { text-decoration: underline; }
.badge-new { background: #FFF3E0; color: #E65100; }
.badge-blacklist { background: #1a1a1a; color: #fff; margin-left: 8px; font-size: 11px; vertical-align: middle; }
.row-blacklisted { opacity: .82; }
.row-blacklisted .link-btn { color: var(--text-muted); }
.client-blacklist-banner {
  margin-bottom: 16px;
  border-color: #333;
  background: linear-gradient(135deg, #fafafa, #f0f0f0);
}
.client-blacklist-banner strong { display: block; margin-bottom: 6px; }
body.theme-dark .client-blacklist-banner {
  background: linear-gradient(135deg, #2a2a2a, #1f1f1f);
  border-color: #555;
}
body.theme-dark .badge-blacklist { background: #444; color: #fff; }

.confirm-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 440px;
  width: min(440px, calc(100vw - 32px));
  margin: auto;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
}
.confirm-dialog[open] {
  position: fixed;
  inset: 0;
  height: fit-content;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.confirm-dialog::backdrop {
  background: rgba(15, 20, 25, 0.45);
  backdrop-filter: blur(4px);
}
.confirm-dialog-inner { padding: 24px; }
.confirm-dialog-inner h3 { margin: 0 0 12px; font-size: 18px; }
.confirm-dialog-inner p { margin: 0 0 20px; color: var(--text-muted); line-height: 1.5; }
.confirm-dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.row-new { background: #F7FBF7; }
.phones-block { margin: 16px 0; }
.phone-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(140px, 1.4fr) auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.phone-row input {
  padding: 12px;
  border: 2px solid #E8E8E8;
  border-radius: var(--radius-sm);
  font-family: inherit;
  min-width: 0;
}
.phone-row .phone-input { width: 100%; }
.phone-row .phone-note-input { width: 100%; }
.phone-row .btn { flex-shrink: 0; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.info-grid span { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.info-grid p { margin-top: 4px; font-size: 14px; }
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item { display: flex; justify-content: space-between; padding: 12px; background: var(--card-bg); border-radius: var(--radius-sm); }
.period-filter { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.period-filter input { padding: 8px 12px; border: 2px solid #E8E8E8; border-radius: var(--radius-sm); font-family: inherit; }
.dot.client { background: var(--primary); }
.dot.investor { background: #7B1FA2; }
.manual-badge.fact { background: #E3F2FD; color: #1565C0; }

/* ??????? � ??????? ?????? */
@media (min-width: 1400px) {
  .header-inner,
  .dashboard-main {
    max-width: 1440px;
  }

  .categories-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ????? ??????????? � ????????? ?????? */
.privacy-fab {
  position: fixed;
  z-index: 350;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.privacy-fab[hidden] {
  display: none !important;
}

.privacy-fab svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.privacy-fab .icon-eye-off {
  display: none !important;
}

.privacy-fab .icon-eye-on {
  display: block !important;
}

body.privacy-active .privacy-fab .icon-eye-on {
  display: none !important;
}

body.privacy-active .privacy-fab .icon-eye-off {
  display: block !important;
}

/* Кнопка приватности — правый нижний угол */
.privacy-fab {
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(20px, env(safe-area-inset-right));
  top: auto;
  left: auto;
  padding: 12px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, #00B341, #009130);
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 179, 65, 0.45);
}

.privacy-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(0, 179, 65, 0.5);
}

.privacy-fab:active {
  transform: scale(0.96);
}

body.privacy-active .privacy-fab {
  background: linear-gradient(135deg, #FF9800, #F57C00);
  box-shadow: 0 8px 32px rgba(245, 124, 0, 0.5);
}

/* Режим приватности: интерфейс работает, размыты суммы, проценты и число клиентов */
body.privacy-active .pv,
body.privacy-active .pv-count {
  filter: blur(7px);
  user-select: none;
  cursor: default;
}

/* ??????? � ????? ? ???? ?????? */
@media (min-width: 769px) {
  .header-dash .header-inner {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .header-dash .toolbar-row {
    display: contents;
  }

  .header-dash #home-btn:not([hidden]) {
    display: inline-flex;
    width: auto;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-md);
  }

  .header-dash .search-bar {
    flex: 1;
    min-width: 240px;
  }
}

/* ??????? � ??????? ?????? ????? ?????? */
@media (max-width: 768px) {
  .privacy-fab {
    top: auto;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(16px, env(safe-area-inset-right));
    left: auto;
    padding: 14px 22px;
    min-height: 52px;
    font-size: 16px;
    border-radius: 999px;
  }

  body.privacy-active .privacy-fab {
    bottom: max(20px, env(safe-area-inset-bottom));
    top: auto;
  }
}

/* --- v10: ������ � �����, ������, ��������� ����/����, ���� --- */
.toolbar-start {
  position: relative;
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  min-width: 0;
  justify-self: start;
  align-self: start;
}

.toolbar-start-group {
  display: flex;
  flex-wrap: wrap;
  max-width: 100%;
  align-items: center;
  gap: 6px;
}

.header-dash .header-inner,
.header-dash .toolbar-row {
  overflow: visible;
}

.header-balance {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--icon-surface), var(--icon-surface-2));
  border: 2px solid var(--icon-border);
  border-radius: var(--radius-md);
  padding: 6px 12px 6px 8px;
  color: var(--primary-dark);
  max-width: 220px;
}

.header-balance svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--primary);
}

.header-balance-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 2px;
}

.header-balance strong {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 200px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  z-index: 120;
}

.search-bar-main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
  margin: 0;
  padding: 4px 4px 4px 14px;
  width: 100%;
}

.search-bar-main input {
  font-size: 15px;
  min-width: 0;
}

.search-bar-main .btn-search {
  padding: 8px 14px;
  min-height: 38px;
  min-width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.search-bar-main .btn-search svg {
  display: none;
  width: 17px;
  height: 17px;
}

.search-bar-main .btn-search-text {
  display: inline;
  letter-spacing: 0.01em;
}

.search-suggest {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-hover);
  max-height: min(360px, 55vh);
  overflow-y: auto;
  z-index: 130;
}

.search-suggest[hidden] {
  display: none !important;
}

.search-suggest-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.search-suggest-item:hover,
.search-suggest-item.active {
  background: var(--primary-light);
  box-shadow: inset 3px 0 0 var(--primary);
}

.search-suggest-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-light);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary-dark);
  overflow: hidden;
}

.search-suggest-icon svg {
  width: 36px;
  height: 36px;
}

.search-suggest-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.search-suggest-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-suggest-title b {
  font-weight: 800;
  color: var(--primary-dark);
}

.search-suggest-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-content: flex-end;
  min-width: 0;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.check-row input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.check-box {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 2px solid var(--icon-border);
  background: var(--card-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.check-box::after {
  content: '';
  width: 7px;
  height: 12px;
  border: solid transparent;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0.4);
  opacity: 0;
  margin-top: -2px;
  transition: all 0.18s ease;
}

.check-row:hover .check-box {
  border-color: var(--primary);
  background: var(--primary-light);
}

.check-row input:focus-visible + .check-box {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 179, 65, 0.18);
}

.check-row input:checked + .check-box {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 179, 65, 0.28);
}

.check-row input:checked + .check-box::after {
  border-color: #fff;
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.check-row input:checked ~ .check-label {
  color: var(--primary-dark);
}

.check-label {
  transition: color 0.2s ease;
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.rating-badge.rating-1 { background: #C8E6C9; color: #1B5E20; }
.rating-badge.rating-2 { background: #DCEDC8; color: #33691E; }
.rating-badge.rating-3 { background: #FFF9C4; color: #F57F17; }
.rating-badge.rating-4 { background: #FFE0B2; color: #E65100; }
.rating-badge.rating-5 { background: #FFCDD2; color: #B71C1C; }

.summary-card-rating {
  border: none;
  padding: 16px;
  text-align: center;
}

.summary-card-rating.rating-1 { background: #C8E6C9; color: #1B5E20; }
.summary-card-rating.rating-2 { background: #DCEDC8; color: #33691E; }
.summary-card-rating.rating-3 { background: #FFF9C4; color: #F57F17; }
.summary-card-rating.rating-4 { background: #FFE0B2; color: #E65100; }
.summary-card-rating.rating-5 { background: #FFCDD2; color: #B71C1C; }

.summary-card-rating span {
  color: inherit;
  opacity: 0.75;
  font-size: 12px;
  margin-bottom: 4px;
}

.summary-card-rating .summary-card-value-row {
  justify-content: center;
}

.summary-card-rating strong {
  display: inline-block;
  margin-top: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.1;
}

.summary-card-rating-edit-actions {
  justify-content: center;
}

.active-docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.active-doc-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px;
  background: #fff;
  border: 1px solid #E8EEE8;
  border-radius: 14px;
}

.active-doc-preview .doc-thumb,
.active-doc-preview .doc-file-icon {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
}

.active-doc-preview .doc-file-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #E8F5E9;
  color: #1B5E20;
  font-weight: 700;
  font-size: 12px;
}

.active-doc-body {
  min-width: 0;
  flex: 1;
}

.active-doc-body p {
  margin: 4px 0;
  font-size: 13px;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain-list li {
  padding: 8px 0;
  border-bottom: 1px solid #F0F0F0;
}

.rating-edit {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.rating-edit select {
  padding: 10px 14px;
  border: 2px solid #E8E8E8;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}

.btn-danger-outline {
  background: var(--card-bg);
  color: #C62828;
  border: 2px solid rgba(198, 40, 40, 0.25);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-outline:hover {
  background: rgba(198, 40, 40, 0.08);
}

.cal-cell.day-plan {
  background: var(--cal-plan-bg) !important;
  border-color: var(--cal-plan-border);
}

.cal-cell.day-paid {
  background: var(--cal-paid-bg) !important;
  border-color: var(--cal-paid-border);
}

.cal-cell.day-overdue {
  background: #FFEBEE !important;
  border-color: #E57373;
}

.cal-cell.day-late {
  background: #FFF9C4 !important;
  border-color: #FFB300;
}

.dot.plan { background: #F9A825; }
.dot.fact { background: #43A047; }

.cal-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.cal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cal-legend .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.cal-event.status-fact {
  background: var(--cal-event-fact-bg);
  border-left-color: #43A047;
  transition: background 0.45s ease, border-color 0.45s ease, transform 0.35s ease;
}

.cal-event.just-paid {
  animation: paidFlash 0.7s ease;
}

@keyframes paidFlash {
  0% { transform: scale(0.98); background: var(--cal-plan-bg); }
  50% { transform: scale(1.02); background: var(--cal-paid-bg); }
  100% { transform: scale(1); background: var(--cal-event-fact-bg); }
}

.cal-event-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.cal-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-thumb {
  width: 72px;
  height: 72px;
  border: none;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  cursor: zoom-in;
  background: #eee;
  flex-shrink: 0;
  position: relative;
}

.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.doc-thumb-hint {
  position: absolute;
  inset: auto 0 0 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 0;
  text-align: center;
  letter-spacing: 0.02em;
}

.doc-file-icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFEBEE;
  color: #C62828;
  font-size: 11px;
  font-weight: 800;
  border-radius: 10px;
  flex-shrink: 0;
}

.doc-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.doc-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.doc-preview-modal[hidden] {
  display: none !important;
}

.doc-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}

.doc-preview-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: min(920px, 96vw);
  max-height: 90vh;
  overflow: auto;
  z-index: 1;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.doc-preview-box img {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  margin: 0 auto 12px;
  border-radius: 12px;
  cursor: default;
}

.doc-preview-hint {
  text-align: center;
  margin: 0;
  font-size: 13px;
}

.doc-preview-x {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 24px;
  z-index: 2;
}

.upload-preview-box {
  width: min(720px, 96vw);
}

.upload-preview-title {
  margin: 0 0 6px;
  font-size: 20px;
}

.upload-preview-sub {
  margin: 0 0 16px;
  font-size: 14px;
}

.upload-preview-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow: auto;
  margin-bottom: 16px;
}

.upload-preview-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: #F7FAF7;
  border: 1px solid #E0EAE0;
  border-radius: 12px;
}

.upload-preview-item.is-error {
  background: #FFF5F5;
  border-color: #FFCDD2;
}

.upload-thumb {
  position: relative;
  width: 88px;
  height: 88px;
  border: none;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
  flex-shrink: 0;
  background: #ddd;
}

.upload-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.upload-thumb-zoom {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-preview-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.upload-preview-meta strong {
  font-size: 14px;
  word-break: break-all;
}

.upload-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* ??????? �????? ??????� */
.app-modal {
  position: fixed;
  inset: 0;
  z-index: 520;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.app-modal[hidden] {
  display: none !important;
}

.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.app-modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 28px 24px 22px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
  border: 1px solid #E8F5E9;
  animation: cardAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-modal-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
}

.app-modal-icon svg {
  width: 100%;
  height: 100%;
}

.app-modal-card h3 {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.app-modal-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 18px;
  line-height: 1.4;
}

.app-modal-input {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 16px;
  border: 2px solid #E8E8E8;
  border-radius: var(--radius-md);
  outline: none;
  background: var(--card-bg);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.app-modal-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 179, 65, 0.12);
}

.app-modal-error {
  color: #C62828;
  font-size: 13px;
  font-weight: 600;
  margin-top: 8px;
  text-align: center;
}

.app-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.app-modal-actions .btn {
  flex: 1;
}

/* ������ */
.task-composer {
  margin-bottom: 16px;
}

.task-composer > input[type="text"]#task-title {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  margin-bottom: 12px;
  background: var(--card-bg);
  color: var(--text);
}

.task-composer > input:focus {
  border-color: var(--primary);
}

.task-composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

.task-composer-row input {
  font-family: inherit;
  font-size: 14px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--card-bg);
  color: var(--text);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.25s ease;
  color: var(--text);
}

.task-item.pending {
  border-color: var(--border);
  background: var(--card-bg);
  border-left: 4px solid #9E9E9E;
}

.task-item.progress {
  border-color: rgba(249, 168, 37, 0.35);
  background: color-mix(in srgb, #FFFDE7 18%, var(--card-bg));
  border-left: 4px solid #F9A825;
}

.task-item.done {
  opacity: 0.45;
  background: var(--card-bg);
  border-color: var(--border);
  border-left: 4px solid #BDBDBD;
}

.task-item.done .task-body strong {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-item.late:not(.done) {
  border-color: rgba(239, 83, 80, 0.35);
  background: color-mix(in srgb, #FFF8F8 15%, var(--card-bg));
  border-left-color: #EF5350;
}

.task-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 8px;
}

.task-status-pending {
  background: #EEEEEE;
  color: #616161;
}

.task-status-progress {
  background: #FFF3CD;
  color: #F57F17;
}

.task-status-done {
  background: #E8F5E9;
  color: #2E7D32;
}

.task-assignee {
  display: block;
  margin: 4px 0;
  color: var(--text);
  font-size: 12px;
}

.task-assignee b {
  color: var(--primary-dark);
}

.task-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-body strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--text);
}

.task-body p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.task-body small {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ─── Kanban задачник (Bitrix-style) ─── */
.task-section-actions {
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#task-drawer-side-btn {
  font-size: 12px;
  white-space: nowrap;
}

.task-section-head {
  margin-bottom: 16px;
}

.task-kanban-wrap {
  overflow-x: auto;
  padding-bottom: 12px;
  margin: 0 -4px;
}

.task-kanban {
  display: flex;
  gap: 10px;
  min-height: 420px;
  min-width: min(100%, 1200px);
}

.task-kanban-col {
  flex: 0 0 168px;
  min-width: 168px;
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--card-bg) 92%, transparent);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

.task-kanban-col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 8px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  border-bottom: 3px solid transparent;
}

.task-kanban-col-head span {
  flex: 1;
}

.task-kanban-col-head strong {
  font-size: 12px;
  font-weight: 800;
  opacity: 0.75;
  min-width: 1.2em;
  text-align: right;
}

.task-col-add {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, currentColor 12%, transparent);
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.task-col-add:hover {
  background: color-mix(in srgb, currentColor 22%, transparent);
}

.head-overdue {
  background: var(--head-overdue-bg);
  color: var(--head-overdue-color);
  border-bottom-color: var(--head-overdue-border);
}

.head-today {
  background: var(--head-today-bg);
  color: var(--head-today-color);
  border-bottom-color: var(--head-today-border);
}

.head-this-week {
  background: var(--head-this-week-bg);
  color: var(--head-this-week-color);
  border-bottom-color: var(--head-this-week-border);
}

.head-next-week {
  background: var(--head-next-week-bg);
  color: var(--head-next-week-color);
  border-bottom-color: var(--head-next-week-border);
}

.head-no-deadline {
  background: var(--head-no-deadline-bg);
  color: var(--head-no-deadline-color);
  border-bottom-color: var(--head-no-deadline-border);
}

.head-later {
  background: var(--head-later-bg);
  color: var(--head-later-color);
  border-bottom-color: var(--head-later-border);
}

.head-done {
  background: var(--head-done-bg);
  color: var(--head-done-color);
  border-bottom-color: var(--head-done-border);
}

.task-kanban-col-body {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
  background: var(--bg);
  transition: background 0.2s;
}

.task-kanban-col-body.task-col-drop-target {
  background: color-mix(in srgb, var(--primary-light) 50%, var(--bg));
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
}

.task-col-empty {
  font-size: 11px;
  text-align: center;
  padding: 16px 4px;
}

.task-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 52px 10px 10px;
  cursor: grab;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.task-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.task-card-dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.task-card.is-done {
  opacity: 0.65;
}

.task-card-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: #FFEBEE;
  color: #C62828;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s, transform 0.15s;
  z-index: 2;
}

.task-card:hover .task-card-delete,
.task-card:focus-within .task-card-delete {
  opacity: 1;
}

.task-card-delete:hover {
  background: #C62828;
  color: #fff;
  transform: scale(1.08);
}

.task-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.task-card-priority {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.priority-low .task-card-priority { background: #9E9E9E; }
.priority-normal .task-card-priority { background: #42A5F5; }
.priority-high .task-card-priority { background: #EF5350; }

.task-card-deadline {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}

.task-card-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 8px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
}

.task-card-assignee {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-card-check,
.task-card-comments {
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.task-card-client {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  margin: -2px 0 6px;
  padding: 0;
  border: none;
  background: none;
  color: var(--primary-dark);
}

.task-card-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.task-quick-btn {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 4px 2px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.task-quick-btn:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--icon-border);
}

.task-card-move {
  position: absolute;
  top: 6px;
  right: 30px;
  width: 20px;
  height: 20px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 2;
}

.task-card:hover .task-card-move,
.task-card:focus-within .task-card-move {
  opacity: 1;
}

.task-card-move:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.task-move-menu {
  position: absolute;
  top: 28px;
  right: 6px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  padding: 4px;
  gap: 2px;
}

.task-move-item {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.task-move-item:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.task-card-debt-row {
  margin: -2px 0 6px;
}

.task-card-debt {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}

.task-co-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.task-co-picker-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.task-filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.task-search-bar {
  flex: 1;
  min-width: 220px;
}

.task-search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.task-quick-filters {
  flex-wrap: wrap;
}

.task-templates-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.task-templates-compact {
  margin-bottom: 0;
  margin-top: 10px;
  padding: 8px 10px;
}

.task-templates-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  margin-right: 4px;
}

.task-drawer-templates {
  margin-bottom: 12px;
}

.task-client-context {
  margin: -4px 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  border: 1px solid var(--icon-border);
  font-size: 12px;
}

.task-client-context-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.task-client-context-row span {
  color: var(--text-muted);
}

.task-client-panel .task-client-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 0;
}

.task-client-list-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.task-client-list-item:hover {
  border-color: var(--icon-border);
  transform: translateX(3px);
}

.task-client-list-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.task-client-list-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.cal-event-actions {
  margin-top: 8px;
}

.cal-task-btn {
  font-size: 11px !important;
  padding: 4px 10px !important;
}

/* Task drawer */
.task-drawer[hidden] {
  display: none !important;
}

.task-drawer:not([hidden]) {
  display: flex;
}

.task-drawer.task-drawer-right:not([hidden]) {
  justify-content: flex-end;
}

.task-drawer.task-drawer-left:not([hidden]) {
  justify-content: flex-start;
}

.task-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.task-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.task-drawer-panel {
  position: relative;
  width: min(480px, 100%);
  height: 100%;
  background: var(--card-bg);
  overflow: hidden;
}

.task-drawer-right .task-drawer-panel {
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.15);
  animation: taskDrawerInRight 0.25s ease;
}

.task-drawer-left .task-drawer-panel {
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.15);
  animation: taskDrawerInLeft 0.25s ease;
}

@keyframes taskDrawerInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes taskDrawerInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.task-drawer-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.task-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.task-drawer-head h3 {
  margin: 0;
  font-size: 18px;
}

.task-drawer-close {
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
}

.task-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.task-drawer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.task-drawer-foot-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.task-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.task-field-full {
  width: 100%;
}

.task-field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.task-drawer-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.task-drawer-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  outline: none;
}

.task-drawer-input:focus {
  border-color: var(--primary);
}

textarea.task-drawer-input {
  resize: vertical;
  min-height: 72px;
}

.task-drawer-section {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.task-drawer-section h4 {
  margin: 0 0 12px;
  font-size: 14px;
}

.task-checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}

.task-checklist-item input {
  flex-shrink: 0;
}

.task-checklist-item span {
  flex: 1;
}

.task-checklist-del {
  border: none;
  background: transparent;
  color: #C62828;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.task-checklist-add,
.task-comment-add {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: flex-start;
}

.task-checklist-add input {
  flex: 1;
}

.task-comment-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.task-comment-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.task-comment-head strong {
  font-size: 12px;
}

.task-comment-item p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.task-co-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.task-co-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  font-size: 12px;
}

.task-co-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #C62828;
  font-size: 14px;
  line-height: 1;
}

@media (max-width: 768px) {
  .task-card-delete,
  .task-card-move {
    opacity: 1;
  }

  .task-drawer-row {
    grid-template-columns: 1fr;
  }

  .task-kanban-col {
    flex: 0 0 240px;
    min-width: 240px;
  }
}

body.theme-dark .task-kanban-col {
  border-color: var(--border);
}

body.theme-dark .task-kanban-col-body {
  background: color-mix(in srgb, var(--card-bg) 60%, #000);
}

body.theme-dark .task-card {
  background: var(--card-bg);
  border-color: var(--border);
}

body.theme-dark .task-drawer-panel {
  background: var(--card-bg);
}

body.theme-dark .task-card-delete {
  background: #3a2020;
  color: #ff8a80;
}

body.theme-dark .task-card-delete:hover {
  background: #c62828;
  color: #fff;
}

body.theme-dark .task-card-client {
  color: var(--icon-accent);
}

body.theme-dark .task-quick-btn {
  background: color-mix(in srgb, var(--card-bg) 80%, #000);
  color: var(--text-muted);
}

body.theme-dark .task-quick-btn:hover {
  background: #1a2820;
  color: var(--icon-accent);
}

body.theme-dark .task-client-context {
  background: #1a2820;
  border-color: rgba(74, 222, 128, 0.25);
}

body.theme-dark .task-templates-bar {
  background: color-mix(in srgb, var(--card-bg) 92%, #000);
}

@media (max-width: 768px) {
  .toolbar-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "start end"
      "search search";
    gap: 10px;
    width: 100%;
  }

  .toolbar-start {
    grid-area: start;
    width: auto;
    justify-self: start;
    align-self: start;
  }

  .header-balance {
    max-width: none;
  }

  .toolbar-end {
    grid-area: end;
    width: auto;
  }

  .search-wrap {
    grid-area: search;
    max-width: none;
    margin: 0;
  }

  .search-bar-main {
    grid-area: auto;
    max-width: none;
    margin: 0;
    padding: 6px 6px 6px 14px;
  }

  .search-bar-main .btn-search-text {
    display: none;
  }

  .search-bar-main .btn-search svg {
    display: block;
  }

  .task-composer-row {
    grid-template-columns: 1fr;
  }

  .cal-header-actions {
    width: 100%;
  }

  .cal-header-actions .btn {
    flex: 1;
  }
}

@media (min-width: 769px) {
  .header-dash .toolbar-row {
    display: grid !important;
    grid-template-columns: minmax(180px, 1fr) minmax(320px, 560px) minmax(140px, 1fr);
    align-items: center;
    gap: 16px;
    width: 100%;
  }

  .header-dash .toolbar-start {
    justify-self: start;
  }

  .header-dash .search-wrap {
    justify-self: center;
    width: 100%;
    max-width: 560px;
  }

  .header-dash .search-bar-main {
    justify-self: stretch;
    width: 100%;
    max-width: none;
  }

  .header-dash .toolbar-end {
    justify-self: end;
  }
}

.client-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.client-metric {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
}
.client-metric span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.client-metric strong { font-size: 16px; font-weight: 800; color: var(--text); }
.client-metric.tone-red strong, .client-metric.tone-red span { color: #C62828; }
.client-metric.tone-green strong, .client-metric.tone-green span { color: #2E7D32; }
.tone-text-green { color: #2E7D32 !important; }
.tone-text-red { color: #C62828 !important; }
body.theme-dark .tone-text-green { color: #6ee7a0 !important; }
body.theme-dark .tone-text-red { color: #ff8a80 !important; }
.summary-card.highlight-plan {
  background: var(--primary-light);
  border: 1px solid var(--icon-border);
}
.summary-card small { display: block; margin-top: 6px; font-size: 12px; opacity: 0.8; }
.doc-cat-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid #EEF2EE; }
.doc-cat-block h4 { margin: 0; font-size: 15px; }
tr.row-current td { background: var(--primary-light); }
tr.row-selected td { outline: 2px solid #81C784; outline-offset: -2px; }
.stats-plan-hero .summary-card strong { font-size: 22px; }

.doc-preview-box-wide { width: min(960px, 96vw); }
.doc-preview-title { margin: 0 36px 12px 0; font-weight: 700; word-break: break-all; }
.doc-preview-body { min-height: 120px; }
.doc-preview-frame {
  width: 100%;
  height: min(70vh, 720px);
  border: 1px solid #E0EAE0;
  border-radius: 12px;
  background: #fafafa;
}
.doc-preview-text {
  max-height: 70vh;
  overflow: auto;
  padding: 14px;
  background: #F7FAF7;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.45;
}
.doc-preview-fallback {
  text-align: center;
  padding: 24px 12px;
}
.doc-preview-fallback .btn { margin-top: 10px; display: inline-flex; }
button.doc-file-icon, .upload-file-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
}
button.doc-file-icon:hover, .upload-file-btn:hover { filter: brightness(0.95); }

.doc-preview-action {
  flex-shrink: 0;
  white-space: nowrap;
}
.doc-item .doc-preview-action {
  margin-left: auto;
}

/* Stats KPI icons + Excel table */
.stats-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-kpi-card {
  min-height: 110px;
}

.excel-panel-head {
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.excel-portfolio-return {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--primary-light);
  border: 1px solid var(--icon-border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}

.excel-portfolio-return small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.excel-portfolio-return strong {
  font-size: 22px;
  color: var(--primary);
}

.excel-return-icon svg {
  width: 40px;
  height: 40px;
}

.excel-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
}

.excel-year-table thead th {
  background: #1B5E20;
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  padding: 10px 8px;
}

.excel-year-table .excel-month {
  font-weight: 700;
  background: var(--primary-light);
  white-space: nowrap;
}

.excel-year-table .excel-month b {
  display: block;
  font-size: 13px;
}

/* Период месяца — подсказкой под названием */
.excel-year-table .excel-month small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.excel-year-table tfoot .excel-year-totals .excel-month small {
  color: rgba(255, 255, 255, 0.75);
}

.excel-year-table tfoot .excel-year-totals td {
  background: #2E7D32;
  color: #fff;
  font-weight: 700;
  border-top: 2px solid #1B5E20;
}

.excel-year-table .excel-zero {
  color: var(--text-muted);
  text-align: center;
}

.year-archive-footer {
  margin-top: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  padding: 18px 18px 16px;
}

.year-archive-footer h3 {
  margin: 0 0 14px;
  color: var(--primary);
  font-size: 18px;
}

.year-archive-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.year-archive-grid div {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-width: 0;
}

.year-archive-grid span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.year-archive-grid strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.year-archive-pokazateli {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.year-archive-pokazateli-note {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Показатели — тот же стиль карточек, ровная сетка */
.pokaz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px;
}

.pokaz-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 3px solid #BDBDBD;
}

.pokaz-row {
  min-width: 0;
}

.pokaz-row span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pokaz-row strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  word-break: break-word;
}

.pokaz-card.tone-balance { border-left-color: #66BB6A; }
.pokaz-card.tone-assets { border-left-color: #90A4AE; }
.pokaz-card.tone-liab { border-left-color: #FF8A65; }
.pokaz-card.tone-klabs { border-left-color: #64B5F6; }
.pokaz-card.tone-cost { border-left-color: #FFD54F; }
.pokaz-card.tone-person { border-left-color: #90A4AE; }

@media (max-width: 1100px) {
  .year-archive-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .year-archive-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .pokaz-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* старый excel-strip больше не используем как основу */
#excel-metrics-host,
.excel-metrics-strip {
  display: none;
}

.stats-archive-panel {
  margin-top: 8px;
}

.overdue-inline {
  display: block;
  margin-top: 6px;
  color: #C62828;
  font-weight: 600;
  font-size: 12px;
}

.client-metric small.overdue-inline {
  font-weight: 600;
}

.client-filter {
  margin-bottom: 20px;
}

.client-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.client-filter-search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
}

.client-filter-search:focus-within {
  border-color: var(--primary);
}

.client-filter-search svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.client-filter-search input {
  border: none;
  outline: none;
  padding: 10px 0;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  background: transparent;
  color: var(--text);
}

.client-filter-select {
  min-width: 140px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text);
}

.client-filter-sort {
  min-width: 170px;
  font-weight: 600;
}

.client-filter-tabs {
  margin-bottom: 8px;
}

.client-filter-meta {
  margin: 0;
  font-size: 13px;
}

/* Excel Показатели strip (как нижняя строка в Excel) */
#excel-metrics-host {
  margin: 8px 0 20px;
  overflow-x: auto;
}

.excel-metrics-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  min-width: max-content;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 12px;
}

.excel-metric-cell {
  display: flex;
  flex-direction: column;
  min-width: 118px;
  border-right: 1px solid var(--border);
  flex: 0 0 auto;
}

.excel-metric-cell:last-child {
  border-right: none;
}

.excel-metric-top,
.excel-metric-bot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  line-height: 1.25;
}

.excel-metric-top {
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.excel-metric-bot {
  min-height: 48px;
}

.excel-metric-top span,
.excel-metric-bot span {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.excel-metric-top strong,
.excel-metric-bot strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.metric-balance {
  background: var(--card-bg);
  min-width: 100px;
}

.metric-balance .excel-metric-top {
  border-bottom: none;
  min-height: 96px;
  justify-content: center;
}

.metric-assets {
  background: var(--card-hover);
}

.metric-liab {
  background: color-mix(in srgb, #fce4d6 18%, var(--card-bg));
}

.metric-liab-split .excel-metric-top {
  min-height: 24px;
  padding: 4px 8px;
  border-bottom: none;
}

.metric-liab-span .excel-metric-top {
  border-bottom: none;
  min-height: 96px;
  justify-content: center;
}

.metric-klabs {
  background: color-mix(in srgb, #ddebf7 22%, var(--card-bg));
}

.metric-cost {
  background: color-mix(in srgb, #fff2cc 20%, var(--card-bg));
}

.metric-person {
  background: color-mix(in srgb, #d6dce4 22%, var(--card-bg));
}

@media (max-width: 900px) {
  .excel-metrics-strip {
    font-size: 11px;
  }
  .excel-metric-cell {
    min-width: 104px;
  }
}

/* ─── История изменений ─── */
.history-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.history-search {
  flex: 1 1 260px;
  min-width: 200px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

.history-search:focus {
  outline: none;
  border-color: var(--primary);
}

.history-offline {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--primary-light);
  border: 1px solid var(--icon-border);
  color: var(--text-muted);
  font-size: 13px;
}

.history-offline[hidden] {
  display: none;
}

.history-count {
  margin: 0 0 10px;
  font-size: 13px;
}

.history-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.history-badge-create {
  background: #E8F5E9;
  color: #1B5E20;
}

.history-badge-delete {
  background: #FFEBEE;
  color: #B71C1C;
}

.history-badge-update {
  background: #E3F2FD;
  color: #0D47A1;
}

.data-table tr.history-day td {
  background: var(--card-hover);
  font-weight: 700;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 16px;
}

.data-table tr.history-pending {
  background: color-mix(in srgb, var(--primary-light) 50%, var(--card-bg));
}

.history-time b {
  display: block;
  font-size: 14px;
}

.history-time small {
  color: var(--text-muted);
  font-size: 11px;
}

/* ─── Роли пользователей ─── */
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.roles-col ul {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

.roles-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.table-actions {
  white-space: normal;
}

.table-actions .btn {
  margin: 2px 2px 2px 0;
}

/* ─── Таблица клиентов как в Excel ─── */
.clients-excel-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.clients-excel-table {
  min-width: 1200px;
  font-size: 13px;
}

.clients-excel-table th,
.clients-excel-table td {
  white-space: nowrap;
}

.clients-excel-table tfoot .clients-totals-row {
  background: var(--primary-light);
  font-weight: 600;
}

.clients-excel-table tfoot td {
  border-top: 2px solid var(--primary);
}

/* ─── Переключатель темы ─── */
.theme-toggle-btn .icon-theme-sun {
  display: none;
}

body.theme-dark .theme-toggle-btn .icon-theme-moon {
  display: none;
}

body.theme-dark .theme-toggle-btn .icon-theme-sun {
  display: block;
}

.header-nav .theme-toggle-btn {
  margin-left: 8px;
}

/* ─── Ночная тема ─── */
body.theme-dark {
  --bg: #0f1419;
  --card-bg: #1a222d;
  --card-hover: #222c3a;
  --text: #e8edf2;
  --text-muted: #9aa8b8;
  --primary-light: #1a3d28;
  --primary-dark: #6ee7a0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 12px 40px rgba(0, 179, 65, 0.12);
  --border: rgba(255, 255, 255, 0.08);
  --icon-surface: #1e2d24;
  --icon-surface-2: #243028;
  --icon-accent: #4ade80;
  --icon-accent-2: #6ee7a0;
  --icon-accent-3: #86efac;
  --icon-muted: #3d5c48;
  --icon-on-accent: #0f1419;
  --icon-warn: #fb923c;
  --icon-border: rgba(74, 222, 128, 0.25);
  --cal-border: rgba(255, 255, 255, 0.08);
  --cal-has-events-bg: #222c3a;
  --cal-plan-bg: #222c3a;
  --cal-plan-border: rgba(249, 168, 37, 0.35);
  --cal-paid-bg: #1a3d28;
  --cal-paid-border: rgba(74, 222, 128, 0.55);
  --cal-overdue-bg: #3a2020;
  --cal-overdue-border: #ff5252;
  --cal-late-bg: #3d3520;
  --cal-late-border: #fbbf24;
  --cal-client-pending-bg: #3a2818;
  --cal-client-pending-border: #ffb74d;
  --cal-investor-pending-bg: #2a1a32;
  --cal-investor-pending-border: #ce93d8;
  --cal-paid-amount: #81c784;
  --cal-overdue-amount: #ff8a80;
  --cal-late-amount: #ffb74d;
  --cal-event-plan-bg: #222c3a;
  --cal-event-fact-bg: #1a2820;
  --cal-badge-plan-bg: #3d3520;
  --cal-badge-plan-color: #fbbf24;
  --toast-bg: #1a2820;
  --toast-color: #e8f5e9;
  --toast-border: rgba(74, 222, 128, 0.35);
  --head-overdue-bg: #2a1e1e;
  --head-overdue-color: #ff8a80;
  --head-overdue-border: #ef5350;
  --head-today-bg: #1a2820;
  --head-today-color: #81c784;
  --head-today-border: var(--icon-accent);
  --head-this-week-bg: #1a2430;
  --head-this-week-color: #90caf9;
  --head-this-week-border: #42a5f5;
  --head-next-week-bg: #1a2828;
  --head-next-week-color: #80cbc4;
  --head-next-week-border: #26a69a;
  --head-no-deadline-bg: #252830;
  --head-no-deadline-color: #b0bec5;
  --head-no-deadline-border: #78909c;
  --head-later-bg: #231e2e;
  --head-later-color: #b39ddb;
  --head-later-border: #7e57c2;
  --head-done-bg: #2a2a2a;
  --head-done-color: #bdbdbd;
  --head-done-border: #757575;
  --search-bg: rgba(255, 255, 255, 0.07);
  --search-border: rgba(255, 255, 255, 0.16);
  color-scheme: dark;
}

body.theme-dark .bg-blobs {
  opacity: 0.12;
}

body.theme-dark .blob-1 { background: #1a3d28; }
body.theme-dark .blob-2 { background: #1e3344; }
body.theme-dark .blob-3 { background: #243040; }

body.theme-dark .header,
body.theme-dark .login-card,
body.theme-dark .panel-card,
body.theme-dark .stat-card,
body.theme-dark .category-card,
body.theme-dark .summary-card,
body.theme-dark .client-filter,
body.theme-dark .login-card-icon svg rect {
  background: var(--card-bg);
  border-color: var(--border);
}

body.theme-dark .search-bar {
  /* Прозрачный фон — поле принимает цвет полоски вокруг и не выделяется
     тёмным прямоугольником; форму обозначает только мягкая рамка. */
  background: transparent;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

body.theme-dark .search-bar:focus-within {
  border-color: rgba(74, 222, 128, 0.4);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.1);
}

/* Поле ввода поиска не должно иметь собственный тёмный фон (#121820 от общего
   правила body.theme-dark input) — иначе внутри полоски виден тёмный прямоугольник.
   Делаем его прозрачным, чтобы оно сливалось с полоской поиска. */
body.theme-dark .search-bar input {
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

body.theme-dark .search-suggest {
  background: var(--card-bg);
  border-color: var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

body.theme-dark .more-menu {
  background: var(--card-bg);
  border-color: var(--border);
  box-shadow: none;
}

body.theme-dark .more-menu-balance {
  background: #1a2820;
  border-color: rgba(74, 222, 128, 0.25);
}

body.theme-dark .more-menu-item:hover {
  background: rgba(74, 222, 128, 0.1);
}

body.theme-dark .client-filter-search,
body.theme-dark .client-filter-select {
  background: #121820;
  border-color: var(--border);
}

body.theme-dark .balance-item {
  background: #1a3d28;
  border-color: var(--icon-border);
}

body.theme-dark .balance-item strong {
  color: var(--icon-accent);
}

body.theme-dark .check-row input:checked ~ .check-label {
  color: var(--icon-accent);
}

body.theme-dark .header {
  background: rgba(26, 34, 45, 0.92);
  backdrop-filter: blur(12px);
}

body.theme-dark .data-table th {
  background: #1e2a22;
  color: #b8e6c8;
}

body.theme-dark .data-table td {
  border-color: var(--border);
}

body.theme-dark .data-table tbody tr:hover {
  background: var(--card-hover);
}

body.theme-dark .clients-excel-table tfoot .clients-totals-row {
  background: #1e2a22;
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea {
  background: #121820;
  color: var(--text);
  border-color: var(--border);
}

body.theme-dark .field-input-wrap input {
  background: #121820;
}

body.theme-dark .btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

body.theme-dark .btn-ghost:hover {
  background: var(--card-hover);
  color: var(--text);
}

body.theme-dark .filter-tabs .tab {
  background: #121820;
  border-color: var(--border);
  color: var(--text-muted);
}

body.theme-dark .filter-tabs .tab.active,
body.theme-dark .filter-tabs .tab:hover {
  background: var(--primary-light);
  color: #b8e6c8;
}

body.theme-dark .doc-preview-box,
body.theme-dark .app-modal-card {
  background: var(--card-bg);
  color: var(--text);
}

body.theme-dark .active-doc-card {
  background: var(--card-bg);
  border-color: var(--border);
}

body.theme-dark .app-modal-input {
  background: #121820;
  color: var(--text);
  border-color: var(--border);
}

body.theme-dark .app-modal-input:focus {
  background: #121820;
}

body.theme-dark .upload-preview-item {
  background: color-mix(in srgb, var(--card-bg) 80%, #000);
  border-color: var(--border);
}

body.theme-dark .upload-preview-item.is-error {
  background: #2a1e1e;
  border-color: #ff8a80;
}

body.theme-dark .doc-preview-frame,
body.theme-dark .doc-preview-text {
  background: color-mix(in srgb, var(--card-bg) 80%, #000);
  color: var(--text);
  border-color: var(--border);
}

body.theme-dark .privacy-fab {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

body.theme-dark .row-overdue {
  background: rgba(255, 82, 82, 0.08);
}

body.theme-dark .row-new {
  background: rgba(0, 179, 65, 0.08);
}

body.theme-dark .data-table tbody tr.row-new:hover {
  background: var(--card-hover);
}

body.theme-dark .badge-new {
  background: rgba(230, 81, 0, 0.22);
  color: #ffb74d;
}

body.theme-dark .calendar-main,
body.theme-dark .calendar-side,
body.theme-dark .cal-add-form {
  background: var(--card-bg);
  border-color: var(--cal-border);
}

body.theme-dark .cal-cell {
  background: var(--card-bg);
  border-color: transparent;
}

body.theme-dark .cal-cell.has-events {
  background: var(--cal-has-events-bg) !important;
  border-color: rgba(255, 255, 255, 0.06);
}

body.theme-dark .cal-cell.day-plan {
  background: var(--cal-plan-bg) !important;
  border-color: var(--cal-plan-border) !important;
}

body.theme-dark .cal-cell.day-paid {
  background: #1a2820 !important;
  border-color: #43a047 !important;
}

body.theme-dark .cal-cell.day-overdue {
  background: #2a1e1e !important;
  border-color: #ef5350 !important;
}

body.theme-dark .cal-cell.day-late {
  background: #4a3d00 !important;
  border-color: #ffca28 !important;
}

body.theme-dark .cal-cell.selected {
  background: var(--primary-light) !important;
  border-color: var(--icon-accent) !important;
}

body.theme-dark .cal-cell:hover {
  background: var(--card-hover) !important;
  border-color: var(--icon-accent);
}

body.theme-dark .cal-cell.day-plan:hover,
body.theme-dark .cal-cell.day-paid:hover,
body.theme-dark .cal-cell.day-overdue:hover,
body.theme-dark .cal-cell.day-late:hover,
body.theme-dark .cal-cell.has-events:hover {
  filter: brightness(1.08);
}

body.theme-dark .cal-cell.today .cal-day {
  background: var(--icon-accent);
  color: var(--icon-on-accent);
}

body.theme-dark .cal-count {
  background: var(--icon-accent);
  color: var(--icon-on-accent);
}

body.theme-dark .cal-event {
  color: var(--text);
}

body.theme-dark .cal-event-text,
body.theme-dark .cal-event-date,
body.theme-dark .cal-event-fact,
body.theme-dark .cal-event-comment {
  color: var(--text);
}

body.theme-dark .cal-event-date,
body.theme-dark .cal-event-fact,
body.theme-dark .cal-event-comment,
body.theme-dark .cal-event-split {
  color: var(--text-muted);
}

body.theme-dark .cal-event.cal-entity-client.status-pending .cal-event-amount {
  color: #ffb74d;
}

body.theme-dark .cal-event.cal-entity-investor.status-pending .cal-event-amount {
  color: #ce93d8;
}

body.theme-dark .cal-event .manual-badge.fact {
  background: #1a3d28 !important;
  color: #81c784 !important;
}

body.theme-dark .cal-event .manual-badge.overdue {
  background: #3a2020 !important;
  color: #ff8a80 !important;
}

body.theme-dark .cal-event .manual-badge.late {
  background: #6d5c00 !important;
  color: #ffeb3b !important;
}

body.theme-dark .cal-event .badge-client-cal {
  background: #3a2818 !important;
  color: #ffb74d !important;
}

body.theme-dark .cal-event .badge-investor-cal {
  background: #2a1a32 !important;
  color: #ce93d8 !important;
}

body.theme-dark .cal-event .manual-badge.plan {
  background: var(--cal-badge-plan-bg) !important;
  color: var(--cal-badge-plan-color) !important;
}

body.theme-dark .cal-event.expense .cal-event-amount {
  color: #ff8a80;
}

body.theme-dark .cal-edit {
  background: #1e3a5f;
  color: #93c5fd;
}
body.theme-dark .cal-edit:hover {
  background: #2563eb;
  color: #fff;
}
body.theme-dark .cal-delete {
  background: #3a2020;
  color: #ff8a80;
}

body.theme-dark .cal-delete:hover {
  background: #c62828;
  color: #fff;
}

body.theme-dark .cal-sum.expense strong {
  color: #ff8a80;
}

body.theme-dark .cal-sum.net strong {
  color: var(--icon-accent);
}

body.theme-dark .flow-sticky-panel {
  background: color-mix(in srgb, var(--card-bg) 94%, transparent);
  border-color: var(--border);
}

body.theme-dark .flow-page .flow-table-body-wrap {
  background: var(--card-bg);
  border-color: var(--border);
}

body.theme-dark .stat-card-icon svg,
body.theme-dark .category-card-icon svg,
body.theme-dark .stat-icon svg,
body.theme-dark .login-card-icon svg,
body.theme-dark .app-modal-icon svg {
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
}

body.theme-dark .header-balance {
  color: var(--icon-accent);
}

body.theme-dark .btn-export-excel {
  box-shadow: 0 4px 14px rgba(74, 222, 128, 0.15);
}

body.theme-dark .excel-return-icon,
body.theme-dark .excel-return-icon svg {
  color: var(--icon-accent);
}

body.theme-dark .excel-year-table thead th {
  background: #1a3d28;
  color: var(--text);
}

body.theme-dark .excel-year-table .excel-month {
  background: #1e2a22;
  color: var(--text);
}

body.theme-dark .excel-year-table tfoot .excel-year-totals td {
  background: #1e3d28;
  color: var(--text);
  border-top-color: var(--icon-accent);
}

body.theme-dark tr.row-current td {
  background: #1a3d28 !important;
}

body.theme-dark .summary-card.highlight-plan {
  background: var(--primary-light);
  border-color: var(--icon-border);
}

body.theme-dark .year-archive-footer h3 {
  color: var(--icon-accent);
}

body.theme-dark .pokaz-card.tone-balance { background: #1a2820; }
body.theme-dark .pokaz-card.tone-assets { background: #222830; }
body.theme-dark .pokaz-card.tone-liab { background: #2a221e; }
body.theme-dark .pokaz-card.tone-klabs { background: #1e2838; }
body.theme-dark .pokaz-card.tone-cost { background: #2a2618; }
body.theme-dark .pokaz-card.tone-person { background: #222830; }

body.theme-dark .metric-balance { background: #1a222d; }
body.theme-dark .metric-assets { background: #222830; }
body.theme-dark .metric-liab { background: #2a221e; }
body.theme-dark .metric-klabs { background: #1e2838; }
body.theme-dark .metric-cost { background: #2a2618; }
body.theme-dark .metric-person { background: #222830; }

body.theme-dark .btn-danger-outline {
  background: rgba(198, 40, 40, 0.12);
  color: #ff8a80;
  border-color: rgba(255, 138, 128, 0.35);
}

body.theme-dark .btn-danger-outline:hover {
  background: rgba(198, 40, 40, 0.22);
}

body.theme-dark .data-table tr.history-day td {
  background: #1e2a22;
  color: #9aa8b8;
}

body.theme-dark .data-table tr.history-pending {
  background: rgba(249, 168, 37, 0.08);
}

body.theme-dark .history-badge-create {
  background: #1a3d28;
  color: #6ee7a0;
}

body.theme-dark .history-badge-delete {
  background: rgba(198, 40, 40, 0.2);
  color: #ff8a80;
}

body.theme-dark .history-badge-update {
  background: #1e2838;
  color: #90caf9;
}

body.theme-dark .history-offline {
  background: #2a2618;
  border-color: rgba(249, 168, 37, 0.3);
  color: #fbbf24;
}

body.theme-dark .client-metric {
  background: #121820;
  border-color: var(--border);
}

body.theme-dark .client-metric.tone-red strong,
body.theme-dark .client-metric.tone-red span {
  color: #ff8a80;
}

body.theme-dark .client-metric.tone-green strong,
body.theme-dark .client-metric.tone-green span {
  color: #6ee7a0;
}

body.theme-dark .client-metric small.overdue-inline {
  color: #ff8a80;
}

body.theme-dark .summary-card-rating.rating-1 { background: #1a3d28; color: #6ee7a0; }
body.theme-dark .summary-card-rating.rating-2 { background: #1e3320; color: #86efac; }
body.theme-dark .summary-card-rating.rating-3 { background: #2a2618; color: #fbbf24; }
body.theme-dark .summary-card-rating.rating-4 { background: #2a2218; color: #fb923c; }
body.theme-dark .summary-card-rating.rating-5 { background: #2a1e1e; color: #ff8a80; }

body.theme-dark .rating-badge.rating-1 { background: #1a3d28; color: #6ee7a0; }
body.theme-dark .rating-badge.rating-2 { background: #1e3320; color: #86efac; }
body.theme-dark .rating-badge.rating-3 { background: #2a2618; color: #fbbf24; }
body.theme-dark .rating-badge.rating-4 { background: #2a2218; color: #fb923c; }
body.theme-dark .rating-badge.rating-5 { background: #2a1e1e; color: #ff8a80; }

body.theme-dark .task-item.pending {
  background: #121820;
  border-left-color: #6b7280;
}

body.theme-dark .task-item.progress {
  background: #2a2618;
  border-left-color: #f9a825;
}

body.theme-dark .task-item.late:not(.done) {
  background: #2a1e1e;
  border-left-color: #ef5350;
}

body.theme-dark .task-status-pending {
  background: #2a3038;
  color: #9aa8b8;
}

body.theme-dark .task-status-progress {
  background: #3d3520;
  color: #fbbf24;
}

body.theme-dark .task-status-done {
  background: #1a3d28;
  color: #6ee7a0;
}

body.theme-dark .task-composer > input[type="text"]#task-title,
body.theme-dark .task-composer-row input {
  background: #121820;
  border-color: var(--border);
  color: var(--text);
}


/* ══════════════════════════ Мессенджер ══════════════════════════ */
.msgr-app {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  height: min(720px, calc(100vh - 220px));
  min-height: 480px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.msgr-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  min-height: 0;
}

.msgr-sidebar-head {
  padding: 18px 18px 6px;
}
.msgr-sidebar-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.msgr-contacts {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.msgr-empty-contacts {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.msgr-contact {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background .15s;
  margin-bottom: 2px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.msgr-contact:hover { background: var(--card-hover); }
.msgr-contact.active { background: var(--primary-light); }

.msgr-avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .3px;
}

.msgr-contact-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.msgr-contact-row1, .msgr-contact-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.msgr-contact-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msgr-contact-time {
  font-size: 11px;
  color: var(--text-muted);
  flex: none;
}
.msgr-contact-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msgr-badge {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.msgr-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.msgr-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}
.msgr-empty-icon { width: 84px; height: 84px; opacity: .85; }
.msgr-empty-icon svg { width: 100%; height: 100%; }
.msgr-empty p { margin: 0; font-size: 14px; max-width: 260px; }

.msgr-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.msgr-back {
  display: none;
  width: 34px;
  height: 34px;
  border: none;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.msgr-back svg { width: 18px; height: 18px; }
.msgr-header-sub { font-size: 12px; color: var(--text-muted); }
.msgr-contact-presence {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.msgr-contact-presence .presence-label.is-online { color: var(--primary); }

.presence-label { font-size: inherit; color: var(--text-muted); }
.presence-label.is-online { color: var(--primary); font-weight: 600; }

.presence-avatar-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.presence-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3ecf6e;
  border: 2px solid var(--card-bg, #fff);
  box-sizing: border-box;
}

.msgr-header-info { display: flex; flex-direction: column; min-width: 0; }
.msgr-header-name { font-weight: 700; font-size: 15px; }

.msgr-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background:
    radial-gradient(circle at 20% 10%, var(--card-bg) 0%, transparent 55%),
    var(--bg);
}

.msgr-empty-thread {
  margin: auto;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.msgr-day-sep {
  text-align: center;
  margin: 14px 0 10px;
}
.msgr-day-sep span {
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
}

.msgr-bubble-row {
  display: flex;
  margin: 3px 0;
}
.msgr-bubble-row.mine { justify-content: flex-end; }
.msgr-bubble-row.theirs { justify-content: flex-start; }

.msgr-bubble {
  position: relative;
  max-width: min(72%, 440px);
  padding: 9px 34px 9px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.42;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.msgr-bubble.mine {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msgr-bubble.theirs {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msgr-bubble.is-voice { padding-right: 34px; }

.msgr-bubble-text { white-space: pre-wrap; word-break: break-word; }

.msgr-bubble-meta {
  display: block;
  margin-top: 4px;
  font-size: 10.5px;
  opacity: .75;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}
.msgr-ticks { display: inline-flex; width: 14px; height: 14px; }
.msgr-ticks svg { width: 100%; height: 100%; }
.msgr-ticks.read { color: #bff7d6; }

.msgr-bubble-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: rgba(0,0,0,.12);
  color: inherit;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: .5;
  transition: opacity .15s;
}
.msgr-bubble-del svg { width: 11px; height: 11px; }
.msgr-bubble-row.mine:hover .msgr-bubble-del,
.msgr-bubble-del:focus-visible { opacity: 1; }

/* ─ Голосовое сообщение ─ */
.msgr-voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  padding: 2px 0;
}
.msgr-voice-play {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msgr-bubble.mine .msgr-voice-play { background: rgba(255,255,255,.22); color: #fff; }
.msgr-bubble.theirs .msgr-voice-play { background: var(--primary-light); color: var(--primary-dark); }
.msgr-voice-play svg { width: 15px; height: 15px; }

.msgr-voice-wave {
  position: relative;
  flex: 1;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
}
.msgr-voice-wave i {
  flex: 1;
  min-width: 2px;
  max-width: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: .35;
}
.msgr-bubble.mine .msgr-voice-wave i { background: #fff; }
.msgr-bubble.theirs .msgr-voice-wave i { background: var(--primary); }
.msgr-voice-progress {
  position: absolute;
  inset: 0;
  width: 0%;
  overflow: hidden;
  display: flex;
  align-items: center;
  pointer-events: none;
}
.msgr-voice-duration {
  flex: none;
  font-size: 11px;
  opacity: .8;
  font-variant-numeric: tabular-nums;
}

/* ─ Фото в чате ─ */
.msgr-image-bubble {
  display: block;
  border: none;
  padding: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  max-width: 260px;
  line-height: 0;
}
.msgr-image-bubble img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
}

/* ─ Файл в чате ─ */
.msgr-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  max-width: 280px;
  padding: 2px 0;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.msgr-file-icon {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .3px;
}
.msgr-bubble.mine .msgr-file-icon { background: rgba(255,255,255,.22); color: #fff; }
.msgr-bubble.theirs .msgr-file-icon { background: var(--primary-light); color: var(--primary-dark); }
.msgr-file-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.msgr-file-body strong {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.msgr-file-body small {
  font-size: 11px;
  opacity: .75;
}

/* ─ Композер ─ */
.msgr-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex: none;
  position: relative;
}
.msgr-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  max-height: 120px;
  line-height: 1.4;
  outline: none;
}
.msgr-input:focus { border-color: var(--primary); }

.msgr-btn-mic[hidden], .msgr-btn-send[hidden], .msgr-btn-attach[hidden] {
  display: none !important;
}
.msgr-btn-mic, .msgr-btn-send, .msgr-btn-attach {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, background .15s;
}
.msgr-btn-mic, .msgr-btn-attach { background: var(--card-bg); color: var(--text-muted); }
.msgr-btn-mic:hover, .msgr-btn-attach:hover { background: var(--card-hover); color: var(--primary-dark); }
.msgr-btn-attach:disabled { opacity: .5; cursor: default; }
.msgr-btn-send { background: var(--primary); color: #fff; }
.msgr-btn-send:hover { background: var(--primary-dark); transform: translateY(-1px); }
.msgr-btn-mic svg, .msgr-btn-send svg { width: 19px; height: 19px; }
.msgr-btn-attach svg { width: 18px; height: 18px; }

.msgr-rec-live[hidden] {
  display: none !important;
}
.msgr-rec-live {
  position: absolute;
  inset: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 14px;
}
.msgr-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red, #FF5252);
  animation: msgrPulse 1.1s ease-in-out infinite;
}
@keyframes msgrPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.75); }
}
.msgr-rec-timer { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.msgr-rec-hint { font-size: 12.5px; color: var(--text-muted); flex: 1; }
.msgr-rec-cancel {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msgr-rec-cancel:hover { background: rgba(255,82,82,.12); color: var(--red, #FF5252); }
.msgr-rec-cancel svg { width: 14px; height: 14px; }
.msgr-rec-stop {
  flex: none;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msgr-rec-stop:hover { background: var(--primary-dark); }
.msgr-rec-stop svg { width: 14px; height: 14px; }

/* ─ Адаптив ─ */
@media (max-width: 860px) {
  .msgr-app {
    grid-template-columns: 1fr;
    height: min(680px, calc(100vh - 180px));
  }
  .msgr-sidebar { border-right: none; }
  .msgr-main { display: none; }
  .msgr-app.show-thread .msgr-sidebar { display: none; }
  .msgr-app.show-thread .msgr-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
  }
  .msgr-back { display: inline-flex; }
  .msgr-bubble { max-width: 84%; }
}

/* ─ Тёмная тема ─ */
body.theme-dark .msgr-bubble.theirs { background: var(--card-bg); border-color: var(--border); }
body.theme-dark .msgr-badge { color: #0f1419; }
body.theme-dark .msgr-messages {
  background:
    radial-gradient(circle at 20% 10%, var(--card-hover) 0%, transparent 55%),
    var(--bg);
}

/* ─ CRM в левом меню ─ */
.more-menu {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ══════════════════════════ CRM ══════════════════════════ */
.crm-shell {
  animation: fadeIn 0.35s ease;
}

.crm-page-head.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.crm-page-head-text { flex: 1; min-width: 200px; }
.crm-title { margin-bottom: 6px; }
.crm-sub { color: var(--text-muted); font-size: 14px; margin: 0; line-height: 1.45; }
.crm-page-actions { flex-shrink: 0; }

.crm-stats { margin-bottom: 28px; }
.crm-stat-card { border: 1px solid var(--border); box-shadow: var(--shadow); }

.crm-quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.crm-quick-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--text);
  transition: transform var(--transition), box-shadow var(--transition), border-color 0.2s;
}

.crm-quick-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

.crm-quick-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--icon-surface);
  border: 1px solid var(--icon-border);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.crm-quick-icon .ui-icon,
.crm-quick-icon svg {
  width: 32px;
  height: 32px;
  display: block;
}
.crm-quick-card strong { font-size: 15px; font-weight: 800; }
.crm-quick-card small { font-size: 12px; color: var(--text-muted); }

/* Kanban */
.crm-kanban-wrap {
  overflow-x: auto;
  padding-bottom: 12px;
  margin: 0 -4px;
}

.crm-kanban {
  display: flex;
  gap: 12px;
  min-height: 440px;
  min-width: min(100%, 920px);
}

.crm-kanban-deals { min-width: min(100%, 1100px); }

.crm-kanban-col {
  flex: 0 0 200px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--card-bg) 92%, transparent);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.crm-kanban-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  border-bottom: 3px solid transparent;
}

.crm-kanban-col-head span { flex: 1; }
.crm-kanban-col-head strong {
  font-size: 13px;
  font-weight: 800;
  opacity: 0.7;
  min-width: 1.2em;
  text-align: right;
}

.crm-head-new { background: var(--head-today-bg); color: var(--head-today-color); border-bottom-color: var(--head-today-border); }
.crm-head-work { background: var(--head-this-week-bg); color: var(--head-this-week-color); border-bottom-color: var(--head-this-week-border); }
.crm-head-talk { background: var(--head-next-week-bg); color: var(--head-next-week-color); border-bottom-color: var(--head-next-week-border); }
.crm-head-won { background: var(--head-done-bg); color: var(--head-done-color); border-bottom-color: var(--head-done-border); }
.crm-head-lost { background: var(--head-overdue-bg); color: var(--head-overdue-color); border-bottom-color: var(--head-overdue-border); }

.crm-kanban-col-body {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 140px;
  background: var(--bg);
  transition: background 0.2s, outline 0.2s;
}

.crm-kanban-col-body.over {
  background: color-mix(in srgb, var(--primary-light) 55%, var(--bg));
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
}

.crm-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: grab;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.crm-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.crm-card.dragging { opacity: 0.55; transform: rotate(1deg); cursor: grabbing; }

.crm-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.crm-card-top strong {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  flex: 1;
}

.crm-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.crm-card-amount {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 4px;
}

.crm-card-foot { font-size: 11px; margin-bottom: 8px; }

.crm-card-owner {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.crm-card-owner span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crm-card-btn { margin-top: 4px; }

.crm-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
  white-space: nowrap;
}

.crm-pill-role {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.crm-pill-role-owner {
  background: color-mix(in srgb, var(--primary) 18%, var(--card-bg));
  color: var(--primary-dark);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}

.crm-pill-role-admin {
  background: color-mix(in srgb, #7c4dff 16%, var(--card-bg));
  color: #9575ff;
  border: 1px solid color-mix(in srgb, #7c4dff 28%, transparent);
}

.crm-pill-role-member {
  background: color-mix(in srgb, var(--text-muted) 12%, var(--card-bg));
  color: var(--text-muted);
  border: 1px solid var(--border);
}

body.theme-dark .crm-pill-role-owner {
  background: rgba(74, 222, 128, 0.12);
  color: #86efac;
  border-color: rgba(74, 222, 128, 0.28);
}

body.theme-dark .crm-pill-role-admin {
  background: rgba(124, 77, 255, 0.14);
  color: #c4b5fd;
  border-color: rgba(124, 77, 255, 0.28);
}

body.theme-dark .crm-pill-role-member {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
}

.crm-role-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-muted) 8%, var(--card-bg));
  border: 1px solid var(--border);
}

.crm-role-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.crm-role-switch-3 .crm-role-btn {
  font-size: 9px;
  padding: 7px 8px;
}

.crm-role-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.crm-role-btn.is-active.crm-role-btn-owner {
  background: color-mix(in srgb, var(--primary) 20%, var(--card-bg));
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 35%, transparent);
}

.crm-role-btn.is-active.crm-role-btn-admin {
  background: color-mix(in srgb, #7c4dff 22%, var(--card-bg));
  color: #b39dff;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #7c4dff 35%, transparent);
}

.crm-role-btn.is-active.crm-role-btn-member {
  background: color-mix(in srgb, var(--text-muted) 14%, var(--card-bg));
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

body.theme-dark .crm-role-switch {
  background: #121820;
}

body.theme-dark .crm-role-btn.is-active.crm-role-btn-owner {
  background: rgba(74, 222, 128, 0.18);
  color: #86efac;
}

body.theme-dark .crm-role-btn.is-active.crm-role-btn-admin {
  background: rgba(124, 77, 255, 0.22);
  color: #ddd6fe;
}

body.theme-dark .crm-role-btn.is-active.crm-role-btn-member {
  background: rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
}

.crm-table-wrap .data-table td:nth-child(2),
.crm-table-wrap .data-table th:nth-child(2) {
  width: min(360px, 42vw);
}

.crm-table-wrap .data-table td {
  vertical-align: middle;
}

.crm-avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-light), #C8E6C9);
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 800;
  border: 2px solid var(--icon-border);
}

.crm-avatar-sm { width: 28px; height: 28px; font-size: 11px; border-width: 1px; }
.crm-avatar-xs { width: 24px; height: 24px; font-size: 10px; border-width: 1px; }
.crm-avatar-xl { width: 88px; height: 88px; font-size: 28px; border-width: 3px; }

.crm-avatar-photo {
  padding: 0;
  overflow: hidden;
  background: var(--card-bg);
  position: relative;
}

.crm-avatar-photo .crm-avatar-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}

.crm-avatar-photo.is-fallback .crm-avatar-fallback {
  display: inline-flex;
  background: linear-gradient(135deg, var(--primary-light), #C8E6C9);
  color: var(--primary-dark);
}

.crm-avatar-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.crm-empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--card-bg) 80%, transparent);
}

.crm-empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: var(--radius-md);
  background: var(--icon-surface);
  border: 1px solid var(--icon-border);
  opacity: 0.85;
}

.crm-empty-icon .ui-icon,
.crm-empty-icon svg {
  width: 36px;
  height: 36px;
  display: block;
}

.crm-empty p { font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.crm-empty small { font-size: 12px; line-height: 1.4; }

/* CRM profile */
.crm-profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.75fr);
  gap: 20px;
  align-items: start;
}

.crm-profile-side {
  display: grid;
  gap: 16px;
  align-content: start;
}

@media (max-width: 960px) {
  .crm-profile-grid { grid-template-columns: 1fr; }
}

.crm-profile-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.crm-profile-hero {
  height: 112px;
  background:
    radial-gradient(circle at 20% 30%, color-mix(in srgb, var(--primary) 35%, transparent), transparent 55%),
    radial-gradient(circle at 85% 70%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 50%),
    linear-gradient(135deg, color-mix(in srgb, var(--primary) 18%, var(--card-bg)), var(--card-bg));
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 15%, var(--border));
}

.crm-profile-body {
  padding: 0 24px 24px;
}

.crm-profile-identity {
  margin-top: 16px;
  margin-bottom: 18px;
}

.crm-profile-photo-panel {
  margin-bottom: 22px;
  padding: 18px;
  border-radius: 16px;
  border: 1px dashed color-mix(in srgb, var(--primary) 35%, var(--border));
  background: color-mix(in srgb, var(--primary) 6%, var(--card-bg));
}

.crm-profile-photo-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.crm-profile-photo-head strong {
  font-size: 15px;
}

.crm-profile-photo-head .muted {
  font-size: 13px;
}

.crm-profile-photo-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.crm-profile-photo-actions {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.crm-profile-avatar-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
}

.crm-profile-avatar-pick svg {
  width: 18px;
  height: 18px;
}

.crm-profile-avatar-pick.is-loading {
  opacity: 0.7;
  pointer-events: none;
}

.crm-profile-photo-steps {
  margin: 4px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
}

.crm-profile-photo-steps li {
  margin-bottom: 4px;
}

.crm-profile-photo-steps strong {
  color: var(--text);
}

.crm-profile-display-name {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
}

.crm-profile-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.crm-profile-handle {
  font-size: 13px;
  color: var(--text-muted);
}

.crm-profile-tagline {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

.crm-profile-avatar-edit {
  flex: none;
  position: relative;
  cursor: pointer;
  border-radius: 50%;
  line-height: 0;
}

.crm-profile-avatar-edit .crm-avatar-xl {
  width: 96px;
  height: 96px;
  font-size: 32px;
  border-width: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.crm-profile-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.crm-profile-avatar-overlay svg {
  width: 20px;
  height: 20px;
}

.crm-profile-avatar-edit:hover .crm-profile-avatar-overlay,
.crm-profile-avatar-edit:focus-within .crm-profile-avatar-overlay {
  opacity: 1;
}

.crm-profile-form {
  display: grid;
  gap: 20px;
  border-top: 1px solid var(--border);
  padding-top: 22px;
}

.crm-profile-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.crm-profile-fields .field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.crm-profile-fields .field > span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.crm-profile-fields .field-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.crm-profile-fields .field-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.crm-profile-bio-field {
  grid-column: 1 / -1;
}

.crm-profile-bio {
  resize: vertical;
  min-height: 104px;
  line-height: 1.5;
}

.crm-profile-foot {
  display: flex;
  justify-content: flex-end;
}

.crm-profile-save {
  min-width: 180px;
  border-radius: 999px;
  padding: 12px 24px;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 30%, transparent);
}

.crm-profile-stats.crm-panel {
  min-height: 0;
  padding: 20px;
}

.crm-profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.crm-profile-stat {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.crm-profile-stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.crm-profile-stat strong {
  display: block;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 6px;
}

.crm-profile-stat span {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.crm-profile-stat.is-leads {
  background: color-mix(in srgb, #3b82f6 10%, var(--bg));
  border-color: color-mix(in srgb, #3b82f6 22%, var(--border));
}

.crm-profile-stat.is-leads strong { color: #2563eb; }

.crm-profile-stat.is-funnel {
  background: color-mix(in srgb, #f59e0b 10%, var(--bg));
  border-color: color-mix(in srgb, #f59e0b 22%, var(--border));
}

.crm-profile-stat.is-funnel strong { color: #d97706; }

.crm-profile-stat.is-won {
  background: color-mix(in srgb, var(--primary) 12%, var(--bg));
  border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
}

.crm-profile-stat.is-won strong { color: var(--primary-dark); }

.crm-profile-stat.is-sum {
  background: color-mix(in srgb, #8b5cf6 10%, var(--bg));
  border-color: color-mix(in srgb, #8b5cf6 22%, var(--border));
}

.crm-profile-stat.is-sum strong {
  color: #7c3aed;
  font-size: 20px;
}

.crm-profile-bio-card {
  min-height: 0;
  padding: 20px;
}

.crm-profile-bio-text {
  margin: 0;
  padding: 0 2px;
  line-height: 1.6;
  color: var(--text-muted);
  font-size: 14px;
}

@media (max-width: 640px) {
  .crm-profile-fields { grid-template-columns: 1fr; }
  .crm-profile-identity {
    text-align: center;
  }
  .crm-profile-identity-text { padding-top: 12px; }
  .crm-profile-badges { justify-content: center; }
  .crm-profile-photo-row {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .crm-profile-photo-actions { align-items: center; }
  .crm-profile-photo-steps { text-align: left; }
  .crm-profile-foot { justify-content: stretch; }
  .crm-profile-save { width: 100%; }
}

body.theme-dark .crm-profile-card {
  border-color: rgba(74, 222, 128, 0.12);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

body.theme-dark .crm-profile-hero {
  background:
    radial-gradient(circle at 20% 30%, rgba(74, 222, 128, 0.18), transparent 55%),
    radial-gradient(circle at 85% 70%, rgba(34, 197, 94, 0.12), transparent 50%),
    linear-gradient(135deg, #0f1812, #121820);
  border-bottom-color: rgba(74, 222, 128, 0.12);
}

body.theme-dark .crm-profile-fields .field-input {
  background: #121820;
  border-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .crm-profile-fields .field-input:focus {
  border-color: rgba(74, 222, 128, 0.45);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.1);
}

body.theme-dark .crm-profile-stat {
  background: #121820;
  border-color: rgba(255, 255, 255, 0.06);
}

body.theme-dark .crm-profile-stat.is-leads {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.22);
}

body.theme-dark .crm-profile-stat.is-leads strong { color: #60a5fa; }

body.theme-dark .crm-profile-stat.is-funnel {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.22);
}

body.theme-dark .crm-profile-stat.is-funnel strong { color: #fbbf24; }

body.theme-dark .crm-profile-stat.is-won {
  background: rgba(74, 222, 128, 0.1);
  border-color: rgba(74, 222, 128, 0.22);
}

body.theme-dark .crm-profile-stat.is-won strong { color: #4ade80; }

body.theme-dark .crm-profile-stat.is-sum {
  background: rgba(139, 92, 246, 0.1);
  border-color: rgba(139, 92, 246, 0.22);
}

body.theme-dark .crm-profile-stat.is-sum strong { color: #a78bfa; }

body.theme-dark .crm-profile-photo-panel {
  background: rgba(74, 222, 128, 0.06);
  border-color: rgba(74, 222, 128, 0.22);
}

/* Feed */
.crm-feed-composer {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.crm-feed-composer textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 88px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-feed-composer textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.crm-feed-composer-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.crm-feed-list { max-width: 760px; }
.crm-feed-day { margin-bottom: 24px; }
.crm-feed-day-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.crm-feed-post {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.crm-feed-post.is-system {
  background: color-mix(in srgb, var(--primary-light) 40%, var(--card-bg));
  border-style: dashed;
}

.crm-feed-post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.crm-feed-post-head strong { display: block; font-size: 14px; }
.crm-feed-post-head time { font-size: 11px; color: var(--text-muted); }
.crm-feed-post p { font-size: 14px; line-height: 1.55; margin: 0; }

/* Chat — modern messenger layout */
.crm-chat-app {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  height: min(720px, calc(100vh - 200px));
  min-height: 480px;
  background: var(--card-bg);
  border: 1px solid color-mix(in srgb, var(--primary) 12%, var(--border));
  border-radius: calc(var(--radius-lg) + 4px);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.06),
    0 0 0 1px color-mix(in srgb, var(--primary) 6%, transparent);
  overflow: hidden;
  isolation: isolate;
}

.crm-chat-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--primary) 4%, var(--card-bg)) 0%, var(--card-bg) 120px);
  min-height: 0;
}

.crm-chat-sidebar-head {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.crm-chat-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.crm-chat-sidebar-count {
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 14%, var(--card-bg));
  color: var(--primary-dark);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
}

.crm-chat-create-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 7px 12px;
  border-radius: 999px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent);
}

.crm-chat-create-btn svg {
  width: 14px;
  height: 14px;
}

.crm-chat-sidebar-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.crm-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
}

.crm-chat-item-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
  align-items: stretch;
  border-radius: var(--radius-md);
  transition: background 0.18s ease;
}

.crm-chat-item-wrap.is-active {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  box-shadow: inset 3px 0 0 var(--primary);
}

.crm-chat-item-wrap.is-pinned .crm-chat-item-body strong {
  color: var(--primary-dark);
}

.crm-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 11px 10px 11px 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.18s ease, transform 0.12s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.crm-chat-item:hover {
  background: color-mix(in srgb, var(--primary) 6%, var(--card-hover));
}

.crm-chat-item.active {
  background: transparent;
}

.crm-chat-item-icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--icon-surface), color-mix(in srgb, var(--primary) 8%, var(--card-bg)));
  border: 1px solid var(--icon-border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.crm-chat-item-wrap.is-active .crm-chat-item-icon {
  transform: scale(1.03);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 25%, transparent);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--icon-border));
}

.crm-chat-item-icon .ui-icon,
.crm-chat-item-icon svg {
  width: 22px;
  height: 22px;
  display: block;
}

.crm-chat-item-icon-dm {
  background: transparent;
  border: none;
  box-shadow: none;
}

.crm-chat-item-icon-dm .crm-avatar {
  width: 44px;
  height: 44px;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.crm-chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.crm-chat-item-body strong {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.crm-chat-item-body small {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-chat-pin-badge {
  flex: none;
  font-size: 10px;
  color: var(--primary);
  align-self: flex-start;
  margin-top: 2px;
}

.crm-chat-menu-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 18px;
  line-height: 1;
  border-radius: 10px;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.crm-chat-item-wrap:hover .crm-chat-menu-btn,
.crm-chat-item-wrap.is-active .crm-chat-menu-btn {
  opacity: 1;
}

.crm-chat-menu-btn:hover,
.crm-chat-menu-btn:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--primary) 12%, var(--card-hover));
  color: var(--primary-dark);
}

.crm-chat-pin { display: none; }

.crm-chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  position: relative;
}

.crm-chat-main-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card-bg) 92%, transparent);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 2;
}

.crm-chat-back {
  display: none;
  flex: none;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
}

.crm-chat-back svg {
  width: 18px;
  height: 18px;
}

.crm-chat-head-info {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}

.crm-chat-head-icon {
  flex: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--icon-surface), color-mix(in srgb, var(--primary) 10%, var(--card-bg)));
  border: 1px solid color-mix(in srgb, var(--primary) 20%, var(--icon-border));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 12%, transparent);
}

.crm-chat-head-icon .ui-icon,
.crm-chat-head-icon svg {
  width: 24px;
  height: 24px;
  display: block;
}

.crm-chat-head-icon-dm {
  background: transparent;
  border: none;
  box-shadow: none;
}

.crm-chat-head-icon-dm .crm-avatar {
  width: 48px;
  height: 48px;
  font-size: 17px;
}

.crm-chat-head-info strong {
  display: block;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.crm-chat-head-info small {
  font-size: 12px;
  color: var(--text-muted);
}

.crm-chat-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.crm-chat-action-btn {
  background: color-mix(in srgb, var(--primary) 8%, var(--card-bg));
  color: var(--primary-dark);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.crm-chat-action-btn:active,
.crm-chat-settings-btn:active {
  transform: scale(0.97);
}

.crm-chat-action-btn:hover {
  background: color-mix(in srgb, var(--primary) 16%, var(--card-bg));
  border-color: var(--primary);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 20%, transparent);
}

.crm-chat-settings-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: color-mix(in srgb, var(--primary) 8%, var(--card-bg));
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
  color: var(--primary-dark);
  border-radius: 50%;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.crm-chat-settings-btn:hover {
  background: color-mix(in srgb, var(--primary) 16%, var(--card-bg));
  border-color: var(--primary);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 20%, transparent);
}

.crm-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.crm-btn-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.crm-chat-head-actions .crm-chat-action-btn .crm-btn-icon svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.crm-chat-settings-btn .crm-btn-icon svg {
  width: 18px;
  height: 18px;
}

body.theme-dark .crm-chat-action-btn,
body.theme-dark .crm-chat-settings-btn {
  background: #1a2820;
  border-color: rgba(74, 222, 128, 0.28);
  color: #8ee4a8;
}

body.theme-dark .crm-chat-action-btn:hover,
body.theme-dark .crm-chat-settings-btn:hover {
  background: #243830;
  border-color: rgba(74, 222, 128, 0.5);
  color: #b8f0c8;
  box-shadow: 0 2px 16px rgba(74, 222, 128, 0.12);
}

.crm-chat-members {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card-bg) 70%, var(--bg));
}

.crm-chat-members-stack {
  display: flex;
  align-items: center;
  padding-left: 4px;
}

.crm-chat-members-stack .crm-avatar {
  margin-left: -8px;
  border: 2px solid var(--card-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease;
}

.crm-chat-members-stack .crm-avatar:first-child {
  margin-left: 0;
}

.crm-chat-members-stack .crm-avatar:hover {
  transform: translateY(-2px);
  z-index: 2;
  position: relative;
}

.crm-chat-members-more {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 8%, var(--card-bg));
  border: 1px solid var(--border);
}

.crm-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 28px;
  color: var(--text-muted);
  position: relative;
  overflow: hidden;
}

.crm-chat-empty-glow {
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--primary) 22%, transparent) 0%, transparent 70%);
  pointer-events: none;
  animation: crm-chat-glow 4s ease-in-out infinite alternate;
}

@keyframes crm-chat-glow {
  from { transform: scale(0.92); opacity: 0.7; }
  to { transform: scale(1.08); opacity: 1; }
}

.crm-chat-empty-icon {
  position: relative;
  z-index: 1;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--primary) 18%, var(--card-bg)), var(--card-bg));
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  margin-bottom: 18px;
  box-shadow: 0 8px 28px color-mix(in srgb, var(--primary) 18%, transparent);
}

.crm-chat-empty-icon .ui-icon,
.crm-chat-empty-icon svg {
  width: 36px;
  height: 36px;
  opacity: 0.9;
  color: var(--primary);
}

.crm-chat-empty p {
  position: relative;
  z-index: 1;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.crm-chat-empty small {
  position: relative;
  z-index: 1;
  font-size: 13px;
  line-height: 1.5;
  max-width: 280px;
}

.crm-chat-send {
  flex: none;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 38%, transparent);
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.crm-chat-send svg {
  width: 18px;
  height: 18px;
  margin-left: 1px;
}

.crm-chat-send:hover {
  box-shadow: 0 6px 20px color-mix(in srgb, var(--primary) 45%, transparent);
}

.crm-chat-send:active {
  transform: scale(0.94);
}

.crm-chat-no-access {
  padding: 14px 20px;
  text-align: center;
  font-size: 13px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

.crm-msg-author {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 3px;
  letter-spacing: 0.01em;
}

.crm-member-fixed {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--primary) 12%, var(--card-bg));
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
}

.crm-member-fixed strong {
  display: block;
  font-size: 14px;
}

.crm-member-fixed small {
  font-size: 11px;
  color: var(--text-muted);
}

.crm-member-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  min-height: 56px;
}

.crm-member-picker {
  display: grid;
  gap: 8px;
}

.crm-dialog-inner .crm-member-search {
  width: 100%;
  min-width: 0;
  padding: 4px 4px 4px 12px;
  background: var(--search-bg, var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.crm-dialog-inner .crm-member-search input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 8px 4px;
  min-width: 0;
}

.crm-dialog-inner .crm-member-search input:focus {
  outline: none;
}

.crm-dialog-inner .crm-member-search:focus-within {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.crm-member-check[hidden] {
  display: none !important;
}

.crm-member-name small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 1px;
}

.crm-member-no-match {
  padding: 10px 8px;
  text-align: center;
  font-size: 13px;
}

body.theme-dark .crm-dialog-inner .crm-member-search {
  background: #121820;
}

.crm-member-empty {
  padding: 12px 8px;
  text-align: center;
}

.crm-member-empty p {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.crm-member-empty small {
  display: block;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.crm-inline-add {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.crm-inline-add .field-input {
  flex: 1;
  min-width: 0;
}

body.theme-dark .crm-member-fixed {
  background: #1a2820;
  border-color: rgba(74, 222, 128, 0.25);
}

.crm-member-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin: 0;
}

.crm-member-check:hover {
  background: var(--card-hover);
}

.crm-member-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.crm-member-check-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.crm-member-check .crm-avatar {
  flex-shrink: 0;
}

.crm-member-name {
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-settings-section {
  display: grid;
  gap: 8px;
}

.crm-settings-field {
  display: grid;
  gap: 8px;
  margin: 0;
  cursor: default;
}

.crm-field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.3;
}

.crm-perm-grid {
  display: grid;
  gap: 14px;
}

.crm-select,
.crm-dialog-inner select.field-input {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding-right: 40px;
  cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235F6F5F' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

body.theme-dark .crm-select,
body.theme-dark .crm-dialog-inner select.field-input {
  background-color: #121820;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A5D6A7' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.crm-dialog-wide {
  max-width: 480px;
  width: min(480px, calc(100vw - 32px));
}

.crm-dialog-inner h3 {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 8px;
  line-height: 1.25;
}

.crm-dialog-inner .crm-settings-section + .crm-settings-section {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.crm-settings-lead {
  margin: -4px 0 12px;
  font-size: 13px;
}

.crm-settings-hint {
  margin: 8px 0 0;
  font-size: 13px;
}

.crm-settings-readonly .crm-settings-members {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.crm-settings-readonly .crm-settings-members li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 14px;
}

.crm-settings-danger {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid color-mix(in srgb, var(--danger, #c62828) 25%, var(--border));
}

.crm-company-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.crm-company-form .crm-panel-body {
  display: grid;
  gap: 14px;
}

.crm-company-form .field {
  display: grid;
  gap: 6px;
}

.crm-company-form .field span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.crm-company-form .field-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-company-form .field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.crm-company-form .field-input[readonly] {
  opacity: 0.85;
  cursor: default;
}

.crm-panel-settings .crm-panel-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.crm-chat-delete-btn.is-armed {
  border-color: var(--danger, #c62828);
  color: var(--danger, #c62828);
  background: color-mix(in srgb, var(--danger, #c62828) 8%, transparent);
}

.crm-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, color-mix(in srgb, var(--primary) 8%, transparent) 0%, transparent 55%),
    radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--primary) 5%, transparent) 0%, transparent 40%),
    var(--bg);
  scrollbar-width: thin;
}

.crm-chat-form {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--card-bg) 95%, transparent);
  backdrop-filter: blur(10px);
}

.crm-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 8px 6px 6px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--primary) 10%, transparent),
    0 4px 16px rgba(0, 0, 0, 0.06);
}

.crm-chat-attach-btn {
  flex: none;
  width: 36px;
  height: 36px;
  margin-bottom: 1px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.crm-chat-attach-btn svg {
  width: 20px;
  height: 20px;
}

.crm-chat-attach-btn:hover {
  background: var(--card-hover);
  color: var(--primary-dark);
}

.crm-chat-attach-btn:active {
  transform: scale(0.94);
}

.crm-chat-attach-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.crm-chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 9px 4px;
  border-radius: 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: none;
  max-height: 128px;
  field-sizing: content;
}

.crm-chat-input:focus {
  outline: none;
  box-shadow: none;
}

.crm-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(82%, 540px);
  animation: crm-msg-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.crm-msg.is-compact {
  margin-top: -4px;
}

.crm-msg-avatar-spacer {
  flex: none;
  width: 24px;
  height: 1px;
}

@keyframes crm-msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.crm-msg.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.crm-msg-bubble {
  position: relative;
  padding: 9px 13px 7px;
  border-radius: 18px;
  background: var(--card-bg);
  border: 1px solid color-mix(in srgb, var(--border) 90%, transparent);
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  min-width: 72px;
}

.crm-msg:not(.mine) .crm-msg-bubble.has-tail {
  border-bottom-left-radius: 6px;
}

.crm-msg.mine .crm-msg-bubble.has-tail {
  border-bottom-right-radius: 6px;
}

.crm-msg.mine .crm-msg-bubble {
  background: linear-gradient(145deg, color-mix(in srgb, var(--primary) 88%, #fff), color-mix(in srgb, var(--primary) 72%, #1a3d28));
  border-color: color-mix(in srgb, var(--primary) 55%, transparent);
  box-shadow: 0 4px 18px color-mix(in srgb, var(--primary) 28%, transparent);
  color: #fff;
}

.crm-msg-text {
  margin-bottom: 0;
  word-break: break-word;
  white-space: pre-wrap;
}

.crm-msg-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  min-height: 14px;
}

.crm-msg-meta time {
  font-size: 10px;
  line-height: 1;
  opacity: 0.72;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.crm-msg.mine .crm-msg-meta time {
  color: rgba(255, 255, 255, 0.78);
}

.crm-msg.is-image .crm-msg-bubble,
.crm-msg.is-file .crm-msg-bubble {
  padding: 8px;
}

.crm-msg-image {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  max-width: min(280px, 100%);
  line-height: 0;
}

.crm-msg-image img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 12px;
}

.crm-msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 180px;
  max-width: 280px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.crm-msg-file:hover {
  background: var(--card-hover);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.crm-msg-file-icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.crm-msg.mine .crm-msg-file-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.crm-msg-file-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.crm-msg-file-body strong {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-msg-file-body small {
  font-size: 11px;
  color: var(--text-muted);
}

/* Calendar */
.crm-cal-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.crm-cal-shell {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.crm-cal-label {
  text-transform: capitalize;
  margin-bottom: 16px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.crm-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.crm-cal-wd {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  padding: 6px 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.crm-cal-cell {
  min-height: 88px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 8px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.crm-cal-cell:hover:not(.empty) {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.crm-cal-cell.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  min-height: 0;
}

.crm-cal-cell.today {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-light) 55%, var(--bg));
}

.crm-cal-cell.has-events { background: var(--cal-has-events-bg); }

.crm-cal-day-num {
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
}

.crm-cal-events { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }

.crm-cal-event {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--primary-dark);
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--primary-light) 70%, transparent);
}

.crm-cal-more {
  font-size: 10px;
  color: var(--text-muted);
  font-style: normal;
}

/* Tables & panels */
.crm-table-wrap { margin-bottom: 8px; }

.crm-table-person {
  display: flex;
  align-items: center;
  gap: 10px;
}

.crm-file-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--icon-surface);
  border: 1px solid var(--icon-border);
  flex-shrink: 0;
}

.crm-file-icon .ui-icon,
.crm-file-icon svg {
  width: 22px;
  height: 22px;
  display: block;
}

.crm-project-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.crm-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.crm-panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.crm-panel-head .crm-quick-icon {
  margin-bottom: 0;
  width: 52px;
  height: 52px;
}

.crm-panel-head .crm-quick-icon svg {
  width: 34px;
  height: 34px;
}

.crm-panel-head-text {
  flex: 1;
  min-width: 0;
}

.crm-panel-head h3 {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
}

.crm-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.crm-panel-foot {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crm-person-search-wrap {
  position: relative;
}

.crm-person-search {
  width: 100%;
  min-width: 0;
}

.crm-person-suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
}

.crm-person-suggest .search-suggest-icon.crm-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 16px;
}

.crm-people-toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.crm-people-search-wrap {
  max-width: 560px;
}

.crm-people-hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.crm-person-remove {
  color: var(--danger, #c62828);
}

.crm-person-actions {
  text-align: right;
  white-space: nowrap;
}

.crm-person-suggest-empty {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
}

.crm-person-remove {
  color: var(--danger, #c62828);
}

.crm-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.crm-invite-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

.crm-invite-input { flex: 1; min-width: 180px; }

.crm-people-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}

.crm-people-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.crm-people-list li:last-child { border-bottom: none; }
.crm-people-list strong { display: block; font-size: 14px; }
.crm-people-list small { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }

/* Dialogs */
.crm-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 440px;
  width: min(440px, calc(100vw - 32px));
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
  margin: auto;
  border: 1px solid var(--border);
}

.crm-dialog[open] {
  position: fixed;
  inset: 0;
  height: fit-content;
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.crm-dialog::backdrop {
  background: rgba(15, 20, 25, 0.45);
  backdrop-filter: blur(4px);
}

.crm-dialog-inner {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.crm-dialog-inner .field {
  display: grid;
  gap: 6px;
}

.crm-dialog-inner .field-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-dialog-inner select.field-input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-dialog-inner .field-input:focus,
.crm-dialog-inner select.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.crm-dialog-inner .field span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.crm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.btn-full { width: 100%; }

/* Dark theme */
body.theme-dark .crm-stat-card,
body.theme-dark .crm-quick-card,
body.theme-dark .crm-feed-composer,
body.theme-dark .crm-feed-post,
body.theme-dark .crm-cal-shell,
body.theme-dark .crm-panel {
  border-color: var(--border);
}

body.theme-dark .crm-chat-app {
  border-color: rgba(74, 222, 128, 0.15);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(74, 222, 128, 0.08);
  background: #0f1419;
}

body.theme-dark .crm-chat-sidebar {
  background: linear-gradient(180deg, #141c24 0%, #101820 100%);
}

body.theme-dark .crm-chat-item-wrap.is-active {
  background: rgba(74, 222, 128, 0.08);
  box-shadow: inset 3px 0 0 #4ade80;
}

body.theme-dark .crm-chat-main-head,
body.theme-dark .crm-chat-form {
  background: rgba(18, 24, 32, 0.92);
}

body.theme-dark .crm-chat-log {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(74, 222, 128, 0.06) 0%, transparent 55%),
    #0c1015;
}

body.theme-dark .crm-chat-composer {
  background: #121820;
  border-color: rgba(74, 222, 128, 0.14);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
}

body.theme-dark .crm-chat-composer:focus-within {
  border-color: rgba(74, 222, 128, 0.38);
  box-shadow:
    0 0 0 3px rgba(74, 222, 128, 0.1),
    0 4px 20px rgba(0, 0, 0, 0.3);
}

body.theme-dark .crm-feed-composer textarea,
body.theme-dark .crm-chat-input {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}

body.theme-dark .crm-chat-attach-btn {
  background: transparent;
  border: none;
}

body.theme-dark .crm-chat-attach-btn:hover {
  background: rgba(74, 222, 128, 0.1);
  color: #4ade80;
}

body.theme-dark .crm-msg-bubble {
  background: #161d26;
  border-color: rgba(255, 255, 255, 0.06);
}

body.theme-dark .crm-msg-author {
  color: #4ade80;
}

body.theme-dark .crm-msg.mine .crm-msg-bubble {
  background: linear-gradient(145deg, #22c55e, #15803d);
  border-color: rgba(74, 222, 128, 0.35);
  box-shadow: 0 4px 20px rgba(34, 197, 94, 0.22);
  color: #f0fdf4;
}

body.theme-dark .crm-msg.mine .crm-msg-meta time {
  color: rgba(240, 253, 244, 0.72);
}

body.theme-dark .crm-msg-file {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(74, 222, 128, 0.12);
}

body.theme-dark .crm-chat-empty-icon {
  background: linear-gradient(145deg, #1a2820, #121820);
  border-color: rgba(74, 222, 128, 0.25);
}

body.theme-dark .crm-card {
  background: #121820;
  border-color: var(--border);
}

body.theme-dark .crm-kanban-col-body {
  background: #0f1419;
}

body.theme-dark .crm-kanban-col-body.over {
  background: #1a2820;
}

body.theme-dark .crm-cal-cell.today {
  background: #1a2820;
}

body.theme-dark .crm-avatar {
  background: linear-gradient(135deg, #1a3d28, #243830);
  border-color: rgba(74, 222, 128, 0.25);
  color: #6ee7a0;
}

@media (max-width: 768px) {
  .crm-page-head.row-between { flex-direction: column; }
  .crm-page-actions { width: 100%; }
  .crm-page-actions .btn { flex: 1; }
  .crm-kanban { min-width: 100%; }
  .crm-kanban-col { flex: 0 0 168px; min-width: 168px; }
  .crm-chat-app {
    grid-template-columns: 1fr;
    height: min(680px, calc(100vh - 180px));
    min-height: 420px;
  }
  .crm-chat-sidebar { max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .crm-chat-list { flex-direction: column; overflow-x: hidden; overflow-y: auto; padding-bottom: 8px; max-height: 240px; }
  .crm-chat-item { flex: none; min-width: 0; width: 100%; }
  .crm-chat-main { display: none; }
  .crm-chat-app.show-active .crm-chat-sidebar { display: none; }
  .crm-chat-app.show-active .crm-chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .crm-chat-back { display: inline-flex; }
  .crm-cal-grid { gap: 4px; }
  .crm-cal-cell { min-height: 64px; padding: 6px; }
  .crm-project-grid { grid-template-columns: 1fr; }
  .crm-quick-grid { grid-template-columns: repeat(2, 1fr); }
}

/* CRM entity cards */
.crm-card[data-crm-entity] { cursor: pointer; }
.crm-client-row { cursor: pointer; }
.crm-client-row:hover { background: color-mix(in srgb, var(--primary) 5%, transparent); }

.crm-entity-dialog {
  max-width: 520px;
  width: min(520px, calc(100vw - 32px));
}

.crm-entity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.crm-entity-head h3 { margin: 0; }

.crm-dialog-x {
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
}

.crm-entity-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 42vh;
  overflow-y: auto;
  padding-right: 4px;
}

.crm-entity-history {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.crm-entity-history h4 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.crm-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
}

.crm-history-list li {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 4px 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.crm-history-list li:last-child { border-bottom: none; }

.crm-history-list time {
  grid-column: 1;
  color: var(--text-muted);
  font-size: 11px;
}

.crm-history-list strong {
  grid-column: 2;
  font-size: 12px;
}

.crm-history-list span {
  grid-column: 2;
  color: var(--text);
}

.crm-linked-block {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--text-muted) 6%, var(--card-bg));
  font-size: 13px;
}

.crm-upload-hint {
  margin: 0;
  font-size: 12px;
}

.crm-upload-dialog {
  max-width: 480px;
  width: min(480px, calc(100vw - 32px));
  overflow: hidden;
}

.crm-upload-dialog .crm-dialog-inner {
  overflow: hidden;
  min-width: 0;
}

.crm-upload-form {
  gap: 18px;
  min-width: 0;
  overflow: hidden;
}

.crm-upload-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.crm-upload-head h3 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.crm-upload-head p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.crm-upload-head-icon {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--primary) 16%, var(--card-bg));
  color: var(--primary-dark);
}

.crm-upload-head-icon .ui-icon,
.crm-upload-head-icon svg {
  width: 22px;
  height: 22px;
}

.crm-upload-drop {
  display: block;
  position: relative;
  padding: 28px 20px;
  border-radius: 16px;
  border: 1.5px dashed color-mix(in srgb, var(--text-muted) 35%, var(--border));
  background: color-mix(in srgb, var(--text-muted) 5%, var(--card-bg));
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  text-align: center;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

.crm-upload-drop:hover,
.crm-upload-drop:focus-visible {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--primary) 6%, var(--card-bg));
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.crm-upload-drop.is-dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, var(--card-bg));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.crm-upload-drop.has-file {
  padding: 14px 16px;
  border-style: solid;
  border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
  background: color-mix(in srgb, var(--primary) 5%, var(--card-bg));
  text-align: left;
}

.crm-upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.crm-upload-drop.has-file .crm-upload-input {
  display: none;
}

.crm-upload-drop-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.crm-upload-drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--text-muted) 10%, var(--card-bg));
  color: var(--text-muted);
  margin-bottom: 4px;
}

.crm-upload-drop-icon .ui-icon,
.crm-upload-drop-icon svg {
  width: 24px;
  height: 24px;
}

.crm-upload-drop-visual strong {
  font-size: 14px;
  font-weight: 700;
}

.crm-upload-drop-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.crm-upload-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.crm-upload-chip-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--primary) 18%, var(--card-bg));
  color: var(--primary-dark);
}

.crm-upload-chip-icon .ui-icon,
.crm-upload-chip-icon svg {
  width: 20px;
  height: 20px;
}

.crm-upload-chip-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.crm-upload-chip-text strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-upload-chip-text small {
  font-size: 12px;
}

.crm-upload-chip-clear {
  flex-shrink: 0;
  min-width: 36px;
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
}

.crm-upload-name-field span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.crm-upload-name-field .field-input,
#crm-file-name {
  max-width: 100%;
  min-width: 0;
}

.crm-upload-actions {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

body.theme-dark .crm-upload-head-icon {
  color: #86efac;
  background: rgba(74, 222, 128, 0.12);
}

body.theme-dark .crm-upload-drop-icon {
  background: rgba(148, 163, 184, 0.1);
}

body.theme-dark .crm-upload-chip-icon {
  color: #86efac;
  background: rgba(74, 222, 128, 0.14);
}

#crm-entity-delete.is-armed {
  background: rgba(220, 38, 38, 0.15);
  border-color: #dc2626;
  color: #f87171;
}

.crm-history-text {
  grid-column: 1 / -1;
  font-size: 13px;
  line-height: 1.45;
}

.crm-history-list li {
  display: block;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.crm-history-list time {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 11px;
}

.crm-dialog-spacer { flex: 1; }

/* CRM drive explorer */
.crm-drive-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0 0 12px;
  font-size: 14px;
}
.crm-drive-crumb {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.crm-drive-crumb:hover { background: var(--primary-light); }
.crm-drive-crumb.is-current { color: var(--text); font-weight: 600; cursor: default; }
.crm-drive-crumb-sep { color: var(--text-muted); opacity: 0.6; }
.crm-drive-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0;
  text-align: left;
}
.crm-drive-open:hover strong { color: var(--primary); }
.crm-folder-icon { color: var(--primary); }
.crm-drive-drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; background: var(--primary-light); }
.crm-drive-row.dragging { opacity: 0.45; }
.crm-drive-empty.crm-drive-dropzone { min-height: 120px; border: 1px dashed var(--border); border-radius: 12px; padding: 12px; cursor: pointer; }
.crm-drive-empty.crm-drive-dropzone:hover,
.crm-drive-empty.crm-drive-dropzone.crm-drive-file-drop-target { border-color: var(--accent); background: rgba(0, 179, 65, 0.06); }
.crm-drive-table-wrap.crm-drive-file-drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 12px; }

.crm-drive-file-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.crm-drive-file-open:hover .crm-drive-file-name { color: var(--primary); }

.crm-drive-file-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.crm-drive-file-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.crm-drive-thumb {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}

.crm-drive-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.crm-drive-table .crm-table-person {
  min-width: 0;
  align-items: center;
}

.crm-drive-table .table-actions {
  white-space: nowrap;
}

/* CRM chat context menu (Telegram-style) */
.crm-context-menu {
  position: fixed;
  z-index: 100500;
  min-width: 200px;
  max-width: min(280px, calc(100vw - 16px));
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  animation: crm-context-in 0.12s ease-out;
}

.crm-context-menu[hidden] {
  display: none !important;
}

@keyframes crm-context-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.crm-context-item {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.crm-context-item:hover,
.crm-context-item:focus-visible {
  outline: none;
  background: var(--card-hover);
}

.crm-context-item.is-danger {
  color: var(--danger, #c62828);
}

.crm-context-item.is-danger:hover,
.crm-context-item.is-danger:focus-visible {
  background: color-mix(in srgb, var(--danger, #c62828) 10%, var(--card-hover));
}

.crm-context-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

body.theme-dark .crm-context-menu {
  background: #121820;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* CRM onboarding + company */
.crm-onboarding-dialog .crm-onb-lead { margin-bottom: 12px; }
.crm-panel-company .crm-panel-body p { margin: 0 0 6px; }
