/* ITS CRM page system: one look for every section, matching the home dashboard (home.css).
   Loaded last. Covers page headers, segmented tabs, stat tiles, panels and modal headers.
   Selectors are prefixed with :root[data-theme] #page to outrank older per-module rules (some use #page). */

:root {
  --page-shadow: 0 1px 2px var(--shadow-color), 0 4px 16px var(--shadow-color);
  --workspace-heading-gap: var(--sp-5);   /* header → content, used by workspace-grid.css */
}

/* ---------- Page header: title, subtitle, actions on the right ---------- */
:root[data-theme] #page :is(.page-head, .deal-header, .drive-heading, .task-page-heading, .mail-work-heading, .ai-heading) {
  margin-bottom: var(--sp-5);
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  min-height: 0;
}
:root[data-theme] #page :is(.page-head, .deal-header, .drive-heading, .task-page-heading, .mail-work-heading, .ai-heading)::after { content: none; }
:root[data-theme] #page:not([data-page="dashboard"]) h1 {
  margin: 0;
  font-size: var(--fs-4xl);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.02em;
  color: var(--ink);
}
:root[data-theme] #page :is(.page-subtitle, .page-head .subtitle, .task-heading-note, .ai-heading h1 + p) {
  display: block;
  margin: 6px 0 0;
  font-size: var(--fs-md);
  font-weight: 400;
  line-height: 1.5;
  color: var(--muted);
}
:root[data-theme] #page .page-head .eyebrow { display: none; }
:root[data-theme] #page .page-title { min-width: 0; }

/* Secondary header actions: solid surface buttons (readable on wallpapers too); the primary one is blue */
:root[data-theme] #page :is(.deal-header-actions, .page-head .head-actions, .task-page-heading, .ai-heading, .mail-work-toolbar) .btn:not(.primary):not(.task-create):not(.mail-write) {
  background: var(--surface);
  border-color: var(--control-line);
  box-shadow: 0 1px 2px var(--shadow-color);
  color: var(--ink);
}
:root[data-theme] #page :is(.deal-header-actions, .page-head .head-actions, .task-page-heading, .ai-heading, .mail-work-toolbar) .btn:not(.primary):not(.task-create):not(.mail-write):hover {
  background: var(--surface-2);
  border-color: var(--blue-line);
  color: var(--ink);
}

/* ---------- Segmented tabs: one style for view switches and section tabs ---------- */
:root[data-theme] #page :is(.segmented, .task-view-tabs, .ai-tabs, .settings-sections) {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 3px;
  width: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  box-shadow: none;
}
:root[data-theme] #page :is(.segmented, .task-view-tabs, .ai-tabs, .settings-sections) > :is(button, a) {
  height: 30px;
  min-height: 30px;
  padding: 0 var(--sp-4);
  border: 0;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
}
:root[data-theme] #page :is(.segmented, .task-view-tabs, .ai-tabs, .settings-sections) > :is(button, a):hover { color: var(--ink); background: transparent; }
:root[data-theme] #page :is(.segmented, .task-view-tabs, .ai-tabs, .settings-sections) > :is(button, a):is(.active, [aria-pressed="true"], [aria-current="page"], [aria-current="true"], [aria-selected="true"]) {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px var(--shadow-strong);
}

/* ---------- Stat tiles (ИИ-агенты) match the home KPI strip ---------- */
:root[data-theme] #page .ai-metrics { gap: var(--sp-3); margin: 0 0 var(--sp-5); }
:root[data-theme] #page .ai-metrics > :is(button, div) {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  align-items: flex-start;
  gap: var(--sp-1);
  height: auto;
  min-height: 0;
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--page-shadow);
  text-align: left;
  color: var(--ink);
}
:root[data-theme] #page .ai-metrics > button:hover { border-color: var(--blue-line); }
:root[data-theme] #page .ai-metrics span { font-size: var(--fs-sm); font-weight: 500; color: var(--secondary); }
:root[data-theme] #page .ai-metrics b {
  font-size: var(--fs-4xl);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Panels and cards: one radius, border and shadow ---------- */
:root[data-theme] #page :is(.card, .filter-panel, .portal-filter-panel, .task-filter-panel) {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--page-shadow);
}
:root[data-theme] #page .table-wrap { overflow: hidden; }

/* Tables: quiet headers and row hover */
:root[data-theme] #page table th {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
}
:root[data-theme] #page table tbody tr:hover > td { background: var(--surface-2); }

/* Empty states */
:root[data-theme] #page :is(.empty, .ai-empty) { color: var(--muted); }
:root[data-theme] #page :is(.empty, .ai-empty) :is(b, strong, h3) { color: var(--secondary); font-weight: 600; }

/* ---------- Modals and side panels: same header style ---------- */
:root[data-theme] #modal-root .modal-head :is(h2, h1) {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.25;
}
:root[data-theme] #modal-root .modal { border-color: var(--line); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root[data-theme] #page:not([data-page="dashboard"]) h1 { font-size: var(--fs-3xl); }
  :root[data-theme] #page :is(.page-subtitle, .page-head .subtitle, .task-heading-note, .ai-heading h1 + p) { font-size: var(--fs-sm); }
  :root[data-theme] #page :is(.segmented, .task-view-tabs, .ai-tabs, .settings-sections) { max-width: 100%; }
}

/* ---------- Vertical rhythm: header → content 20px, block → block 16px ---------- */
/* Tasks and Mail put the header in a flex/grid container that already adds a 16px gap */
:root[data-theme] #page .task-workspace > .task-page-heading { margin-bottom: 4px; }   /* container gap 16px */
:root[data-theme] #page .mail-workspace > .mail-work-heading { margin-bottom: 0; }      /* container gap = --workspace-heading-gap */
:root[data-theme] #page .page-heading.drive-heading { margin-bottom: var(--sp-5); }
:root[data-theme] #page :is(.portal-filter-panel, .deal-board-controls, .settings-sections) { margin-bottom: var(--sp-4); }
