/* Shared working geometry. Print templates keep their independent paper layout. */
@media screen {
 .crm-ui { background-image: linear-gradient(#e8eef2e0,#e8eef2d4),url('/vision-environment.webp'); }
 .crm-ui .main { padding-bottom: 24px; }
 .crm-ui .main > main[data-workspace=registry] { margin-top: 20px; padding: 20px; min-height: 0; background: var(--surface-panel); border: 1px solid var(--border-glass); border-radius: 22px; box-shadow: var(--shadow-panel); }
 .crm-ui .main > main[data-workspace=settings] { max-width: 1320px; min-height: 0; }
 .crm-ui :is(.table-wrap,.co-table-scroll,.ord-table-scroll,.fn-table-wrap,.wh-table-wrap,.ct-table-scroll,.schedule-scroll) { background: var(--surface-data); backdrop-filter: none; }
 .crm-ui :is(.fn-table,.wh-table,.iv-table,.sale-table) { font: 13px/1.5 'Golos Text',sans-serif; }
 .crm-ui :is(.fn-table-wrap,.wh-table-wrap) { min-height: 220px; }
 .crm-ui :is(.fn-table,.wh-table) th { padding: 12px; font-size: 13px; }
 .crm-ui :is(.fn-table,.wh-table) td { padding: 12px; }
 .crm-ui :is(.co-empty,.wh-empty,.fn-empty) { min-height: 120px; }
 .crm-ui .wh-empty { padding: 20px; }
 .crm-ui .wh-empty svg { width: 64px; height: 48px; margin: 4px; }
 .crm-ui .fn-empty { padding: 32px 20px; }

 /* A backdrop is never painted with the material of its inner form. */
 .crm-ui :is(.backdrop,.co-backdrop,.ord-backdrop,.task-backdrop,.co-nested-backdrop,.sale-backdrop,.iv-backdrop,.lead-backdrop) { background: #202d3d29; backdrop-filter: blur(5px); border: 0; border-radius: 0; box-shadow: none; }
 .crm-ui [data-overlay-level] { z-index: var(--overlay-z) !important; }
 .crm-ui [data-overlay-underlay=true] { background: transparent; backdrop-filter: none; }
 .crm-ui :is(.co-nested,.modal,.drawer,.co-drawer,.ord-drawer,.task-drawer,.ct-drawer,.sale-drawer,.iv-drawer,.lead-drawer) { background: var(--surface-overlay); }
 .crm-ui .co-nested { width: min(max(var(--dialog-width,480px),440px),calc(100vw - 40px)); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
 .crm-ui .co-nested > form { min-height: 0; display: flex; flex-direction: column; }
 .crm-ui .co-nested-body { padding: 24px; overflow: auto; min-height: 0; }
 .crm-ui .co-nested > header { flex: 0 0 auto; }
 .crm-ui .co-nested form > footer { flex: 0 0 auto; padding: 16px 24px; border-top: 1px solid var(--separator); background: var(--surface-overlay); }
 .crm-ui :is(.fn-drawer,.wh-drawer).co-nested-backdrop { padding: 20px; align-items: center; justify-content: center; }
 .crm-ui :is(.fn-drawer,.wh-drawer) .co-nested { width: min(max(var(--dialog-width,640px),600px),calc(100vw - 40px)); height: auto; max-height: calc(100dvh - 40px); border-radius: 24px; box-shadow: 0 24px 70px #17283a2b; }
 .crm-ui .modal { width: min(560px,calc(100vw - 40px)); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
 .crm-ui .modal.wide { width: min(880px,calc(100vw - 40px)); }
 .crm-ui .modal > form { min-height: 0; overflow: auto; }
 .crm-ui .modal .form-grid { padding: 24px; }
 .crm-ui .modal .form-footer { position: sticky; bottom: 0; margin: 0; z-index: 1; }
 .crm-ui :is(.field,.ord-field,.co-field,.fn-field,.wh-field,.ct-field,.lead-field,.task-field) { min-width: 0; }
 .crm-ui :is(.form-grid .field,.co-nested .field) { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
 .crm-ui :is(.form-grid .field,.co-nested .field) > span { text-align: left; width: auto; font-size: 13px; }
 .crm-ui .form-section { grid-column: 1 / -1; padding-top: 16px; border-top: 1px solid var(--separator); }
 .crm-ui .form-section:first-child { border-top: 0; padding-top: 0; }
 .crm-ui .form-section > h3 { margin: 0 0 16px; font-size: 18px; }
 .crm-ui .form-section-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px 20px; }
 .crm-ui .form-section-grid :is(.form-section-heading,.field:has(textarea),.check-options,.checkbox-field) { grid-column: 1 / -1; }

 .crm-ui .settings-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
 .crm-ui .settings-card { min-height: 96px; padding: 20px; background: var(--surface-data); border: 1px solid var(--separator); border-radius: 16px; box-shadow: none; }
 .crm-ui .settings-card h3 { font-size: 16px; margin-bottom: 6px; }
 .crm-ui .settings-card p { font-size: 13px; }
 .crm-ui .page-heading { align-items: flex-start; gap: 16px; flex-wrap: wrap; }
 .crm-ui .page-heading .actions { gap: 8px; flex-wrap: wrap; }
 .crm-ui :is(.integration-settings,.personal-profile) { max-width: 1040px; }
 .crm-ui .form-intro { padding: 16px 24px 0; max-width: 75ch; }
 .crm-ui .fn-accounts { gap: 12px; }
 .crm-ui .fn-account { min-width: 200px; max-width: 260px; background: var(--surface-data); }
 .crm-ui :is(.sale-lines-empty,.ord-items-empty,.iv-empty) { min-height: 120px; }
 @media(max-width:1100px) { .crm-ui .settings-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
 @media(max-width:760px) {
  .crm-ui .main > main[data-workspace=registry] { margin-top: 14px; padding: 12px; border-radius: 18px; }
  .crm-ui .settings-grid,.crm-ui .form-section-grid { grid-template-columns: 1fr; }
  .crm-ui :is(.fn-drawer,.wh-drawer).co-nested-backdrop { padding: 0; align-items: stretch; }
  .crm-ui :is(.fn-drawer,.wh-drawer) .co-nested { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .crm-ui .co-nested { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .crm-ui .modal,.crm-ui .modal.wide { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .crm-ui .co-nested-body,.crm-ui .modal .form-grid { padding: 20px 16px; }
  .crm-ui .co-nested form > footer { padding: 14px 16px max(14px,env(safe-area-inset-bottom)); }
 }
 @media(prefers-reduced-transparency:reduce), (forced-colors:active) {
  .crm-ui { background-image: none; }
  .crm-ui :is(.backdrop,.co-backdrop,.ord-backdrop,.task-backdrop,.co-nested-backdrop,.sale-backdrop,.iv-backdrop,.lead-backdrop) { backdrop-filter: none; }
 }
}

.form-grid > .form-section { grid-column: 1 / -1; }
.settings-tools { margin: 0 0 24px; padding: 20px; border: 1px solid #dce4ec; border-radius: 18px; background: var(--surface-data); }
.settings-tools h2 { margin: 0 0 14px; font-size: 16px; }
.schedule-grid .day-title.is-today { background: #edf2ff; color: #3156c9; box-shadow: inset 0 3px #5275f5; }

@media screen {
 .crm-ui .commercial-section { margin-bottom: 24px; padding-top: 20px; border-top: 1px solid var(--separator); }
 .crm-ui .commercial-section:first-child { padding-top: 0; border-top: 0; }
 .crm-ui .commercial-section > h3 { margin: 0 0 18px; font-size: 18px; }
 .crm-ui :is(.iv-field,.sale-field) { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
 .crm-ui :is(.iv-field,.sale-field) > span { width: auto; text-align: left; }
 .crm-ui .sale-drawer { width: min(960px,100vw); }
 .crm-ui .iv-main { width: min(860px,100vw); max-width: 100%; }
 .crm-ui .iv-drawer { width: min(860px,100vw); }
 .crm-ui .iv-drawer.iv-existing { width: min(1200px,100vw); }
 .crm-ui :is(.sale-card-content,.iv-content) { padding: 24px; }
 .crm-ui .iv-contact-card { background: var(--surface-data); border: 1px solid var(--separator); box-shadow: none; }
 .crm-ui :is(.sale-totals,.iv-totals) { max-width: 420px; margin-left: auto; }
 @media(max-width:760px) {
  .crm-ui :is(.sale-card-content,.iv-content) { padding: 20px 16px; }
  .crm-ui :is(.sale-drawer,.iv-drawer,.iv-drawer.iv-existing,.iv-main) { width: 100%; }
  .crm-ui .iv-show-feed .iv-main { width: 0; }
 }
}

.crm-ui .settings-tools .actions { flex-wrap: wrap; gap: 10px; }

/* Nonmodal menus sit above their current modal; nested modals inert/hide older menus. */
.crm-ui :is(.sale-popover,.iv-popover,.fn-popover,.wh-popover,.ord-popover,.chat-popover,.task-people-popup,.co-menu,.ord-menu,.ct-menu) { z-index: calc(var(--overlay-top-z,400) + 5); }
.crm-ui :is(.sale-popover,.iv-popover,.fn-popover,.wh-popover,.ord-popover,.chat-popover,.task-people-popup,.co-menu,.ord-menu,.ct-menu)[inert] { visibility: hidden; }

.crm-ui .sale-card-head [data-sa=share] { width: auto; min-width: 110px; padding: 8px 14px; border-radius: 12px; white-space: nowrap; flex-shrink: 0; }

.crm-ui .company-document-vars { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.crm-ui .co-nested form > footer { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; }

@media screen {
 .crm-ui .profile-section { grid-template-columns: 180px minmax(0,600px); gap: 24px; }
 .crm-ui .profile-section form { max-width: 600px; }
 .crm-ui .profile-section .field { display: flex; flex-direction: column; gap: 8px; align-items: stretch; margin-bottom: 16px; }
 .crm-ui .profile-section .field > span { width: auto; text-align: left; font-size: 13px; }
 .crm-ui #personal-form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 20px; }
 .crm-ui #personal-form :is(.form-error,[type=submit]) { grid-column: 1 / -1; justify-self: start; }
 @media(max-width:1100px) { .crm-ui .profile-section { grid-template-columns: 1fr; gap: 18px; } }
 @media(max-width:760px) { .crm-ui #personal-form { grid-template-columns: 1fr; } }
}

@media screen {
  .crm-ui #sale-create-form .commercial-section:first-child { display: grid; grid-template-columns: minmax(0, 2fr) minmax(180px, 1fr); gap: 12px 20px; }
  .crm-ui #sale-create-form .commercial-section:first-child > h3,
  .crm-ui #sale-lead-choice { grid-column: 1 / -1; }
  .crm-ui #sale-lead-choice:empty { display: none; }
  .crm-ui #sale-create-form .sale-client-row { max-width: none; min-width: 0; }
  .crm-ui #sale-create-form .sale-field input:not([type=checkbox]),
  .crm-ui #sale-create-form .sale-field select { min-height: 44px; border: 1px solid #8291a4; border-radius: 10px; padding: 9px 12px; font: inherit; }
  .crm-ui #sale-create-form .sale-client-search input { padding-right: 88px; }
  .crm-ui #sale-create-form .sale-client-search button { width: 40px; height: 44px; }
  .crm-ui #sale-create-form .sale-client-search [data-sa=new-client] { right: 40px; }
}
@media screen and (max-width: 760px) {
  .crm-ui #sale-create-form .commercial-section:first-child { grid-template-columns: minmax(0, 1fr); }
}
