/*
 * CRM visual system — Telegram-inspired desktop UI.
 * This layer intentionally comes after legacy styles and changes presentation
 * only. Business behaviour, layout structure and table column order stay intact.
 */

/* A zero notification count must stay hidden at every viewport width. */
.notification-bell > b[hidden] {
  display: none !important;
}

@media (min-width: 901px) {
  :root,
  html[data-theme="light"] {
    color-scheme: light;

    --app-bg: #f4f6f8;
    --sidebar-bg: #ffffff;
    --surface-1: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;
    --surface-hover: #eef5fb;
    --surface-selected: #e5f2ff;
    --surface-pressed: #d8ebff;
    --input-bg: #ffffff;
    --table-row-hover: #f2f8fd;
    --table-row-selected: #e5f2ff;
    --scroll-thumb: #b5c0ca;
    --scroll-thumb-hover: #8e9ca9;

    --text-primary: #17212b;
    --text-secondary: #596673;
    --text-tertiary: #8593a0;
    --text-disabled: #aeb8c2;
    --text-on-accent: #ffffff;

    --border-subtle: #e4e9ee;
    --border-default: #d7dee5;
    --border-strong: #c5ced8;

    --accent: #3390ec;
    --accent-hover: #2b82da;
    --accent-pressed: #2376ca;
    --accent-soft: #e5f2ff;
    --accent-soft-hover: #d8ebff;
    --focus-ring: rgba(51, 144, 236, 0.28);

    --success: #2fa86d;
    --success-soft: #e5f6ed;
    --warning: #d99412;
    --warning-soft: #fff3d6;
    --danger: #df4f4f;
    --danger-hover: #cf4242;
    --danger-soft: #fdeaea;
    --info: #3390ec;
    --info-soft: #e5f2ff;
    --purple: #7656b7;
    --purple-soft-ui: #eee8fb;
    --cyan-soft-ui: #e7f5f9;

    --overlay: rgba(15, 23, 42, 0.38);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);

    --font-size-10: 10px;
    --font-size-11: 11px;
    --font-size-12: 12px;
    --font-size-13: 13px;
    --font-size-14: 14px;
    --font-size-16: 16px;
    --font-size-18: 18px;
    --font-size-24: 24px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-pill: 999px;

    --motion-instant: 80ms;
    --motion-fast: 120ms;
    --motion-normal: 180ms;
    --motion-slow: 240ms;
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --ease-in: cubic-bezier(0.4, 0, 1, 1);

    /* Compatibility tokens consumed by existing components. */
    --bg: var(--app-bg);
    --paper: var(--surface-1);
    --ink: var(--text-primary);
    --muted: var(--text-secondary);
    --line: var(--border-subtle);
    --blue: var(--accent);
    --blue-soft: var(--accent-soft);
    --navy: var(--text-primary);
    --navy-2: var(--text-secondary);
    --green: var(--success);
    --green-soft: var(--success-soft);
    --amber: var(--warning);
    --amber-soft: var(--warning-soft);
    --red: var(--danger);
    --red-soft: var(--danger-soft);
    --purple-soft: var(--purple-soft-ui);
    --cyan-soft: var(--cyan-soft-ui);
    --shadow: var(--shadow-sm);
    --radius: var(--radius-lg);
    --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
      "Helvetica Neue", Arial, sans-serif;
  }

  html[data-theme="dark"] {
    color-scheme: dark;

    --app-bg: #0e1621;
    --sidebar-bg: #17212b;
    --surface-1: #17212b;
    --surface-2: #1b2835;
    --surface-3: #202f3d;
    --surface-hover: #213346;
    --surface-selected: #2b5278;
    --surface-pressed: #32618e;
    --input-bg: #202f3d;
    --table-row-hover: #1f3141;
    --table-row-selected: #243f58;
    --scroll-thumb: #52697d;
    --scroll-thumb-hover: #6f8799;

    --text-primary: #f2f5f7;
    --text-secondary: #aeb9c3;
    --text-tertiary: #778795;
    --text-disabled: #566674;
    --text-on-accent: #ffffff;

    --border-subtle: #223342;
    --border-default: #2a3c4c;
    --border-strong: #3a5062;

    --accent: #4ea4f6;
    --accent-hover: #61aff8;
    --accent-pressed: #3390ec;
    --accent-soft: #213f5c;
    --accent-soft-hover: #285078;
    --focus-ring: rgba(78, 164, 246, 0.34);

    --success: #4dc68a;
    --success-soft: #183f31;
    --warning: #f0b84b;
    --warning-soft: #493a1d;
    --danger: #ef6b6b;
    --danger-hover: #f07b7b;
    --danger-soft: #4a2529;
    --info: #4ea4f6;
    --info-soft: #213f5c;
    --purple: #b69ae5;
    --purple-soft-ui: #302a49;
    --cyan-soft-ui: #193745;

    --overlay: rgba(0, 0, 0, 0.58);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.22);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.30);
  }

  html,
  body {
    background: var(--app-bg) !important;
    color: var(--text-primary);
    font-family: var(--font);
    line-height: 1.4;
  }

  body:not(.login-page) .content {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scrollbar-color: var(--scroll-thumb) transparent;
    scrollbar-width: thin;
  }

  *::-webkit-scrollbar {
    height: 9px;
    width: 9px;
  }

  *::-webkit-scrollbar-track {
    background: transparent;
  }

  *::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border: 2px solid transparent;
    border-radius: var(--radius-pill);
    background-clip: padding-box;
  }

  *::-webkit-scrollbar-thumb:hover {
    background-color: var(--scroll-thumb-hover);
  }

  a,
  button,
  input,
  select,
  textarea,
  summary {
    -webkit-tap-highlight-color: transparent;
  }

  :where(a, button, input, select, textarea, summary):focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px var(--focus-ring) !important;
  }

  :where(button, .button, a, summary):active {
    transform: scale(0.98);
    transition-duration: var(--motion-instant);
  }

  button:disabled,
  input:disabled,
  select:disabled,
  textarea:disabled,
  .button[aria-disabled="true"] {
    color: var(--text-disabled) !important;
    cursor: not-allowed;
    opacity: 0.72;
  }

  /* App frame and navigation. */
  .app-shell {
    background: var(--app-bg);
  }

  .sidebar {
    background: var(--sidebar-bg) !important;
    border-right: 1px solid var(--border-subtle);
    box-shadow: none !important;
    color: var(--text-primary);
  }

  .brand {
    padding-bottom: var(--space-5);
  }

  .brand-word b {
    color: var(--text-primary) !important;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .brand-word small {
    color: var(--text-tertiary) !important;
    font-weight: 600;
  }

  .nav {
    gap: var(--space-1);
  }

  .nav a {
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--text-secondary) !important;
    font-size: var(--font-size-14);
    font-weight: 500;
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    position: relative;
    transform: none !important;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard);
  }

  .nav a::before {
    background: transparent;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    content: "";
    inset: 7px auto 7px 0;
    position: absolute;
    width: 3px;
  }

  .nav a:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
  }

  .nav a.active {
    background: var(--accent-soft) !important;
    box-shadow: none !important;
    color: var(--accent) !important;
  }

  .nav a.active::before {
    background: var(--accent);
  }

  .nav a span,
  .nav a.active span,
  .nav a:hover span {
    color: inherit !important;
  }

  .nav .nav-icon {
    font-size: 19px;
    font-weight: 500;
    height: 24px !important;
    width: 24px !important;
  }

  .sidebar-foot {
    border-color: var(--border-subtle) !important;
    gap: var(--space-3);
  }

  .theme-toggle,
  .link-button {
    color: var(--text-secondary) !important;
  }

  .theme-toggle {
    background: var(--surface-2) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-md);
    font-size: var(--font-size-13);
    font-weight: 500;
    min-height: 40px;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard);
  }

  .theme-toggle:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
  }

  .agency-pill {
    color: var(--text-secondary) !important;
  }

  .agency-pill small {
    color: var(--text-tertiary) !important;
  }

  .status-dot {
    background: var(--success);
    box-shadow: none;
  }

  .sidebar-collapse {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-default) !important;
    box-shadow: var(--shadow-sm) !important;
    color: var(--text-secondary) !important;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard),
      left var(--motion-slow) var(--ease-standard),
      transform var(--motion-slow) var(--ease-standard);
  }

  .sidebar-collapse:hover {
    background: var(--accent-soft) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
  }

  .main,
  .content {
    background: var(--app-bg) !important;
  }

  .topbar {
    background: var(--surface-1) !important;
    backdrop-filter: none !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    box-shadow: none;
  }

  .topbar h1 {
    color: var(--text-primary);
    font-size: var(--font-size-24);
    font-weight: 600;
    letter-spacing: -0.02em;
  }

  .eyebrow {
    color: var(--text-tertiary);
    font-size: var(--font-size-10);
    font-weight: 600;
  }

  .user-chip {
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--space-1);
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard);
  }

  .user-chip:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-subtle) !important;
  }

  .user-chip b {
    color: var(--text-primary);
    font-size: var(--font-size-13);
    font-weight: 600;
  }

  .user-chip small {
    color: var(--text-tertiary);
    font-size: var(--font-size-11);
  }

  .avatar,
  .agent-avatar {
    background: var(--accent-soft) !important;
    border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent) !important;
    border-radius: var(--radius-md);
    color: var(--accent) !important;
  }

  .notification-bell,
  .tournament-podium-button {
    background: var(--surface-2) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-md);
    box-shadow: none !important;
    color: var(--text-secondary) !important;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard);
  }

  .notification-bell:hover,
  .notification-bell[aria-expanded="true"],
  .tournament-podium-button:hover,
  .tournament-podium-button[aria-expanded="true"] {
    background: var(--accent-soft) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--focus-ring) !important;
  }

  .notification-bell > b,
  .nav-badge {
    background: var(--danger) !important;
    border-color: var(--surface-1) !important;
    color: var(--text-on-accent) !important;
  }

  /* Shared surfaces and controls. */
  .panel,
  .metric,
  .report-kpi,
  .summary-fact-card,
  .form-section,
  .structure-card,
  .agent-card,
  .object-heading,
  .activity-rating-report {
    background: var(--surface-1) !important;
    border-color: var(--border-subtle) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-sm) !important;
    color: var(--text-primary);
  }

  .hero-panel,
  .structure-hero {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary) !important;
  }

  .hero-panel::after {
    display: none;
  }

  .hero-panel p:last-child,
  .structure-hero p:last-child {
    color: var(--text-secondary) !important;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  .search,
  .multi-filter-toggle,
  .objects-filter-control {
    background: var(--input-bg) !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-primary) !important;
    font-size: var(--font-size-13);
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--text-tertiary) !important;
  }

  input:not([type="checkbox"]):not([type="radio"]):hover,
  select:hover,
  textarea:hover,
  .search:hover,
  .multi-filter-toggle:hover,
  .objects-filter-control:hover {
    border-color: var(--border-strong) !important;
  }

  input:not([type="checkbox"]):not([type="radio"]):focus,
  select:focus,
  textarea:focus,
  .search:focus-within,
  .multi-filter-toggle:focus-visible {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--focus-ring) !important;
    outline: 0;
  }

  input[type="checkbox"],
  input[type="radio"] {
    accent-color: var(--accent);
  }

  option {
    background: var(--surface-1);
    color: var(--text-primary);
  }

  .button {
    border-radius: var(--radius-md);
    box-shadow: none !important;
    font-size: var(--font-size-13);
    font-weight: 600;
    min-height: 38px;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard),
      transform var(--motion-instant) var(--ease-standard);
  }

  .button.primary {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .button.primary:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    transform: none;
  }

  .button.secondary,
  .button.light {
    background: var(--surface-1) !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
  }

  .button.secondary:hover,
  .button.light:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-strong) !important;
    transform: none;
  }

  .button.danger,
  .event-reminder-actions .button.danger,
  .calendar-event-manage .button.danger {
    background: var(--danger) !important;
    border-color: var(--danger) !important;
    color: var(--text-on-accent) !important;
  }

  .button.danger:hover {
    background: var(--danger-hover) !important;
    border-color: var(--danger-hover) !important;
  }

  /* Object page: compact Telegram-like hierarchy. */
  .objects-page .content {
    gap: var(--space-2);
  }

  .objects-page .topbar {
    min-height: 72px;
  }

  .object-topbar-metrics {
    gap: var(--space-1) !important;
  }

  .objects-page .object-daily-metric {
    background: var(--surface-2) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: none !important;
    color: var(--text-primary);
    gap: var(--space-2);
    height: 48px;
    padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
    transform: none !important;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard);
  }

  .objects-page .object-daily-metric:hover,
  .objects-page .object-daily-metric.is-active {
    background: var(--accent-soft) !important;
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border-default)) !important;
    box-shadow: 0 0 0 2px var(--focus-ring) !important;
  }

  .objects-page .object-metric-circle {
    background: transparent !important;
    border: 1px solid color-mix(in srgb, var(--accent) 62%, transparent) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-primary) !important;
    flex-basis: 38px;
    font-size: var(--font-size-16);
    font-variant-numeric: tabular-nums;
    height: 38px;
    min-width: 38px;
  }

  .objects-page .object-daily-metric strong {
    color: var(--text-primary) !important;
    font-size: var(--font-size-12);
    font-weight: 600;
  }

  .objects-page .object-daily-metric small {
    color: var(--text-tertiary);
    font-size: var(--font-size-10);
  }

  .metric-delta.positive {
    color: var(--success) !important;
  }

  .metric-delta.negative {
    color: var(--danger) !important;
  }

  .metric-delta.neutral {
    color: var(--text-tertiary) !important;
  }

  .objects-agent-tabs-panel {
    background: transparent !important;
    border: 0 !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .objects-agent-tabs-panel .avito-agent-tabs {
    flex-wrap: nowrap;
    gap: var(--space-1);
    overflow-x: auto;
    padding: 0 0 var(--space-1);
  }

  .objects-agent-tabs-row .avito-agent-tab,
  .objects-agent-tabs-row .avito-agent-tab.is-tournament-leader {
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-md) !important;
    box-shadow: none !important;
    color: var(--text-secondary) !important;
    font-size: var(--font-size-14) !important;
    font-weight: 600;
    min-height: 40px !important;
    padding: var(--space-2) var(--space-3) !important;
    transform: none !important;
    transition:
      background-color var(--motion-normal) var(--ease-standard),
      border-color var(--motion-normal) var(--ease-standard),
      color var(--motion-normal) var(--ease-standard);
  }

  .objects-agent-tabs-row .avito-agent-tab:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
  }

  .objects-agent-tabs-row .avito-agent-tab.is-active,
  .objects-agent-tabs-row .avito-agent-tab.is-tournament-leader.is-active {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .objects-agent-tabs-row .avito-agent-tab.is-tournament-leader:not(.is-active) {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: var(--text-on-accent) !important;
    box-shadow: 0 5px 13px color-mix(in srgb, var(--accent) 28%, transparent) !important;
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress {
    display: inline-flex;
    align-items: stretch;
    flex: 0 0 auto;
    gap: 0;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
    border-radius: 999px;
    background: var(--surface-1);
    transition: border-color var(--motion-normal) var(--ease-standard), background-color var(--motion-normal) var(--ease-standard);
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress .avito-agent-tab {
    min-height: 38px !important;
    padding: var(--space-2) 10px var(--space-2) 13px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-primary) !important;
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress .agent-plan-progress {
    min-width: 48px;
    min-height: 38px;
    padding: 0 10px;
    border: 0;
    border-left: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
    border-radius: 0;
    background: color-mix(in srgb, var(--accent) 8%, var(--surface-1));
    color: var(--accent);
    font-size: var(--font-size-12);
    font-weight: 750;
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-active,
  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-leader {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: 0 5px 13px color-mix(in srgb, var(--accent) 24%, transparent);
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-active .avito-agent-tab,
  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-leader .avito-agent-tab,
  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-active .agent-plan-progress,
  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-leader .agent-plan-progress {
    color: var(--text-on-accent) !important;
  }

  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-active .agent-plan-progress,
  .objects-agent-tabs-row .objects-agent-tab-wrap.has-plan-progress.is-leader .agent-plan-progress {
    border-left-color: color-mix(in srgb, var(--text-on-accent) 46%, transparent);
    background: color-mix(in srgb, var(--text-on-accent) 10%, transparent);
  }

  .sheet-toolbar {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: none !important;
    padding: var(--space-2) var(--space-3) !important;
  }

  .sheet-toolbar .filters {
    gap: var(--space-2);
  }

  .sheet-toolbar .search,
  .sheet-toolbar .multi-filter-toggle,
  .sheet-toolbar .objects-filter-control {
    height: 38px !important;
    min-height: 38px !important;
  }

  .sheet-toolbar .search {
    background: var(--surface-2) !important;
  }

  .sheet-toolbar .search input {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    min-height: 36px;
  }

  .multi-filter.has-selection .multi-filter-toggle {
    background: var(--accent-soft) !important;
    border-color: color-mix(in srgb, var(--accent) 50%, var(--border-default)) !important;
    color: var(--accent) !important;
  }

  .multi-filter-toggle > b {
    background: var(--surface-3) !important;
    color: var(--text-secondary) !important;
    font-variant-numeric: tabular-nums;
    min-width: 22px;
  }

  .multi-filter.has-selection .multi-filter-toggle > b {
    background: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .multi-filter-panel,
  .planned-address-results {
    animation: telegram-popover-in var(--motion-normal) var(--ease-out);
    background: var(--surface-1) !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-primary);
    transform-origin: top center;
  }

  .multi-filter-panel header,
  .multi-filter-panel footer {
    border-color: var(--border-subtle) !important;
  }

  .multi-filter-options label:hover,
  .planned-address-results button:hover {
    background: var(--surface-hover) !important;
  }

  .objects-filter-control {
    background: var(--surface-2) !important;
    color: var(--text-secondary) !important;
    font-size: var(--font-size-13) !important;
    font-weight: 500 !important;
  }

  .objects-filter-control:has(input:checked) {
    background: var(--accent-soft) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
  }

  .objects-page .filters .missing-advertising-button {
    background: var(--danger) !important;
    border: 1px solid var(--danger) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-on-accent) !important;
    font-size: var(--font-size-13) !important;
    font-weight: 600 !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 var(--space-3) !important;
  }

  .objects-page .filters .missing-advertising-button:hover,
  .objects-page .filters .missing-advertising-button.is-active {
    background: var(--danger-hover) !important;
    border-color: var(--danger-hover) !important;
  }

  .objects-page .filters .missing-advertising-button.is-zero {
    background: var(--surface-1) !important;
    border-color: var(--border-default) !important;
    color: var(--danger) !important;
  }

  .objects-page .filters .objects-new-button {
    background: var(--accent) !important;
    border: 1px solid var(--accent) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-on-accent) !important;
    font-size: var(--font-size-13) !important;
    font-weight: 600 !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 var(--space-4) !important;
  }

  .objects-page .filters .objects-new-button:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    color: var(--text-on-accent) !important;
  }

  .sheet-save-state {
    color: var(--text-tertiary);
    font-size: var(--font-size-11);
    font-weight: 500;
  }

  .sheet-save-state i {
    background: var(--success);
    box-shadow: none;
  }

  .sheet-save-state.saving i {
    background: var(--warning);
  }

  .sheet-save-state.error,
  .sheet-save-state.error i {
    color: var(--danger);
  }

  .sheet-hint {
    color: var(--text-tertiary);
    font-size: var(--font-size-11);
    min-height: 24px;
  }

  .sheet-hint b {
    color: var(--text-secondary);
    font-weight: 600;
  }

  .formula-key i {
    background: var(--surface-3);
    border-color: var(--border-subtle);
  }

  /* Main object table. */
  .sheet-panel {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: none !important;
  }

  .objects-table {
    background: var(--surface-1);
    overscroll-behavior: contain;
  }

  .crm-sheet {
    color: var(--text-primary);
    font-size: var(--font-size-12);
    font-variant-numeric: tabular-nums;
  }

  .crm-sheet th {
    background: var(--surface-2) !important;
    border-bottom: 1px solid var(--border-default) !important;
    color: var(--text-secondary) !important;
    font-size: var(--font-size-10);
    font-weight: 600;
    height: 36px;
    letter-spacing: 0.02em;
    padding: var(--space-1) var(--space-2);
  }

  .crm-sheet td {
    background: var(--surface-1);
    border-bottom: 1px solid var(--border-subtle) !important;
    color: var(--text-primary);
    height: 36px;
    max-height: 36px;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard);
  }

  .crm-sheet .sheet-cell,
  .crm-sheet .formula-col {
    background: var(--surface-1) !important;
  }

  .crm-sheet tbody tr:hover td,
  .crm-sheet tbody tr:hover .sheet-cell,
  .crm-sheet tbody tr:hover .formula-col {
    background: var(--table-row-hover) !important;
  }

  .crm-sheet .sticky-id,
  .crm-sheet .sticky-agent,
  .crm-sheet .sticky-address,
  .crm-sheet .sticky-ad-status,
  .crm-sheet .sticky-task,
  .crm-sheet .sticky-object-status,
  .crm-sheet .sticky-category {
    background: var(--surface-1) !important;
  }

  .crm-sheet thead .sticky-id,
  .crm-sheet thead .sticky-agent,
  .crm-sheet thead .sticky-address,
  .crm-sheet thead .sticky-ad-status,
  .crm-sheet thead .sticky-task,
  .crm-sheet thead .sticky-object-status,
  .crm-sheet thead .sticky-category {
    background: var(--surface-2) !important;
  }

  .crm-sheet .sticky-category {
    box-shadow: 1px 0 0 var(--border-default);
  }

  .crm-sheet .sheet-control {
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    font-size: var(--font-size-12);
    height: 35px;
    min-height: 35px;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      border-color var(--motion-fast) var(--ease-standard),
      box-shadow var(--motion-fast) var(--ease-standard);
  }

  .crm-sheet .sheet-control:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-default) !important;
  }

  .crm-sheet .sheet-control:focus {
    background: var(--surface-1) !important;
    border-color: var(--accent) !important;
    box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 2px var(--focus-ring) !important;
  }

  .crm-sheet .sheet-value {
    color: var(--text-primary);
    font-size: var(--font-size-12);
    line-height: 1.35;
  }

  .crm-sheet .id-cell .sheet-control,
  .crm-sheet .id-cell > a:not(.sheet-open),
  .crm-sheet .address-cell .sheet-control,
  .crm-sheet .address-cell .sheet-value {
    font-weight: 600;
  }

  .sheet-open {
    color: var(--text-tertiary) !important;
    transition:
      background-color var(--motion-fast) var(--ease-standard),
      color var(--motion-fast) var(--ease-standard);
  }

  .sheet-open:hover {
    color: var(--accent) !important;
  }

  .crm-sheet .address-cell-inner .address-crm-open {
    background: var(--surface-2) !important;
    border-color: var(--border-default) !important;
    color: var(--text-secondary) !important;
  }

  .crm-sheet .address-cell-inner .address-crm-open:hover {
    background: var(--accent-soft) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
  }

  .crm-sheet .metric-today-row:not(.row-deal):not(.row-sold):not(.row-refused) td {
    background: var(--table-row-selected) !important;
  }

  .crm-sheet .metric-today-row .sticky-id {
    box-shadow: inset 3px 0 var(--accent);
  }

  .crm-sheet .row-deal td,
  .crm-sheet .row-deal .sheet-cell {
    background: var(--purple-soft-ui) !important;
  }

  .crm-sheet .row-sold td,
  .crm-sheet .row-sold .sheet-cell {
    background: var(--cyan-soft-ui) !important;
  }

  .crm-sheet .row-refused td,
  .crm-sheet .row-refused .sheet-cell {
    background: var(--danger-soft) !important;
  }

  .crm-sheet .row-deposit .address-cell {
    background: var(--surface-1) !important;
  }

  .crm-sheet .row-deposit .address-cell-inner {
    background: var(--purple-soft-ui) !important;
    border-radius: var(--radius-sm);
  }

  .crm-sheet .task-cell.has-task {
    background: var(--warning-soft) !important;
    color: var(--text-primary) !important;
  }

  .crm-sheet .task-cell.task-missing-agreed {
    background: var(--danger-soft) !important;
    color: var(--danger) !important;
  }

  .crm-sheet .task-cell.task-missing-agreed .sheet-control,
  .crm-sheet .task-cell.task-missing-agreed .sheet-value {
    color: var(--danger) !important;
  }

  .crm-sheet .id-cell.id-advertising-warning {
    background: var(--surface-1) !important;
  }

  .crm-sheet .id-cell.id-advertising-warning .sheet-control,
  .crm-sheet .id-cell.id-advertising-warning > a:not(.sheet-open) {
    background: var(--danger-soft) !important;
    border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--border-default)) !important;
    color: var(--danger) !important;
  }

  .crm-sheet .deposit-date-missing .object-status-col .sheet-control,
  .crm-sheet .deposit-date-missing .object-status-col .sheet-value {
    background: var(--danger-soft) !important;
    border-color: var(--danger) !important;
    color: var(--danger) !important;
  }

  .crm-sheet .publication-age.age-fresh {
    background: var(--success-soft) !important;
    color: var(--success) !important;
  }

  .crm-sheet .age-mature,
  .crm-sheet .age-normal,
  .crm-sheet .age-old {
    background: var(--surface-3) !important;
    color: var(--text-secondary) !important;
  }

  .crm-sheet .category,
  .status-chip,
  .role-chip,
  .deviation {
    border-radius: var(--radius-pill);
    font-size: var(--font-size-11);
    font-weight: 600;
    min-height: 22px;
  }

  .category-aplus {
    background: var(--success) !important;
    color: var(--text-on-accent) !important;
  }

  .category-a {
    background: var(--success-soft) !important;
    color: var(--success) !important;
  }

  .category-b {
    background: var(--warning-soft) !important;
    color: var(--warning) !important;
  }

  .category-c {
    background: var(--danger-soft) !important;
    color: var(--danger) !important;
  }

  .category-none {
    background: var(--surface-3) !important;
    color: var(--text-tertiary) !important;
  }

  .deviation-good {
    background: var(--success-soft) !important;
    color: var(--success) !important;
  }

  .deviation-warn {
    background: var(--warning-soft) !important;
    color: var(--warning) !important;
  }

  .deviation-bad {
    background: var(--danger-soft) !important;
    color: var(--danger) !important;
  }

  .ad-platform-indicator {
    background: var(--surface-3) !important;
    border-color: var(--border-default) !important;
    color: var(--text-tertiary) !important;
  }

  .ad-platform-indicator.is-active {
    color: var(--text-on-accent) !important;
  }

  .ad-platform-indicator.is-avito.is-active {
    background: conic-gradient(
      #00aaff 0 25%,
      #ff6163 25% 50%,
      #97cf26 50% 75%,
      #a169f7 75%
    ) !important;
    border-color: transparent !important;
    color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  }

  .ad-platform-indicator.is-cian.is-active {
    background: #0468ff !important;
    border-color: #0468ff !important;
    color: #ffffff !important;
  }

  .sheet-cell.is-saving {
    box-shadow: inset 0 -2px var(--warning);
  }

  .sheet-cell.save-success {
    animation: telegram-save-success 760ms var(--ease-out);
  }

  .sheet-cell.save-error {
    background: var(--danger-soft) !important;
    box-shadow: inset 0 0 0 1px var(--danger);
  }

  .objects-excel-scrollbar {
    background: var(--surface-2) !important;
    border-color: var(--border-default) !important;
    height: 24px;
  }

  .objects-excel-scrollbar > button,
  .objects-excel-scroll-rail {
    background: var(--surface-3) !important;
    border-color: var(--border-default) !important;
    color: var(--text-secondary) !important;
  }

  .objects-excel-scroll-thumb {
    background: var(--scroll-thumb) !important;
    border-color: transparent !important;
    border-radius: var(--radius-pill) !important;
  }

  /* Overlays, feedback and connected object scenarios. */
  dialog,
  dialog > section,
  .notification-popover,
  .tournament-popover,
  .object-ad-dialog-card,
  .ad-link-dialog-card,
  .calendar-dialog-card,
  .event-reminder-card,
  .planned-events-card,
  .planned-confirm-dialog > section {
    background: var(--surface-1) !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
  }

  dialog::backdrop {
    background: var(--overlay) !important;
    backdrop-filter: none !important;
  }

  dialog[open] > section,
  dialog[open] .object-ad-dialog-card,
  dialog[open] .ad-link-dialog-card,
  dialog[open] .calendar-dialog-card,
  dialog[open] .event-reminder-card,
  dialog[open] .planned-events-card {
    animation: telegram-dialog-in var(--motion-slow) var(--ease-out);
    border-radius: var(--radius-xl) !important;
    box-shadow: var(--shadow-md) !important;
  }

  .notification-popover,
  .tournament-popover {
    animation: telegram-popover-in var(--motion-normal) var(--ease-out);
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-md) !important;
  }

  .notification-popover > header,
  .tournament-popover > header {
    background: var(--surface-1) !important;
    border-color: var(--border-subtle) !important;
  }

  .notification-popover > header > button,
  .tournament-popover > header > button,
  dialog header > button[aria-label="Закрыть"],
  dialog header > button[data-object-ad-close] {
    background: var(--surface-3) !important;
    border: 0 !important;
    color: var(--text-secondary) !important;
  }

  .notification-item,
  .tournament-popover-list article,
  .tournament-popover-list .tournament-agent-filter {
    color: var(--text-primary) !important;
  }

  .notification-item:hover,
  .tournament-popover-list article:hover,
  .tournament-popover-list .tournament-agent-filter:hover {
    background: var(--surface-hover) !important;
  }

  .tournament-popover-list .tournament-agent-filter {
    align-items: center;
    appearance: none;
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    cursor: pointer;
    display: grid;
    font: inherit;
    gap: 8px;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    padding: 8px;
    text-align: left;
    text-decoration: none;
    transition: background var(--motion-fast) var(--ease-standard), border-color var(--motion-fast) var(--ease-standard);
    width: 100%;
  }

  .tournament-popover-list .tournament-agent-filter > b {
    align-items: center;
    background: var(--surface-3);
    border-radius: 8px;
    display: flex;
    height: 26px;
    justify-content: center;
  }

  .tournament-popover-list .tournament-agent-filter.is-podium {
    background: var(--warning-soft);
    border-color: color-mix(in srgb, var(--warning) 45%, var(--border-default));
  }

  .tournament-popover-list .tournament-agent-filter:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
    outline: 0;
  }

  .tournament-report > .tournament-archive {
    justify-self: start;
    position: relative;
  }

  .tournament-report > .tournament-archive > summary {
    align-items: center;
    cursor: pointer;
    display: inline-flex;
    font-size: 15px !important;
    gap: 8px;
    list-style: none;
    min-height: 38px;
    padding: 8px 15px;
  }

  .tournament-report > .tournament-archive > summary::-webkit-details-marker {
    display: none;
  }

  .tournament-report > .tournament-archive > summary b {
    align-items: center;
    background: var(--accent-soft);
    border-radius: var(--radius-pill);
    color: var(--accent);
    display: inline-flex;
    font-size: 12px;
    height: 24px;
    justify-content: center;
    min-width: 24px;
    padding: 0 7px;
  }

  .tournament-archive-panel {
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    display: grid;
    gap: 14px;
    left: 0;
    margin-top: 8px;
    max-height: min(72vh, 760px);
    overflow: auto;
    padding: 18px;
    position: absolute;
    width: min(1050px, calc(100vw - 340px));
    z-index: 125;
  }

  .tournament-archive-panel h3,
  .tournament-archive-panel h4,
  .tournament-archive-panel h5 {
    color: var(--text-primary);
    margin: 0;
  }

  .tournament-archive-panel h3 { font-size: 22px; }
  .tournament-archive-panel h4 { font-size: 20px; }
  .tournament-archive-panel h5 { font-size: 15px; }
  .tournament-archive-months { display: grid; gap: 14px; }

  .tournament-archive-month {
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    display: grid;
    gap: 10px;
    padding: 14px;
  }

  .tournament-archive-tables {
    align-items: start;
    display: grid;
    gap: 12px;
    grid-template-columns: max-content max-content;
  }

  .tournament-archive-tables > section {
    display: grid;
    gap: 7px;
  }

  .notification-item.is-unread {
    background: var(--accent-soft) !important;
  }

  .activity-toast,
  .flash {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-default) !important;
    border-left: 3px solid var(--accent) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-primary) !important;
  }

  .flash.success {
    background: var(--success-soft) !important;
    border-left-color: var(--success) !important;
    color: var(--success) !important;
  }

  .flash.error {
    background: var(--danger-soft) !important;
    border-left-color: var(--danger) !important;
    color: var(--danger) !important;
  }

  .photo-chat-launcher {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-on-accent) !important;
    right: var(--space-5);
  }

  .photo-chat-launcher:hover {
    background: var(--accent-hover) !important;
  }

  /* Embedded chat uses the same Telegram surfaces and controls as the CRM. */
  .photo-chat {
    --chat-bg: var(--app-bg) !important;
    --chat-panel: var(--surface-1) !important;
    --chat-panel-2: var(--surface-2) !important;
    --chat-control: var(--surface-3) !important;
    --chat-hover: var(--surface-hover) !important;
    --chat-line: var(--border-subtle) !important;
    --chat-text: var(--text-primary) !important;
    --chat-muted: var(--text-secondary) !important;
    --chat-blue: var(--accent) !important;
    --chat-blue-hover: var(--accent-hover) !important;
    --chat-in: var(--surface-1) !important;
    --chat-out: var(--accent-soft) !important;
    --chat-danger: var(--danger) !important;
  }

  .photo-chat-panel {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-xl) !important;
    box-shadow: var(--shadow-md) !important;
  }

  .photo-chat-head {
    background: var(--surface-1) !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    color: var(--text-primary) !important;
  }

  .photo-chat-head small,
  .team-chat-item-copy small,
  .team-chat-item-meta time,
  .team-chat-message-empty,
  .team-chat-directory-empty {
    color: var(--text-secondary) !important;
  }

  .photo-chat-head .team-chat-sound,
  .photo-chat-head .team-chat-expand {
    background: var(--surface-3) !important;
    color: var(--text-secondary) !important;
  }

  .photo-chat-head .team-chat-sound:hover,
  .photo-chat-head .team-chat-expand:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
  }

  .team-chat-directory {
    background: var(--surface-1) !important;
  }

  .team-chat-section-label {
    color: var(--accent) !important;
    font-size: 10px !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
  }

  .team-chat-pinned-list,
  .team-chat-private-list,
  .team-chat-group-list {
    overflow: hidden;
    background: var(--surface-1) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-lg) !important;
  }

  .team-chat-directory-item {
    background: var(--surface-1) !important;
    border-color: var(--border-subtle) !important;
    color: var(--text-primary) !important;
  }

  .team-chat-directory-item:hover {
    background: var(--surface-hover) !important;
  }

  .team-chat-directory-item.is-active {
    background: var(--accent-soft) !important;
    box-shadow: inset 3px 0 var(--accent) !important;
  }

  .team-chat-item-meta b {
    background: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .team-chat-message-list,
  .photo-chat-body {
    background: var(--app-bg) !important;
  }

  .team-chat-bubble,
  .photo-message.assistant {
    background: var(--surface-1) !important;
    border: 1px solid var(--border-subtle) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-sm) !important;
  }

  .team-chat-bubble.is-mine,
  .photo-message.user {
    background: var(--accent-soft) !important;
    border-color: color-mix(in srgb, var(--accent) 22%, transparent) !important;
  }

  .team-chat-bubble p,
  .team-chat-bubble > header,
  .team-chat-bubble > header b {
    color: var(--text-primary) !important;
  }

  .team-chat-compose,
  .team-chat-readonly,
  .photo-chat-foot {
    background: var(--surface-1) !important;
    border-color: var(--border-subtle) !important;
  }

  .team-chat-compose textarea {
    background: var(--surface-3) !important;
    border: 1px solid transparent !important;
    color: var(--text-primary) !important;
  }

  .team-chat-compose textarea:focus {
    background: var(--surface-3) !important;
    border-color: var(--accent) !important;
  }

  .team-chat-compose > button[type="submit"] {
    background: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .team-chat-compose > button[type="submit"]:hover {
    background: var(--accent-hover) !important;
  }

  .team-chat-compose .team-chat-attach,
  .team-chat-compose .team-chat-emoji-button {
    background: transparent !important;
    color: var(--text-secondary) !important;
  }

  .team-chat-compose .team-chat-attach:hover,
  .team-chat-compose .team-chat-emoji-button:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
  }

  /* Desktop chat readability: align its scale and typography with the CRM. */
  .photo-chat:not(.is-expanded) .photo-chat-panel {
    height: min(720px, calc(100vh - 110px));
    width: min(520px, calc(100vw - 44px));
  }

  .photo-chat-head {
    gap: 12px;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    min-height: 84px;
    padding: 14px 16px;
  }

  .photo-chat-head b {
    font-size: 19px;
    line-height: 1.2;
  }

  .photo-chat-head small {
    font-size: 14px;
    line-height: 1.35;
    margin-top: 5px;
  }

  .photo-chat-avatar {
    border-radius: 14px;
    font-size: 22px;
    height: 52px;
    width: 52px;
  }

  .team-chat-thread-head {
    grid-template-columns: 32px 52px minmax(0, 1fr) auto;
  }

  .photo-chat-head > .team-chat-back {
    font-size: 34px;
  }

  .photo-chat-head .team-chat-sound,
  .photo-chat-head .team-chat-expand,
  .photo-chat-head .team-chat-close {
    min-height: 42px;
  }

  .photo-chat-head .team-chat-sound {
    border-radius: 12px;
    font-size: 19px;
    height: 42px;
    width: 42px;
  }

  .photo-chat-head .team-chat-expand {
    border-radius: 12px;
    gap: 7px;
    padding: 0 13px;
  }

  .photo-chat-head .team-chat-expand > span {
    font-size: 19px;
  }

  .photo-chat-head .team-chat-expand > b {
    font-size: 13px;
  }

  .photo-chat-head .team-chat-close {
    font-size: 29px;
    width: 38px;
  }

  .team-chat-directory {
    padding: 18px 16px 24px;
  }

  .team-chat-section-label {
    font-size: 14px !important;
    font-weight: 800;
    margin: 4px 10px 10px;
  }

  .team-chat-section-label.is-private {
    margin-top: 22px;
  }

  .team-chat-pinned-list,
  .team-chat-private-list,
  .team-chat-group-list {
    border-radius: 18px !important;
  }

  .team-chat-section-heading {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-top: 22px;
  }

  .team-chat-section-heading .team-chat-section-label {
    margin-top: 0;
  }

  .team-chat-create-group {
    background: transparent;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    padding: 3px 10px 10px;
  }

  .team-chat-create-group:hover {
    color: var(--accent-hover);
  }

  .team-chat-group-list {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
  }

  .team-chat-item-avatar.is-group,
  .team-chat-thread-avatar.is-group {
    background: var(--purple) !important;
    color: #fff !important;
  }

  .team-chat-directory-item {
    gap: 14px;
    grid-template-columns: 58px minmax(0, 1fr) auto;
    min-height: 88px;
    padding: 12px 14px;
  }

  .team-chat-item-avatar {
    border-radius: 16px;
    font-size: 21px;
    height: 58px;
    width: 58px;
  }

  .team-chat-item-avatar.is-direct {
    font-size: 17px;
  }

  .team-chat-item-copy b {
    font-size: 17px;
    line-height: 1.25;
  }

  .team-chat-item-copy small {
    font-size: 14px;
    line-height: 1.3;
    margin-top: 6px;
  }

  .team-chat-item-pin {
    font-size: 22px;
  }

  .team-chat-item-meta {
    gap: 9px;
    min-width: 42px;
  }

  .team-chat-item-meta time {
    font-size: 12px;
    min-height: 15px;
  }

  .team-chat-item-meta b {
    font-size: 11px;
    height: 24px;
    min-width: 24px;
    padding: 0 7px;
  }

  .team-chat-directory-empty,
  .team-chat-message-empty {
    font-size: 14px;
    line-height: 1.4;
  }

  .team-chat-message-list,
  .photo-chat-body {
    gap: 12px;
    padding: 18px;
  }

  .team-chat-bubble {
    border-radius: 16px;
    gap: 6px;
    max-width: 88%;
    padding: 12px 14px;
  }

  .team-chat-bubble > header {
    font-size: 12px;
    gap: 9px;
  }

  .team-chat-bubble > header b {
    font-size: 13px;
  }

  .team-chat-bubble p,
  .photo-message {
    font-size: 16px;
    line-height: 1.45;
  }

  .team-chat-reply-quote b,
  .team-chat-reply-quote small {
    font-size: 12px;
    max-width: 330px;
  }

  .team-chat-message-status,
  .team-chat-message-views {
    font-size: 11px;
  }

  .team-chat-message-error,
  .team-chat-readonly {
    font-size: 13px;
    line-height: 1.4;
  }

  .team-chat-compose {
    gap: 10px;
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
    padding: 12px 14px;
  }

  .team-chat-compose textarea {
    border-radius: 14px;
    font-size: 16px;
    line-height: 1.4;
    max-height: 150px;
    min-height: 44px;
    padding: 10px 13px;
  }

  .team-chat-compose button,
  .team-chat-compose .team-chat-attach,
  .team-chat-compose .team-chat-emoji-button {
    border-radius: 12px;
    font-size: 20px;
    height: 44px;
    width: 44px;
  }

  .team-chat-reply-draft b,
  .team-chat-selected-copy b,
  .team-chat-attachment-footer b,
  .team-chat-file-card b {
    font-size: 13px;
  }

  .team-chat-reply-draft small,
  .team-chat-selected-copy small,
  .team-chat-attachment-footer small,
  .team-chat-file-card small {
    font-size: 12px;
  }

  .team-chat-message-actions button,
  .team-chat-viewer-row b,
  .team-chat-viewers header small {
    font-size: 13px;
  }

  .team-chat-viewers header b {
    font-size: 16px;
  }

  .team-chat-viewer-row time,
  .team-chat-viewers-empty,
  .team-chat-image-preview > small {
    font-size: 12px;
  }

  .team-chat-group-dialog {
    align-items: center;
    background: color-mix(in srgb, var(--text-primary) 40%, transparent);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 22px;
    position: absolute;
    z-index: 40;
  }

  .team-chat-group-dialog[hidden] {
    display: none;
  }

  .team-chat-group-dialog > form {
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    display: grid;
    gap: 16px;
    max-height: min(620px, calc(100vh - 160px));
    overflow: hidden;
    padding: 18px;
    width: min(430px, 100%);
  }

  .team-chat-group-dialog header {
    align-items: center;
    display: flex;
    justify-content: space-between;
  }

  .team-chat-group-dialog header b,
  .team-chat-group-dialog header small {
    display: block;
  }

  .team-chat-group-dialog header b {
    color: var(--text-primary);
    font-size: 20px;
  }

  .team-chat-group-dialog header small {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 4px;
  }

  .team-chat-group-dialog header button {
    background: var(--surface-3);
    border: 0;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 25px;
    height: 38px;
    width: 38px;
  }

  .team-chat-group-name {
    display: grid;
    gap: 7px;
  }

  .team-chat-group-name > span,
  .team-chat-group-dialog legend {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 750;
  }

  .team-chat-group-name input {
    background: var(--surface-3);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-primary);
    font: inherit;
    font-size: 15px;
    min-height: 46px;
    outline: none;
    padding: 10px 12px;
  }

  .team-chat-group-name input:focus {
    border-color: var(--accent);
  }

  .team-chat-group-dialog fieldset {
    border: 0;
    display: grid;
    gap: 8px;
    margin: 0;
    min-height: 0;
    padding: 0;
  }

  .team-chat-group-dialog fieldset > div {
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    max-height: 300px;
    overflow: auto;
  }

  .team-chat-group-dialog fieldset label {
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    display: grid;
    gap: 10px;
    grid-template-columns: 20px 38px minmax(0, 1fr);
    min-height: 58px;
    padding: 8px 10px;
  }

  .team-chat-group-dialog fieldset label:last-child {
    border-bottom: 0;
  }

  .team-chat-group-dialog fieldset label:hover {
    background: var(--surface-hover);
  }

  .team-chat-group-dialog fieldset input {
    accent-color: var(--accent);
    height: 18px;
    width: 18px;
  }

  .team-chat-group-member-avatar {
    align-items: center;
    background: var(--purple);
    border-radius: 50%;
    color: #fff;
    display: flex;
    font-size: 11px;
    font-weight: 850;
    height: 38px;
    justify-content: center;
    width: 38px;
  }

  .team-chat-group-dialog fieldset label > span:last-child b,
  .team-chat-group-dialog fieldset label > span:last-child small {
    display: block;
  }

  .team-chat-group-dialog fieldset label > span:last-child b {
    color: var(--text-primary);
    font-size: 14px;
  }

  .team-chat-group-dialog fieldset label > span:last-child small {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 3px;
  }

  .team-chat-group-error {
    background: var(--danger-soft);
    border-radius: 10px;
    color: var(--danger);
    font-size: 13px;
    margin: 0;
    padding: 9px 11px;
  }

  .team-chat-group-submit {
    background: var(--accent);
    border: 0;
    border-radius: 12px;
    color: var(--text-on-accent);
    cursor: pointer;
    font: inherit;
    font-size: 15px;
    font-weight: 800;
    min-height: 46px;
  }

  .team-chat-group-submit:hover {
    background: var(--accent-hover);
  }

  .team-chat-group-submit:disabled {
    cursor: wait;
    opacity: .6;
  }

  .photo-chat-foot {
    font-size: 14px;
    min-height: 92px;
  }

  .photo-result-card .button {
    font-size: 14px;
    min-height: 42px;
  }

  /* Objects: manager control date and missing priority status warnings. */
  .crm-sheet .control-date-col {
    min-width: 92px;
    width: 92px;
  }

  .sheet-hint-actions {
    align-items: center;
    display: flex;
    gap: var(--space-3);
    margin-left: auto;
  }

  .object-table-edit-button {
    align-items: center;
    background: var(--surface-1) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    display: inline-flex;
    font-size: 18px !important;
    min-height: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;
    padding: 0 !important;
    width: 34px !important;
    justify-content: center;
  }

  .object-table-edit-button span {
    line-height: 1;
  }

  .object-table-edit-button[aria-pressed="true"] {
    background: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .object-table-editor {
    align-items: end;
    display: grid;
    gap: var(--space-4);
    grid-template-columns: minmax(260px, 1fr) auto minmax(320px, .9fr) auto;
    margin-bottom: var(--space-3);
    padding: var(--space-4) var(--space-5) !important;
  }

  .object-table-editor[hidden] {
    display: none !important;
  }

  .object-table-editor-copy {
    display: grid;
    gap: 3px;
  }

  .object-table-editor-copy b {
    font-size: var(--font-size-14);
  }

  .object-table-editor-copy span,
  .object-layout-save-state {
    color: var(--text-secondary);
    font-size: var(--font-size-11);
  }

  .object-layout-save-state {
    grid-column: 1 / -1;
  }

  .object-layout-save-state.is-error {
    color: var(--danger);
  }

  .object-row-height-control {
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    display: grid;
    gap: var(--space-2);
    grid-template-columns: auto 32px 58px 32px;
    min-height: 42px;
    padding: var(--space-1) var(--space-2) var(--space-1) var(--space-3);
  }

  .object-row-height-control span,
  .object-row-height-control b {
    font-size: var(--font-size-11);
    white-space: nowrap;
  }

  .object-row-height-control button,
  .object-hidden-columns button {
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 800;
  }

  .object-row-height-control button {
    height: 30px;
    width: 32px;
  }

  .object-custom-column-form {
    align-items: end;
    display: grid;
    gap: var(--space-2);
    grid-template-columns: minmax(210px, 1fr) auto;
  }

  .object-custom-column-form label {
    display: grid;
    gap: 4px;
  }

  .object-custom-column-form label span {
    color: var(--text-secondary);
    font-size: var(--font-size-10);
    font-weight: 700;
  }

  .object-custom-column-form input {
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    min-height: 38px;
    padding: 0 var(--space-3);
  }

  .object-hidden-columns {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    grid-column: 1 / -1;
  }

  .object-hidden-columns > span,
  .object-hidden-columns > b {
    color: var(--text-secondary);
    font-size: var(--font-size-11);
  }

  .object-hidden-columns button {
    color: var(--accent);
    font-size: var(--font-size-10);
    min-height: 28px;
    padding: 0 var(--space-3);
  }

  .crm-sheet th,
  .crm-sheet td {
    height: var(--object-row-height, 36px) !important;
    max-height: var(--object-row-height, 36px) !important;
  }

  .crm-sheet .sheet-control {
    height: calc(var(--object-row-height, 36px) - 1px) !important;
    min-height: calc(var(--object-row-height, 36px) - 1px) !important;
  }

  .crm-sheet .custom-object-column {
    min-width: 140px;
    width: 140px;
  }

  .crm-sheet thead th {
    position: relative;
  }

  .object-column-layout-controls,
  .object-column-resize {
    display: none;
  }

  .crm-sheet.is-layout-editing thead th {
    border-top: 2px solid var(--accent) !important;
    cursor: grab;
    padding-right: 68px !important;
    user-select: none;
  }

  .object-column-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .object-column-name-input {
    background: var(--surface-1);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: var(--text-primary);
    font: inherit;
    height: 26px;
    left: 4px;
    min-width: 100px;
    padding: 2px 7px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: calc(100% - 76px);
    z-index: 16;
  }

  .crm-sheet.is-layout-editing .object-column-layout-controls {
    align-items: center;
    display: flex;
    gap: 1px;
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 12;
  }

  .object-column-layout-controls button {
    align-items: center;
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    font-size: 11px;
    height: 22px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 20px;
  }

  .object-column-layout-controls .object-column-remove:hover {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
  }

  .object-column-layout-controls .object-column-rename:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
  }

  .crm-sheet.is-layout-editing .object-column-resize {
    bottom: 0;
    cursor: col-resize;
    display: block;
    position: absolute;
    right: -4px;
    top: 0;
    width: 8px;
    z-index: 14;
  }

  .crm-sheet.is-layout-editing .object-column-resize::after {
    background: color-mix(in srgb, var(--accent) 55%, transparent);
    bottom: 5px;
    content: "";
    position: absolute;
    right: 3px;
    top: 5px;
    width: 2px;
  }

  .crm-sheet.is-layout-editing th.is-dragging {
    opacity: .45;
  }

  .crm-sheet.is-layout-editing th.is-drop-target {
    box-shadow: inset 4px 0 var(--accent) !important;
  }

  body.is-resizing-object-column,
  body.is-resizing-object-column * {
    cursor: col-resize !important;
    user-select: none !important;
  }

  .crm-sheet td.object-status-missing-priority,
  .crm-sheet td.agreed-control-due {
    background: var(--danger) !important;
    border-color: var(--danger) !important;
    color: var(--text-on-accent) !important;
  }

  .crm-sheet .object-status-missing-priority .sheet-control,
  .crm-sheet .object-status-missing-priority .sheet-value,
  .crm-sheet .agreed-control-due .sheet-control,
  .crm-sheet .agreed-control-due .sheet-value {
    background-color: var(--danger) !important;
    border-color: var(--danger) !important;
    border-radius: var(--radius-pill) !important;
    color: var(--text-on-accent) !important;
    font-weight: 800;
  }

  /* Calendar: restore the full-size daily panels while keeping the redesign. */
  .schedule-page .calendar-daily-overview {
    align-items: stretch !important;
    height: auto;
  }

  .schedule-page .calendar-today-report {
    height: auto !important;
    min-height: 0 !important;
    max-height: none;
    overflow: visible;
  }

  .schedule-page .calendar-feed-preview {
    align-self: stretch;
    height: auto !important;
    min-height: 0 !important;
    max-height: none;
    overflow: hidden;
  }

  .schedule-page .calendar-today-report {
    background: #17212b !important;
    border-color: #223342 !important;
    color: #ffffff !important;
  }

  .schedule-page .calendar-today-report .eyebrow,
  .schedule-page .calendar-today-report header > span,
  .schedule-page .calendar-today-report p {
    color: #aeb9c3 !important;
  }

  .schedule-page .calendar-today-columns {
    max-height: none;
    overflow: visible;
  }

  .schedule-page .calendar-feed-preview {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .schedule-page .calendar-feed-preview .calendar-feed-list {
    align-content: start;
    gap: 8px;
    height: 100%;
    max-height: none !important;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-event {
    align-items: center;
    gap: 10px;
    grid-template-columns: 38px minmax(0, 1fr) !important;
    height: auto;
    min-height: 66px !important;
    overflow: hidden;
    padding: 8px 10px !important;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-content {
    align-items: center;
    display: flex;
    gap: 10px;
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-main {
    flex: 1 1 auto;
    min-width: 0;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-main b {
    display: block;
    font-size: 22px !important;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-main small {
    display: block;
    font-size: 16px !important;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-main em {
    display: none !important;
  }

  .schedule-page .calendar-feed-preview .calendar-event-status {
    flex: 0 0 auto;
    font-size: 16px !important;
    justify-self: auto;
    margin: 0;
    white-space: nowrap;
  }

  .schedule-page .calendar-feed-preview .calendar-feed-icon {
    font-size: 20px !important;
    height: 38px;
    width: 38px;
  }

  /* Completed items in "События сегодня" stay readable, but recede visually. */
  .schedule-page .calendar-today-event.status-completed {
    background: var(--surface-3) !important;
    border-left-color: var(--text-disabled) !important;
    box-shadow: none !important;
    color: var(--text-secondary) !important;
    filter: grayscale(1) saturate(0.12);
    opacity: 0.64;
  }

  .schedule-page .calendar-today-event.status-completed .calendar-today-event-time,
  .schedule-page .calendar-today-event.status-completed b {
    color: var(--text-secondary) !important;
  }

  .schedule-page .calendar-today-event.status-completed small {
    color: var(--text-tertiary) !important;
  }

  .schedule-page .calendar-today-event.status-completed:hover,
  .schedule-page .calendar-today-event.status-completed:focus-visible {
    background: var(--surface-hover) !important;
    opacity: 0.82;
  }

  .schedule-page .calendar-feed-event.status-completed {
    background: var(--surface-3) !important;
    border-color: var(--border-default) !important;
    box-shadow: none !important;
    color: var(--text-secondary) !important;
    filter: grayscale(1) saturate(0.12);
    opacity: 0.64;
  }

  .schedule-page .calendar-feed-event.status-completed .calendar-feed-icon,
  .schedule-page .calendar-feed-event.status-completed .calendar-event-status {
    background: var(--border-default) !important;
    color: var(--text-secondary) !important;
  }

  .schedule-page .calendar-feed-event.status-completed .calendar-feed-main b,
  .schedule-page .calendar-feed-event.status-completed .calendar-feed-main small {
    color: var(--text-secondary) !important;
  }

  .schedule-page .calendar-feed-event.status-completed:hover,
  .schedule-page .calendar-feed-event.status-completed:focus-visible {
    background: var(--surface-hover) !important;
    opacity: 0.82;
  }

  /* Other pages inherit the same visual grammar without changing layout. */
  .calculated-card,
  .showing-row,
  .type-matrix > div,
  .result-count,
  .org-person,
  .calendar-event-brief,
  .calendar-listing-summary,
  .planned-event-editor,
  .event-reminder-brief,
  .admin-edit-form,
  .suggestion-ticket,
  .suggestion-chat,
  .focus-card,
  .valuation-card {
    background: var(--surface-2) !important;
    border-color: var(--border-subtle) !important;
    color: var(--text-primary) !important;
  }

  .calendar-month-day,
  .calendar-feed-event,
  .schedule-cell,
  .ad-agent-group,
  .ad-agent-column li {
    background-color: var(--surface-1);
    border-color: var(--border-subtle);
    color: var(--text-primary);
  }

  .calendar-month-day.is-weekend,
  .schedule-cell.is-weekend {
    background-color: var(--surface-2);
  }

  .avito-agent-tab {
    background: var(--surface-2) !important;
    border-color: var(--border-subtle) !important;
    color: var(--text-secondary) !important;
  }

  .avito-agent-tab:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
  }

  .avito-agent-tab.is-active {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  /* Remove legacy decorative gradients and the old red action accent. */
  .objects-new-button.button.primary,
  html[data-theme="dark"] .objects-new-button.button.primary {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  .objects-new-button.button.primary:hover,
  html[data-theme="dark"] .objects-new-button.button.primary:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
  }

  .parser-feed-tabs button.is-active,
  html[data-theme="dark"] .parser-feed-tabs button.is-active {
    background: var(--accent-soft) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
  }

  .tournament-number,
  html[data-theme="dark"] .tournament-number {
    color: var(--accent) !important;
  }

  .object-metric-report,
  .photo-bot-report,
  .activity-rating-row.is-leader,
  .team-chat-message-list,
  .photo-chat-body {
    background-image: none !important;
  }

  .activity-rating-row.is-leader {
    background-color: var(--accent-soft) !important;
  }

  .bar-row i,
  .activity-rating-bar i,
  .photo-bot-day i,
  .photo-bot-action-track i,
  .report-column-area i.new-object {
    background: var(--accent) !important;
  }

  .photo-bot-action-track i.cleanup,
  .report-financial-track i.deposit,
  .report-column-area i.deposit {
    background: var(--purple) !important;
  }

  .report-financial-track i.deal,
  .report-column-area i.deal {
    background: var(--success) !important;
  }

  .photo-bot-admin-badge,
  .team-chat-item-avatar.is-photo,
  .team-chat-item-avatar.is-general,
  .photo-chat-avatar {
    background: var(--accent) !important;
    color: var(--text-on-accent) !important;
  }

  @keyframes telegram-popover-in {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes telegram-dialog-in {
    from {
      opacity: 0;
      transform: translateY(8px) scale(0.98);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  @keyframes telegram-save-success {
    0%, 45% {
      background: var(--success-soft);
      box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--success) 48%, transparent);
    }
    100% {
      background: var(--surface-1);
      box-shadow: none;
    }
  }
}

@media (min-width: 901px) {
  .schedule-page .calendar-month-event.is-birthday {
    background: #3390ec !important;
    border-color: #3390ec !important;
    color: #fff !important;
  }
  .schedule-page .calendar-month-event.is-birthday .calendar-event-primary,
  .schedule-page .calendar-month-event.is-birthday .calendar-event-primary b {
    color: inherit !important;
  }
  .parser-flat-deviation {
    display: inline-block;
    border-radius: 8px;
    padding: 4px 7px;
    font-weight: 800;
  }
  .parser-flat-deviation.is-excluded { background: #7137a8; color: #fff !important; }
  .parser-flat-deviation.is-best { background: #167448; color: #fff !important; }
  .parser-flat-deviation.is-good { background: #cbefd7; color: #185a32 !important; }
  .parser-flat-deviation.is-mid { background: #ffec99; color: #654c00 !important; }
  .parser-flat-deviation.is-high { background: #fbd0d0; color: #8c2020 !important; }
  .parser-flat-deviation.is-highest { background: #982832; color: #fff !important; }
  .tournament-announcement-leaders .tournament-announcement-score {
    display: block;
    margin-top: 6px;
    color: var(--text-primary, var(--text));
    font-size: 28px;
    font-weight: 900;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
