/*
 * SKY SIC-PHARMA CRM web interface
 * Authoritative visual layer loaded after legacy module styles.
 */
:root {
  --crm-bg: #f1f4f7;
  --crm-surface: #ffffff;
  --crm-surface-muted: #f7f9fb;
  --crm-surface-strong: #eaf0f5;
  --crm-border: #d5dde6;
  --crm-border-strong: #b8c5d2;
  --crm-text: #152335;
  --crm-muted: #627187;
  --crm-text-subtle: var(--crm-muted);
  --crm-heading: #102f50;
  --crm-primary: #155b91;
  --crm-primary-hover: #104b78;
  --crm-accent: #0b8179;
  --crm-success: #137653;
  --crm-warning: #a65f08;
  --crm-danger: #b83a3a;
  --crm-info-soft: #e5f1fa;
  --crm-success-soft: #e5f4ee;
  --crm-warning-soft: #fbf0de;
  --crm-danger-soft: #f9e8e8;
  --crm-radius: 5px;
  --crm-sidebar: 244px;
  --crm-topbar: 64px;
  --crm-focus: 0 0 0 3px rgba(21, 91, 145, .16);
  --crm-panel: var(--crm-surface);
  --crm-primary-soft: var(--crm-info-soft);
  --bg: var(--crm-bg);
  --surface: var(--crm-surface);
  --surface-2: var(--crm-surface-muted);
  --soft: var(--crm-surface-strong);
  --line: var(--crm-border);
  --text: var(--crm-text);
  --muted: var(--crm-muted);
  --primary: var(--crm-heading);
  --primary-2: var(--crm-primary);
  --accent: var(--crm-accent);
  --teal: var(--crm-accent);
  --green: var(--crm-success);
  --amber: var(--crm-warning);
  --red: var(--crm-danger);
  --radius: var(--crm-radius);
  --radius-sm: var(--crm-radius);
  --shadow: none;
  --shadow-hover: none;
}

.performance-list {
  display: grid;
  gap: 10px;
}

.performance-item {
  border: 1px solid var(--crm-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--crm-panel);
}

.performance-item strong,
.performance-item span {
  display: block;
}

.performance-item span,
.performance-item p {
  color: var(--crm-muted);
}

:root[data-theme="dark"] {
  --crm-bg: #0d141c;
  --crm-surface: #131d27;
  --crm-surface-muted: #18232e;
  --crm-surface-strong: #202d39;
  --crm-border: #2d3c4a;
  --crm-border-strong: #46596a;
  --crm-text: #e7edf3;
  --crm-muted: #9cabb9;
  --crm-heading: #dcecff;
  --crm-primary: #64a9df;
  --crm-primary-hover: #82bce8;
  --crm-accent: #50c5b9;
  --crm-success: #6bd3a7;
  --crm-warning: #efbd69;
  --crm-danger: #ee8d8d;
  --crm-info-soft: #17334a;
  --crm-success-soft: #17372e;
  --crm-warning-soft: #3a2d1b;
  --crm-danger-soft: #3b2225;
  --crm-focus: 0 0 0 3px rgba(100, 169, 223, .22);
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .btn,
:root[data-theme="dark"] .icon-btn,
:root[data-theme="dark"] .panel-head,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .modal-foot,
:root[data-theme="dark"] .search,
:root[data-theme="dark"] .form-actions {
  background: var(--crm-surface) !important;
  border-color: var(--crm-border) !important;
  color: var(--crm-text) !important;
}

:root[data-theme="dark"] option {
  background: var(--crm-surface);
  color: var(--crm-text);
}

.topbar-language select,
.drawer-language select,
.settings-language select {
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
  color: var(--crm-text);
}

.geo-field-with-add {
  grid-template-columns: minmax(0, 1fr) auto;
}

.geo-field-with-add label {
  grid-column: 1 / -1;
}

.geo-quick-add {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.geo-quick-backdrop {
  z-index: 1200;
}

html {
  background: var(--crm-bg);
}

body.app-loading::before {
  position: fixed;
  z-index: 2000;
  top: 0;
  left: 0;
  width: 32%;
  height: 3px;
  border-radius: 0 999px 999px 0;
  background: var(--crm-accent);
  content: "";
  animation: app-loading-slide .8s ease-in-out infinite alternate;
}

@keyframes app-loading-slide {
  from { transform: translateX(-40%); }
  to { transform: translateX(250%); }
}

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

body,
button,
input,
select,
textarea {
  color: var(--crm-text);
}

body {
  background: var(--crm-bg) !important;
  font-size: 14px;
  line-height: 1.45;
}

body,
.auth-screen,
.card,
.panel,
.btn,
.btn.primary,
.nav a,
.nav a.active,
.map-stage,
.progress-track span {
  background-image: none !important;
}

button,
a,
input,
select,
textarea {
  transition: border-color .14s ease, background-color .14s ease, color .14s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 0;
  box-shadow: var(--crm-focus) !important;
}

.shell {
  grid-template-columns: var(--crm-sidebar) minmax(0, 1fr) !important;
  background: var(--crm-bg);
}

.sidebar {
  z-index: 20;
  gap: 0 !important;
  padding: 0 !important;
  background: var(--crm-surface) !important;
  border-right: 1px solid var(--crm-border) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

.sidebar-brand {
  min-height: var(--crm-topbar);
  gap: 10px;
  margin: 0 !important;
  padding: 10px 16px !important;
  border-bottom: 1px solid var(--crm-border) !important;
}

.sidebar-brand .mark {
  width: 38px;
  height: 38px;
}

.sidebar-brand h1 {
  color: var(--crm-heading);
  font-size: 14px;
  letter-spacing: .02em;
}

.sidebar-brand p {
  margin-top: 2px;
  font-size: 11px;
}

.nav-section-label {
  padding: 16px 16px 6px;
  color: var(--crm-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.sidebar > .nav {
  flex: 1;
  align-content: start;
  gap: 2px !important;
  overflow-y: auto;
  padding: 4px 9px 18px;
}

.nav a {
  position: relative;
  min-height: 38px !important;
  gap: 9px;
  padding: 8px 10px !important;
  border: 1px solid transparent !important;
  border-radius: var(--crm-radius) !important;
  color: var(--crm-text) !important;
  background: transparent !important;
  font-size: 12.5px !important;
  font-weight: 650 !important;
  box-shadow: none !important;
  transform: none !important;
}

.nav a::before {
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--crm-border-strong);
  content: "";
}

.nav a:hover {
  border-color: var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
}

.nav a.active {
  border-color: #b7d1e4 !important;
  background: var(--crm-info-soft) !important;
  color: var(--crm-primary) !important;
}

.nav a.active::before {
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: var(--crm-primary);
}

.sidebar-account {
  display: grid;
  gap: 8px;
  padding: 12px 9px;
  border-top: 1px solid var(--crm-border);
  background: var(--crm-surface-muted);
}

.sidebar-account .topbar-user {
  width: 100%;
  padding: 5px 7px;
}

.sidebar-account .topbar-user > span:last-child {
  display: grid;
  min-width: 0;
}

.sidebar-account strong,
.sidebar-account small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-account small {
  color: var(--crm-muted);
  font-size: 10px;
}

.sidebar-account .nav {
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.sidebar-account .nav a {
  justify-content: center;
  min-height: 32px !important;
  padding: 5px !important;
  font-size: 11px !important;
}

.sidebar-account .nav a::before {
  display: none;
}

.main {
  background: var(--crm-bg);
}

.topbar {
  z-index: 15 !important;
  height: var(--crm-topbar) !important;
  min-height: var(--crm-topbar) !important;
  gap: 16px;
  padding: 0 20px !important;
  background: var(--crm-surface) !important;
  border-bottom: 1px solid var(--crm-border) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

.topbar-context {
  display: grid;
  min-width: 160px;
}

.topbar-context span {
  color: var(--crm-muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.topbar-context strong {
  color: var(--crm-heading);
  font-size: 14px;
}

.topbar-search {
  width: min(440px, 35vw);
  margin-right: auto;
}

.search {
  width: 100% !important;
  height: 36px !important;
  padding: 0 12px !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface-muted) !important;
  color: var(--crm-text) !important;
}

.search:focus {
  border-color: var(--crm-primary) !important;
  background: var(--crm-surface) !important;
}

.topbar > .row {
  gap: 6px;
  flex-wrap: nowrap;
}

.topbar-user {
  max-width: 210px;
  color: var(--crm-heading);
  font-size: 12px;
}

.topbar-avatar,
.user-avatar {
  border: 1px solid var(--crm-border);
  background: var(--crm-success-soft);
  color: var(--crm-accent);
}

.topbar-timer,
.notification-trigger {
  min-height: 34px !important;
  padding: 5px 9px !important;
  border: 1px solid var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
  color: var(--crm-muted) !important;
  font-size: 11px !important;
}

.notification-trigger strong {
  min-width: 19px;
  height: 19px;
  background: var(--crm-primary);
  font-size: 10px;
}

.content {
  width: min(100%, 1780px);
  margin-inline: auto;
  padding: 22px 24px 40px !important;
}

.page {
  gap: 14px !important;
}

body[data-route="tableau-de-bord"] .page,
body[data-route="dashboard"] .page,
body[data-route="audit"] .page,
body[data-route="ventes"] .page,
body[data-route="rh"] .page {
  align-content: start;
}

body[data-route="messages"] .content,
body[data-route="ia-terrain"] .content,
body[data-route="geolocalisation"] .content,
body[data-route="geolocation"] .content {
  width: 100%;
  max-width: none;
}

body[data-role="tv"] .sidebar-account,
body[data-role="lab-client"] .sidebar-account {
  background: var(--crm-info-soft);
}

.page-head {
  min-height: 58px;
  align-items: center !important;
  padding: 0 0 8px !important;
  border-bottom: 1px solid var(--crm-border);
}

.eyebrow {
  color: var(--crm-accent) !important;
  font-size: 10px !important;
  letter-spacing: .1em !important;
}

h2 {
  margin-top: 2px !important;
  color: var(--crm-heading) !important;
  font-size: clamp(22px, 2.1vw, 30px) !important;
  letter-spacing: -.02em !important;
}

h3,
h4,
h5 {
  color: var(--crm-heading);
}

.subtle {
  color: var(--crm-muted) !important;
}

.grid-4,
.grid-3,
.grid-2,
.dashboard-split,
.report-cards,
.objectives-grid,
.settings-grid {
  gap: 10px !important;
}

.card,
.panel,
.panel-lite,
.mini-card,
.report-summary-card,
.report-section-card,
.daily-report-section,
.objective-card,
.history-box,
.crm-step,
.crm-item,
.quick-target-form,
.camera-box,
.sales-import-strip,
.diagnostic-grid div,
.map-tooltip,
.comment-item {
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  box-shadow: none !important;
  transform: none !important;
}

.card:hover,
.panel:hover {
  border-color: var(--crm-border-strong) !important;
  box-shadow: none !important;
  transform: none !important;
}

.card {
  min-height: 96px !important;
  padding: 14px !important;
}

.card small {
  color: var(--crm-muted) !important;
  font-size: 10px;
  letter-spacing: .08em;
}

.card strong {
  margin-top: 7px !important;
  color: var(--crm-heading) !important;
  font-size: clamp(22px, 2.3vw, 30px) !important;
  letter-spacing: -.025em !important;
}

.panel {
  overflow: visible;
}

.panel-head {
  min-height: 48px !important;
  gap: 12px;
  padding: 10px 13px !important;
  border-bottom: 1px solid var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
}

.panel-head h3 {
  color: var(--crm-heading) !important;
  font-size: 14px;
}

.panel-head p {
  margin: 3px 0 0;
}

.panel-body {
  padding: 13px !important;
}

.btn,
.icon-btn {
  min-height: 34px !important;
  padding: 6px 10px !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  color: var(--crm-heading) !important;
  font-size: 11.5px;
  font-weight: 750 !important;
  box-shadow: none !important;
  transform: none !important;
margin:5px
}

.btn:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
  border-color: var(--crm-border-strong) !important;
  background: var(--crm-surface-muted) !important;
  box-shadow: none !important;
}

.btn.primary {
  border-color: var(--crm-primary) !important;
  background: var(--crm-primary) !important;
  color: #fff !important;
}

.btn.primary:hover:not(:disabled) {
  border-color: var(--crm-primary-hover) !important;
  background: var(--crm-primary-hover) !important;
}

.btn.danger {
  border-color: color-mix(in srgb, var(--crm-danger) 35%, var(--crm-border)) !important;
  background: var(--crm-danger-soft) !important;
  color: var(--crm-danger) !important;
}

.chip,
.badge,
.status-ok,
.status-warn,
.status-danger {
  min-height: 21px;
  padding: 2px 7px;
  border: 1px solid var(--crm-border);
  border-radius: 999px !important;
  background: var(--crm-surface-strong);
  color: var(--crm-heading);
  font-size: 10px;
  font-weight: 800;
}

.chip.ok,
.badge.success,
.status-ok {
  border-color: color-mix(in srgb, var(--crm-success) 30%, var(--crm-border));
  background: var(--crm-success-soft) !important;
  color: var(--crm-success) !important;
}

.chip.warn,
.badge.warning,
.status-warn {
  border-color: color-mix(in srgb, var(--crm-warning) 30%, var(--crm-border));
  background: var(--crm-warning-soft) !important;
  color: var(--crm-warning) !important;
}

.chip.bad,
.badge.danger,
.status-danger {
  border-color: color-mix(in srgb, var(--crm-danger) 30%, var(--crm-border));
  background: var(--crm-danger-soft) !important;
  color: var(--crm-danger) !important;
}

.form {
  gap: 10px !important;
}

.field {
  gap: 5px !important;
}

.field label {
  color: var(--crm-muted) !important;
  font-size: 10px !important;
  letter-spacing: .07em !important;
}

.field input,
.field select,
.field textarea,
.inline-form select,
.inline-form input,
.line-row input,
.line-row select,
.crm-item textarea,
.compact-number {
  min-height: 36px !important;
  padding: 7px 9px !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  color: var(--crm-text) !important;
  box-shadow: none !important;
}

.field textarea,
.crm-item textarea {
  min-height: 82px !important;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-form select:focus,
.inline-form input:focus {
  border-color: var(--crm-primary) !important;
  box-shadow: var(--crm-focus) !important;
}

.form-actions {
  padding: 10px 13px !important;
  border-top: 1px solid var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
}

.table-toolbar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 6px 9px;
  border: 1px solid var(--crm-border);
  border-bottom: 0;
  background: var(--crm-surface-muted);
}

.panel > .table-toolbar,
.panel-body > .table-toolbar {
  border-right: 0;
  border-left: 0;
}

.table-toolbar-label {
  color: var(--crm-muted);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.table-column-menu {
  position: relative;
}

.table-column-trigger::before {
  content: "☷";
}

.table-column-popover {
  position: absolute;
  z-index: 100;
  top: calc(100% + 5px);
  right: 0;
  display: none;
  width: min(290px, calc(100vw - 30px));
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--crm-border-strong);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
  box-shadow: 0 12px 28px rgba(8, 23, 38, .16);
}

.table-column-menu.open .table-column-popover {
  display: block;
}

.table-column-popover-head {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  border-bottom: 1px solid var(--crm-border);
  background: var(--crm-surface-muted);
  font-size: 11px;
}

.table-column-choices {
  display: grid;
  padding: 5px;
}

.table-column-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 7px;
  border-radius: var(--crm-radius);
  color: var(--crm-text);
  font-size: 11px;
  cursor: pointer;
}

.table-column-choice:hover {
  background: var(--crm-surface-muted);
}

.table-column-choice input {
  accent-color: var(--crm-primary);
}

.table-wrap {
  max-width: 100%;
  border: 1px solid var(--crm-border);
  overflow: auto;
  background: var(--crm-surface);
  scrollbar-color: var(--crm-border-strong) transparent;
}

.panel > .table-wrap,
.panel-body > .table-wrap {
  border-right: 0;
  border-left: 0;
}

.crm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11.5px;
}



.crm-table th,
.crm-table td {
  height: 38px;
  padding: 7px 10px !important;
  border-bottom: 1px solid var(--crm-border) !important;
  background: var(--crm-surface);
  color: var(--crm-text);
  text-align: left;
  vertical-align: middle;
  /* white-space: nowrap; */
}

.crm-table thead th {
  position: sticky;
  z-index: 2;
  top: 0;
  background: var(--crm-surface-muted) !important;
  color: var(--crm-muted) !important;
  font-size: 9.5px !important;
  font-weight: 850;
  letter-spacing: .07em !important;
  text-transform: uppercase;
}

.crm-table tbody tr:last-child td {
  border-bottom: 0 !important;
}

.crm-table tbody tr:hover td {
  background: var(--crm-surface-muted) !important;
}

.crm-table th[role="button"] {
  padding-right: 25px !important;
  cursor: pointer;
}

.crm-table th[role="button"]::after {
  position: absolute;
  right: 8px;
  color: var(--crm-border-strong);
  content: "↕";
  font-size: 12px;
}

.crm-table th[aria-sort="descending"]::after {
  color: var(--crm-primary);
  content: "↓";
}

.crm-table th[aria-sort="ascending"]::after {
  color: var(--crm-primary);
  content: "↑";
}

.crm-table .table-actions-column,
.crm-table td:last-child:has(.btn) {
  text-align: right;
}

.crm-table .btn {
  min-height: 28px !important;
  padding: 4px 7px !important;
  font-size: 10px;

}

.row-action-menu {
  position: relative;
  display: inline-block;
  margin-left: 4px;
  vertical-align: middle;
}

.row-action-menu summary {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  list-style: none;
  cursor: pointer;
}

.row-action-menu summary::-webkit-details-marker {
  display: none;
}

.row-action-popover {
  position: fixed;
  z-index: 1250;
  top: var(--action-menu-top, 80px);
  right: var(--action-menu-right, 10px);
  display: grid;
  width: max-content;
  min-width: 170px;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--crm-border);
  border-radius: 12px;
  background: var(--crm-surface);
  box-shadow: 0 14px 35px rgba(11, 31, 51, .18);
}

.row-action-popover .btn {
  width: 100%;
  margin: 0 !important;
  justify-content: flex-start;
  text-align: left;
}

.table-column-hidden {
  display: none !important;
}

.empty {
  padding: 28px !important;
  color: var(--crm-muted) !important;
}

.error {
  border: 1px solid color-mix(in srgb, var(--crm-danger) 35%, var(--crm-border)) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-danger-soft) !important;
  color: var(--crm-danger) !important;
}

.modal-backdrop {
  z-index: 1200 !important;
  padding: 20px;
  background: rgba(5, 13, 21, .72) !important;
  backdrop-filter: none !important;
}

.modal {
  width: min(860px, 100%);
  max-height: calc(100vh - 40px);
  border: 1px solid var(--crm-border-strong) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  color: var(--crm-text);
  box-shadow: 0 20px 50px rgba(3, 10, 18, .28) !important;
}

.modal-head,
.modal-foot {
  padding: 10px 13px !important;
  border-color: var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
}

.modal-head h3 {
  color: var(--crm-heading) !important;
  font-size: 15px;
}

.modal-body {
  padding: 13px !important;
}

.toast-stack {
  z-index: 1500 !important;
}

.toast {
  border: 1px solid var(--crm-border-strong) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  color: var(--crm-text);
  box-shadow: 0 12px 28px rgba(5, 13, 21, .16) !important;
}

.auth-screen {
  min-height: 100vh;
  grid-template-columns: minmax(0, 1fr);
  background: var(--crm-bg) !important;
}

.login-card {
  width: min(100%, 420px) !important;
  padding: 28px !important;
  border: 1px solid var(--crm-border-strong) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
  box-shadow: none !important;
  animation: none !important;
  backdrop-filter: none !important;
}

.login-card .brand {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--crm-border);
}

.login-card .tagline {
  margin: 0 0 18px;
  color: var(--crm-muted) !important;
  font-size: 12px;
  text-align: left;
}

.mobile-drawer,
.drawer-user {
  background: var(--crm-surface) !important;
  border-color: var(--crm-border) !important;
}

.map-stage,
.map-empty,
.leaflet-map {
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface-muted) !important;
}

.leaflet-container,
.leaflet-pane,
.leaflet-top,
.leaflet-bottom,
.leaflet-control {
  z-index: 1 !important;
}

.ai-workspace {
  min-height: calc(100vh - 145px) !important;
  gap: 0 !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius);
  background: var(--crm-surface) !important;
  overflow: hidden;
}

.ai-workspace.chat-only {
  grid-template-columns: minmax(210px, 270px) minmax(0, 1fr) !important;
  max-width: 1280px;
  margin: 0 auto;
}

.ai-sidebar {
  padding: 9px !important;
  border-right: 1px solid var(--crm-border) !important;
  background: var(--crm-surface-muted) !important;
}

.ai-main {
  min-height: calc(100vh - 145px) !important;
  border: 0 !important;
}

.ai-main .chat-bubble {
  border: 0 !important;
  background: transparent !important;
}

.ai-main .chat-bubble.user {
  border: 1px solid var(--crm-border) !important;
  background: var(--crm-info-soft) !important;
}

.ai-main .message-form {
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface) !important;
}

.ai-product-panel {
  border-top: 1px solid var(--crm-border) !important;
}

.learning-shell {
  display: grid;
  grid-template-columns: minmax(235px, 300px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.learning-catalog {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 92px);
  overflow: hidden;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.learning-catalog-head {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--crm-border);
  background: var(--crm-surface-muted);
}

.learning-catalog-head h3,
.learning-hero h2,
.learning-section h3,
.learning-chapter h4 {
  margin: 0;
}

.learning-product-list {
  display: grid;
  gap: 0;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

.learning-product-card {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  color: var(--crm-text);
  text-decoration: none;
  border-bottom: 1px solid var(--crm-border);
  border-left: 3px solid transparent;
}

.learning-product-card:hover,
.learning-product-card.active {
  background: var(--crm-info-soft);
  border-left-color: var(--crm-accent);
}

.learning-product-card p,
.learning-product-card small {
  margin: 0;
  color: var(--crm-muted);
}

.learning-product-status,
.eyebrow {
  color: var(--crm-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.learning-main,
.learning-section,
.learning-chapters,
.learning-assets {
  display: grid;
  gap: 12px;
}

.learning-hero,
.learning-section {
  padding: 18px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.learning-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 24px;
  border-top: 3px solid var(--crm-accent);
}

.learning-hero p {
  max-width: 760px;
  color: var(--crm-muted);
}

.learning-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.learning-tags span,
.learning-file-type {
  padding: 4px 7px;
  border: 1px solid var(--crm-border);
  border-radius: 3px;
  background: var(--crm-surface-muted);
  font-size: 12px;
}

.learning-progress {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  align-content: center;
  padding-left: 18px;
  border-left: 1px solid var(--crm-border);
}

.learning-progress strong {
  color: var(--crm-accent);
  font-size: 24px;
}

.learning-progress span {
  align-self: center;
  color: var(--crm-muted);
  font-size: 12px;
}

.learning-section-head,
.learning-preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.learning-chapters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.learning-chapter {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--crm-border);
  background: var(--crm-surface-muted);
}

.learning-chapter > span {
  color: var(--crm-accent);
  font-weight: 800;
}

.learning-chapter p,
.learning-preview p {
  margin-bottom: 0;
  color: var(--crm-muted);
  white-space: pre-line;
}

.learning-assets {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.learning-preview {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--crm-border);
  background: var(--crm-surface-muted);
}

.learning-preview-frame {
  min-height: 110px;
}

.learning-preview.image img {
  display: block;
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  background: var(--crm-surface);
}

.learning-preview figcaption {
  padding-top: 8px;
  font-weight: 700;
}

.learning-preview.pdf {
  grid-column: 1 / -1;
}

.learning-preview.pdf iframe {
  width: 100%;
  height: 520px;
  margin-top: 10px;
  border: 1px solid var(--crm-border);
  background: var(--crm-surface);
}

.learning-preview.document {
  display: grid;
  gap: 8px;
  align-content: start;
}

.message-list,
.chat-pane {
  scrollbar-color: var(--crm-border-strong) transparent;
}

.progress-track {
  border-radius: 2px !important;
  background: var(--crm-surface-strong) !important;
}

.progress-track span {
  border-radius: 2px !important;
  background: var(--crm-accent) !important;
}

.theme-choice {
  gap: 8px !important;
}

.theme-card {
  min-height: 115px !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  background: var(--crm-surface-muted) !important;
  color: var(--crm-text) !important;
}

.theme-card:hover {
  border-color: var(--crm-primary) !important;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 216px minmax(0, 1fr) !important;
  }

  .topbar-context {
    display: none;
  }

  .topbar-search {
    width: min(360px, 32vw);
  }

  .content {
    padding: 18px !important;
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 900px) {
  .shell {
    display: block !important;
  }

  .sidebar {
    display: none !important;
  }

  .content {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .page {
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .topbar-brand {
    display: flex !important;
  }

  .topbar-search {
    width: min(360px, 45vw);
  }

  .topbar .topbar-user {
    display: none;
  }

  .grid-2,
  .dashboard-split {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 700px) {
  :root {
    --crm-topbar: 56px;
  }

  .topbar {
    padding: 7px 10px !important;
  }

  .topbar-search,
  .topbar > .row {
    display: none !important;
  }

  .content {
    padding: 10px !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .page {
    gap: 10px !important;
    width: auto !important;
    max-width: 100% !important;
    padding: 0 !important;
    box-sizing: border-box;
  }

  .page-tabs {
    max-width: 100%;
    overflow-x: auto;
  }

  .page-head {
    min-height: 0;
    align-items: stretch !important;
    gap: 9px !important;
    padding-bottom: 10px !important;
  }

  .page-head .actions,
  .panel-head,
  .modal-foot {
    align-items: stretch !important;
  }

  .page-head .actions .btn,
  .panel-head .btn,
  .modal-foot .btn {
    width: 100%;
  }

  h2 {
    font-size: 21px !important;
  }

  .grid-4,
  .grid-3,
  .grid-2,
  .form.two,
  .form.four,
  .report-cards,
  .objectives-grid,
  .settings-grid {
    grid-template-columns: 1fr !important;
  }

  .card {
    min-height: 82px !important;
    padding: 11px !important;
  }

  .card strong {
    font-size: 23px !important;
  }

  .panel-head,
  .panel-body {
    padding: 10px !important;
  }

  .table-toolbar {
    position: sticky;
    z-index: 5;
    left: 0;
  }

  .table-wrap {
    max-width: calc(100vw - 20px);
  }

  table {
    min-width: 680px;
  }

  td:last-child {
    white-space: normal;
    min-width: 150px;
  }

  td:last-child .btn,
  td:last-child a.btn {
    margin: 2px 0;
    width: 100%;
  }

  select[multiple] {
    min-height: 150px;
  }

  .directory-pagination,
  .directory-pagination .actions {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .crm-table th,
  .crm-table td {
    height: 36px;
    padding: 6px 9px !important;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal {
    width: 100%;
    max-height: 100vh;
    min-height: 100vh;
    border: 0 !important;
    border-radius: 0 !important;
  }

  .auth-screen {
    padding: 12px !important;
  }

  .login-card {
    padding: 20px !important;
  }

  .ai-workspace {
    min-height: calc(100vh - 85px) !important;
    border: 0 !important;
  }

  .learning-shell,
  .learning-hero,
  .learning-chapters,
  .learning-assets {
    grid-template-columns: 1fr;
  }

  .learning-catalog {
    position: static;
    max-height: none;
  }

  .learning-product-list {
    max-height: 280px;
  }

  .learning-progress {
    padding: 12px 0 0;
    border-top: 1px solid var(--crm-border);
    border-left: 0;
  }

  .learning-preview.pdf iframe {
    height: 420px;
  }

  .ai-main {
    min-height: calc(100vh - 95px) !important;
  }

  .leaflet-map {
    min-height: 330px !important;
  }
}

/* Final interaction and responsive stability layer. */
.topbar,
.directory-toolbar,
.directory-pagination,
.directory-pagination .actions,
.pagination-pages,
.table-toolbar,
.page-head,
.panel-head {
  min-width: 0;
}

.topbar-search,
.directory-search,
.topbar-search .search,
.directory-search .search,
.collection-search,
#training-product-search {
  min-width: 0;
  max-width: 100%;
}

.directory-query,
.collection-search,
#training-product-search {
  min-height: 40px;
  touch-action: manipulation;
}

.directory-pagination {
  width: 100%;
  box-sizing: border-box;
}

.directory-pagination .actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 6px;
  flex-wrap: wrap;
}

.directory-pagination .btn,
.pagination-pages .btn {
  flex: 0 0 auto;
  text-decoration: none;
  touch-action: manipulation;
}

.pagination-pages {
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.row-action-menu {
  isolation: isolate;
}

.row-action-menu > summary {
  min-height: 34px;
  user-select: none;
  touch-action: manipulation;
}

.row-action-menu:not([open]) > .row-action-popover {
  display: none !important;
}

.row-action-menu[open] > .row-action-popover {
  display: grid;
}

.row-action-popover {
  max-width: min(280px, calc(100vw - 20px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
}

.table-wrap,
.crm-table,
.crm-table th,
.crm-table td {
  min-width: 0;
}

@media (max-width: 700px) {
  .topbar {
    height: auto !important;
    min-height: var(--crm-topbar);
    flex-wrap: wrap;
  }

  .topbar-search {
    display: block !important;
    order: 3;
    width: 100% !important;
    margin: 0;
  }

  .topbar-search .search {
    height: 40px !important;
  }

  .directory-pagination,
  .directory-pagination .actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .directory-pagination .actions > .btn,
  .directory-pagination .actions > a.btn,
  .pagination-pages {
    width: 100%;
  }

  .pagination-pages {
    display: flex;
    justify-content: flex-start;
    flex-wrap: nowrap;
    padding-bottom: 3px;
  }

  .pagination-pages .btn {
    min-width: 44px;
    min-height: 44px;
  }

  .row-action-menu {
    position: static;
  }

  .row-action-popover {
    max-width: none;
    max-height: min(60vh, 420px);
  }
}

/* Design direction 2026: airy medical workspace, inspired by the supplied models. */
:root {
  --crm-bg: #f5f7fb;
  --crm-surface-muted: #f8fafc;
  --crm-border: #e5eaf0;
  --crm-border-strong: #cdd7e2;
  --crm-radius: 14px;
  --crm-sidebar: 268px;
  --crm-topbar: 72px;
  --shadow: 0 10px 30px rgba(21, 47, 76, .07);
}

.shell {
  transition: grid-template-columns .2s ease;
}

.sidebar {
  box-shadow: 8px 0 30px rgba(21, 47, 76, .04) !important;
  transition: width .2s ease;
}

.sidebar-brand {
  position: relative;
  min-height: var(--crm-topbar);
  padding: 12px 14px !important;
}

.sidebar-collapse-toggle {
  width: 28px;
  min-height: 28px !important;
  margin-left: auto !important;
  padding: 0 !important;
  border-radius: 9px !important;
}

.nav-symbol {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  border: 1px solid var(--crm-border);
  border-radius: 9px;
  background: var(--crm-surface-muted);
  color: var(--crm-primary);
  font-size: 10px;
  font-weight: 850;
}

.nav-symbol svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav a {
  min-height: 44px !important;
  padding: 7px 9px !important;
  border-radius: 11px !important;
}

.nav a::before,
.nav-group summary::before {
  display: none;
}

.nav a.active .nav-symbol {
  border-color: var(--crm-primary);
  background: var(--crm-primary);
  color: #fff;
}

.nav-group {
  padding-block: 2px;
}

.nav-group summary {
  min-height: 42px;
  padding: 7px 9px;
  border-radius: 11px;
  font-size: 11px;
  text-transform: none;
}

.nav-group > a {
  margin-left: 18px;
}

.content {
  padding: 28px 30px 48px !important;
}

.page {
  gap: 18px !important;
}

.page-head {
  min-height: 68px;
  border-bottom: 0;
}

.page-head h2 {
  font-size: clamp(25px, 2.1vw, 34px) !important;
}

.card,
.panel {
  border-radius: 16px !important;
  box-shadow: var(--shadow) !important;
}

.card {
  min-height: 126px !important;
  padding: 20px !important;
}

.card small {
  font-size: 11px;
  letter-spacing: .04em;
}

.card strong {
  margin-top: 12px !important;
  font-size: clamp(27px, 3vw, 38px) !important;
}

.panel {
  overflow: hidden;
}

.panel-head {
  min-height: 62px !important;
  padding: 15px 18px !important;
  background: var(--crm-surface) !important;
}

.panel-body {
  padding: 18px !important;
}

.btn,
.icon-btn,
.search,
.field input,
.field select,
.field textarea {
  border-radius: 11px !important;
}

.btn {
  min-height: 40px !important;
  padding: 8px 13px !important;
  margin: 0;
}

.actions,
.row {
  gap: 8px;
}

.modal {
  border-radius: 22px !important;
}

.modal-head,
.modal-foot {
  padding: 14px 18px !important;
  background: var(--crm-surface) !important;
}

.modal-head h3 {
  font-size: 17px !important;
}

.modal-head .modal-close {
  width: 36px;
  min-height: 36px !important;
  border-radius: 50% !important;
  font-size: 20px;
}

.modal-body {
  padding: 18px !important;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 110px;
  text-align: center;
}

.empty::before {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 8px;
  border: 1px solid var(--crm-border);
  border-radius: 50%;
  background: var(--crm-surface-muted);
  color: var(--crm-primary);
  content: "—";
  font-size: 18px;
  font-weight: 800;
}

.dashboard-visual-panel {
  min-height: 360px;
}

.dashboard-chart {
  min-height: 270px;
}

.dashboard-chart svg {
  display: block;
  width: 100%;
  min-height: 230px;
  overflow: visible;
}

.chart-grid-line {
  stroke: var(--crm-border);
  stroke-width: 1;
  stroke-dasharray: 4 7;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.planned {
  stroke: var(--crm-border-strong);
  stroke-dasharray: 7 7;
}

.chart-line.realized {
  stroke: var(--crm-accent);
}

.chart-dot {
  fill: var(--crm-surface);
  stroke: var(--crm-accent);
  stroke-width: 3;
}

.chart-legend,
.chart-axis {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--crm-muted);
  font-size: 11px;
  font-weight: 750;
}

.chart-legend {
  justify-content: flex-end;
}

.chart-legend span::before {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--crm-border-strong);
  content: "";
}

.chart-legend .realized::before {
  background: var(--crm-accent);
}

.dashboard-donut-layout {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  align-items: center;
  gap: 22px;
  min-height: 290px;
  padding: 22px;
}

.dashboard-quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.dashboard-quick-actions a {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--crm-border);
  border-radius: 14px;
  background: var(--crm-surface);
  color: var(--crm-heading);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.dashboard-quick-actions a > span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
}

.dashboard-quick-actions svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.dashboard-quick-actions strong,
.dashboard-quick-actions small {
  display: block;
}

.dashboard-quick-actions small {
  margin-top: 2px;
  color: var(--crm-muted);
  font-size: 10px;
}

.dashboard-quick-actions b {
  color: var(--crm-muted);
  font-size: 20px;
}

.dashboard-donut {
  position: relative;
}

.dashboard-donut svg {
  display: block;
  width: 100%;
  transform: rotate(-90deg);
}

.dashboard-donut > div {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.dashboard-donut strong {
  color: var(--crm-heading);
  font-size: 28px;
}

.dashboard-donut small {
  color: var(--crm-muted);
}

.chart-key {
  display: grid;
  gap: 12px;
}

.chart-key > div {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 10px 0;
  border-bottom: 1px solid var(--crm-border);
  color: var(--crm-muted);
}

.chart-key > div > span:first-child {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.chart-key strong {
  color: var(--crm-heading);
}

.directory-toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--crm-border);
  border-radius: 16px;
  background: var(--crm-surface);
  box-shadow: var(--shadow);
}

.catalog-summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--crm-muted);
}

.catalog-summary strong {
  color: var(--crm-heading);
  font-size: 24px;
}

.product-catalog-grid,
.laboratory-catalog-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.product-catalog-card,
.laboratory-card {
  display: grid;
  align-content: start;
  gap: 18px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--crm-border);
  border-radius: 17px;
  background: var(--crm-surface);
  box-shadow: var(--shadow);
}

.product-card-top,
.laboratory-card-head,
.product-card-actions,
.laboratory-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.product-card-top,
.laboratory-card-head {
  justify-content: space-between;
}

.product-card-mark,
.laboratory-monogram {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
  font-weight: 850;
}

.product-card-mark svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.product-catalog-card small,
.laboratory-card small {
  color: var(--crm-accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.product-catalog-card h3,
.laboratory-card h3 {
  margin: 5px 0;
  font-size: 17px;
}

.product-catalog-card p,
.laboratory-card p {
  color: var(--crm-muted);
}

.product-catalog-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.product-catalog-card dl > div {
  min-width: 0;
  padding: 9px;
  border-radius: 11px;
  background: var(--crm-surface-muted);
}

.product-catalog-card dt {
  color: var(--crm-muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.product-catalog-card dd {
  margin: 4px 0 0;
  color: var(--crm-heading);
  overflow-wrap: anywhere;
}

.product-card-actions,
.laboratory-card-actions {
  align-self: end;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--crm-border);
}

.report-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--crm-heading), var(--crm-primary));
  color: #fff;
  box-shadow: 0 15px 36px rgba(16, 47, 80, .2);
}

.report-hero .eyebrow,
.report-hero p {
  color: rgba(255, 255, 255, .76) !important;
}

.report-hero h3 {
  margin: 5px 0;
  color: #fff;
  font-size: clamp(22px, 3vw, 32px);
}

.report-hero .btn.primary {
  flex: 0 0 auto;
  border-color: #fff !important;
  background: #fff !important;
  color: var(--crm-heading) !important;
}

.report-action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.report-action-card {
  display: grid;
  align-content: start;
  gap: 15px;
  padding: 18px;
  border: 1px solid var(--crm-border);
  border-radius: 17px;
  background: var(--crm-surface);
  box-shadow: var(--shadow);
}

.report-action-card small {
  color: var(--crm-accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.report-action-card h3 {
  margin: 5px 0;
}

.report-action-card p {
  color: var(--crm-muted);
}

.report-action-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
}

.report-action-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.report-action-card .btn {
  align-self: end;
  margin-top: auto;
}

#rh-profile-form,
#rh-generate-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#rh-profile-form .full,
#rh-generate-form .full,
#rh-profile-form > .btn,
#rh-generate-form > .btn {
  grid-column: 1 / -1;
}

.directory-search {
  flex: 1;
}

.directory-search .search {
  width: 100% !important;
  height: 40px !important;
}

.active-filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-chip,
.clear-filters {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid var(--crm-border);
  border-radius: 999px;
  background: var(--crm-surface);
  color: var(--crm-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 750;
}

.filter-chip span {
  color: var(--crm-danger);
}

.directory-filter-panel {
  position: fixed;
  z-index: 160;
  inset: var(--crm-topbar) 0 0 auto;
  width: min(410px, 100vw);
  border-radius: 18px 0 0 18px !important;
  box-shadow: -18px 0 50px rgba(10, 30, 50, .18) !important;
  overflow-y: auto;
}

.filter-drawer-backdrop {
  position: fixed;
  z-index: 150;
  inset: 0;
  width: 100%;
  padding: 0;
  border: 0;
  background: rgba(9, 25, 42, .28);
  backdrop-filter: blur(2px);
  cursor: default;
}

body.filter-drawer-open {
  overflow: hidden;
}

.directory-filter-panel .form.four {
  grid-template-columns: 1fr;
}

body.sidebar-collapsed {
  --crm-sidebar: 82px;
}

body.sidebar-collapsed .sidebar-brand-copy,
body.sidebar-collapsed .nav-section-label,
body.sidebar-collapsed .sidebar-account,
body.sidebar-collapsed .nav-label {
  display: none;
}

body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-collapse-toggle {
  position: absolute;
  right: -13px;
  transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar > .nav {
  padding-inline: 12px;
}

body.sidebar-collapsed .nav a,
body.sidebar-collapsed .nav-group summary {
  justify-content: center;
  padding-inline: 5px !important;
}

body.sidebar-collapsed .nav-group > a {
  margin-left: 0;
}

@media (max-width: 900px) {
  .content {
    padding: 18px 14px 36px !important;
  }

  .directory-toolbar {
    flex-wrap: wrap;
  }

  .directory-search {
    flex-basis: 100%;
  }

  .product-catalog-grid,
  .laboratory-catalog-grid,
  .report-action-grid,
  .dashboard-quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .directory-filter-panel {
    inset: auto 0 0;
    width: 100%;
    max-height: 88vh;
    border-radius: 22px 22px 0 0 !important;
  }
}

@media (max-width: 700px) {
  .page {
    gap: 13px !important;
  }

  .page-head {
    min-height: auto;
    align-items: start !important;
  }

  .directory-toolbar .btn {
    flex: 1 1 auto;
  }

  .product-catalog-grid,
  .laboratory-catalog-grid,
  .report-action-grid,
  .dashboard-quick-actions {
    grid-template-columns: 1fr;
  }

  .product-card-actions .btn,
  .laboratory-card-actions .btn {
    flex: 1 1 auto;
  }

  .report-hero {
    display: grid;
    padding: 20px;
  }

  .report-hero .btn {
    width: 100%;
  }

  #rh-profile-form,
  #rh-generate-form {
    grid-template-columns: 1fr;
  }

  .directory-page .table-wrap {
    border: 0;
    overflow: visible;
    background: transparent;
  }

  .directory-page table,
  .directory-page tbody {
    display: block;
  }

  .directory-page thead {
    display: none;
  }

  .directory-page tbody tr {
    display: grid;
    gap: 8px;
    margin: 10px;
    padding: 15px;
    border: 1px solid var(--crm-border);
    border-radius: 15px;
    background: var(--crm-surface);
  }

  .directory-page tbody td {
    display: block;
    padding: 2px !important;
    border: 0 !important;
  }

  .dashboard-donut-layout {
    grid-template-columns: 1fr;
  }

  .dashboard-donut {
    width: min(220px, 70vw);
    margin-inline: auto;
  }
}

@media (max-width: 700px) {
  .page .table-wrap {
    max-width: none;
    border: 0;
    overflow: visible;
    background: transparent;
  }

  .page .table-wrap > table.crm-table,
  .page .table-wrap > table.crm-table > tbody {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .page .table-wrap > table.crm-table > thead {
    display: none;
  }

  .page .table-wrap > table.crm-table > tbody > tr {
    display: grid;
    gap: 0;
    margin: 9px 0;
    padding: 12px 14px;
    border: 1px solid var(--crm-border);
    border-radius: 15px;
    background: var(--crm-surface);
    box-shadow: 0 7px 20px rgba(21, 47, 76, .05);
  }

  .page .table-wrap > table.crm-table > tbody > tr > td {
    display: grid;
    grid-template-columns: minmax(86px, .45fr) minmax(0, 1fr);
    align-items: start;
    min-width: 0;
    height: auto;
    gap: 10px;
    padding: 8px 0 !important;
    border-bottom: 1px solid var(--crm-border) !important;
    background: transparent !important;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td::before {
    color: var(--crm-muted);
    content: attr(data-label);
    font-size: 9px;
    font-weight: 850;
    letter-spacing: .06em;
    text-align: left;
    text-transform: uppercase;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td:first-child {
    color: var(--crm-heading);
    font-size: 13px;
    font-weight: 750;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td:last-child {
    display: flex;
    grid-template-columns: none;
    justify-content: flex-end;
    min-width: 0;
    gap: 6px;
    padding-bottom: 0 !important;
    border-bottom: 0 !important;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td:last-child::before {
    margin-right: auto;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td.empty {
    display: block;
    text-align: center;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td.empty::before {
    display: none;
  }

  .page .table-wrap > table.crm-table > tbody > tr > td .btn,
  .page .table-wrap > table.crm-table > tbody > tr > td a.btn {
    width: auto;
    margin: 0;
  }

  .table-toolbar {
    position: static;
    border: 1px solid var(--crm-border) !important;
    border-radius: 12px;
  }

  .row-action-popover {
    position: fixed;
    z-index: 1300;
    right: 10px;
    bottom: 10px;
    top: auto;
    left: 10px;
    width: auto;
    padding: 10px;
    border-radius: 16px;
  }
}
.page-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 5px;
  border: 1px solid var(--crm-border);
  border-radius: 12px;
  background: var(--crm-panel);
}

.page-tabs a {
  padding: 9px 14px;
  border-radius: 9px;
  color: var(--crm-muted);
  text-decoration: none;
}

.page-tabs a.active {
  color: var(--crm-text);
  background: var(--crm-primary-soft);
  font-weight: 700;
}

/* Application dashboards v6: styles complémentaires alignés sur le thème CRM existant. */
:root {
  --crm-panel: var(--crm-surface);
  --crm-primary-soft: var(--crm-info-soft);
}

.nav-group {
  display: grid;
  gap: 2px;
}

.nav-group summary {
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--crm-radius);
  color: var(--crm-muted);
  background: transparent;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}

.nav-group summary::-webkit-details-marker {
  display: none;
}

.nav-group summary::before {
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--crm-border-strong);
  content: "";
}

.nav-group summary::after {
  width: 7px;
  height: 7px;
  margin-left: auto;
  flex: 0 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  transform: rotate(45deg) translate(-2px, 2px);
  transition: transform 160ms ease;
}

.nav-group[open] summary::after {
  transform: rotate(225deg) translate(-1px, 1px);
}

.nav-group[open] summary,
.nav-group summary:hover {
  border-color: var(--crm-border);
  background: var(--crm-surface-muted);
  color: var(--crm-heading);
}

.nav-group > a {
  margin-left: 13px;
}

/* Stable sidebar and contextual form controls. Keep this final layer authoritative. */
.sidebar {
  width: var(--crm-sidebar);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar > .nav {
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.sidebar-collapse-toggle svg,
.btn svg,
.geo-quick-add svg,
.target-quick-add svg,
.product-create-context svg,
.context-create-modal .btn svg,
.geo-quick-modal .btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:has(> svg) {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.nav-group summary::before,
.nav-group summary::after {
  display: none !important;
}

.nav-group-chevron {
  width: 18px;
  height: 18px;
  margin-left: auto;
  transition: transform 160ms ease;
}

.nav-group-chevron svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.nav-group[open] .nav-group-chevron {
  transform: rotate(-90deg);
}

body.sidebar-collapsed .nav-group-chevron {
  display: none;
}

body.sidebar-collapsed .sidebar-account .nav {
  grid-template-columns: 1fr;
}

body.sidebar-collapsed .sidebar-account .nav a {
  justify-content: center;
}

.geo-field-with-add,
.target-field-with-add {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  gap: 8px;
}

.geo-field-with-add > label,
.target-field-with-add > label {
  grid-column: 1 / -1;
}

.geo-quick-add,
.target-quick-add {
  width: 42px;
  min-height: 42px;
  padding: 0 !important;
  display: inline-grid;
  place-items: center;
}

.product-section {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.product-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--crm-heading);
  font-weight: 800;
  cursor: pointer;
}

.product-section > summary strong {
  color: var(--crm-muted);
  font-size: 12px;
}

.product-section .product-multiselect {
  padding: 0 12px 12px;
}

.product-picker-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.product-create-context,
.context-create-modal .btn,
.geo-quick-modal .btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.product-select-trigger,
.product-dropdown,
.product-selected-chips span,
.product-choice,
.product-filter {
  background: var(--crm-surface) !important;
  border-color: var(--crm-border) !important;
  color: var(--crm-text) !important;
}

.context-create-backdrop,
.geo-quick-backdrop {
  z-index: 1300 !important;
}

@media (max-width: 700px) {
  .product-picker-actions {
    grid-template-columns: 1fr;
  }

  .product-create-context {
    justify-content: center;
  }
}

.dashboard-subnav,
.page-tabs.dashboard-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0;
  padding: 5px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.dashboard-subnav a {
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: var(--crm-radius);
  color: var(--crm-muted);
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 750;
}

.dashboard-subnav a:hover {
  border-color: var(--crm-border);
  background: var(--crm-surface-muted);
  color: var(--crm-heading);
}

.dashboard-subnav a.active {
  border-color: #b7d1e4;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
}

.app-dashboard {
  display: grid;
  gap: 12px;
}

.dashboard-tabs {
  margin-bottom: 0;
  overflow-x: auto;
}

.dashboard-tabs a {
  white-space: nowrap;
}

.dashboard-meter,
.trend-lines {
  display: grid;
  gap: 6px;
}

.dashboard-meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--crm-text);
}

.dashboard-meter-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-meter-head strong {
  color: var(--crm-heading);
  font-size: 12px;
}

.dashboard-trend-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.trend-label {
  display: grid;
  align-content: start;
  gap: 3px;
}

.trend-label small,
.dashboard-bars small {
  color: var(--crm-muted);
}

.alert-danger {
  border-color: color-mix(in srgb, var(--crm-danger) 35%, var(--crm-border)) !important;
  background: var(--crm-danger-soft) !important;
}

.alert-warning {
  border-color: color-mix(in srgb, var(--crm-warning) 35%, var(--crm-border)) !important;
  background: var(--crm-warning-soft) !important;
}

.alert-info {
  background: var(--crm-info-soft) !important;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check-grid label {
  min-height: 34px;
  padding: 8px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-muted);
  font-size: 12px;
}

.directory-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

@media (max-width: 900px) {
  .dashboard-trend-row {
    grid-template-columns: 1fr;
  }
}

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

  .dashboard-context .panel-head,
  .directory-pagination {
    display: grid !important;
  }
}
.directory-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-top: 1px solid var(--crm-border);
  gap: 1rem;
  flex-wrap: wrap;
}
.pagination-info {
  font-size: 0.875rem;
  color: var(--crm-text-subtle);
}
.pagination-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.pagination-pages {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-wrap: wrap;
}
.pagination-pages .btn {
  min-width: 2.25rem;
  height: 2.25rem;
  text-align: center;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  font-size: 0.875rem;
}
.pagination-pages .btn.active {
  background: var(--crm-accent);
  color: white;
  border-color: var(--crm-accent);
  cursor: default;
}
.pagination-prev, .pagination-next {
  min-width: 2.5rem !important;
  padding: 0 0.75rem !important;
}
.pagination-dots {
  padding: 0 0.25rem;
  color: var(--crm-text-subtle);
}
@media (max-width: 768px) {
  .directory-pagination {
    flex-direction: column;
    align-items: stretch;
  }
  .pagination-info { text-align: center; }
  .pagination-controls { justify-content: center; }
  .pagination-pages .btn {
    min-width: 2rem;
    height: 2rem;
    font-size: 0.8125rem;
  }
  .pagination-prev, .pagination-next {
    min-width: 2.25rem !important;
  }
}
@media (max-width: 480px) {
  .pagination-pages .btn {
    min-width: 1.75rem;
    height: 1.75rem;
    font-size: 0.75rem;
  }
  .pagination-prev, .pagination-next {
    min-width: 2rem !important;
  }
  .pagination-dots { font-size: 0.75rem; }
}
/* Touch-friendly */
@media (max-width: 768px) {
  .pagination-pages .btn,
  .pagination-prev,
  .pagination-next {
    min-height: 44px;
  }
}
.dashboard-filter-panel .dashboard-filters {
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  padding: 13px;
}

.actions-field {
  align-self: end;
}

.dashboard-context .panel-head {
  align-items: center;
}

.dashboard-context .panel-head > strong {
  color: var(--crm-accent);
  font-size: clamp(24px, 3vw, 38px);
}

.dashboard-kpis .card,
.dashboard-levers .panel,
.dashboard-gauge {
  min-height: 104px;
}

.dashboard-bars,
.dashboard-trend,
.dashboard-ranking,
.dashboard-alerts,
.dashboard-corrections {
  display: grid;
  gap: 9px;
  padding: 13px;
}

.dashboard-bar {
  display: grid;
  gap: 6px;
  padding: 9px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-muted);
}

.dashboard-bar > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.dashboard-bar span {
  color: var(--crm-muted);
  font-size: 11px;
  font-weight: 700;
}

.dashboard-bar strong {
  color: var(--crm-heading);
  font-size: 15px;
}

.bar-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--crm-surface-strong);
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--crm-accent);
}

.dashboard-gauge {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.dashboard-gauge small {
  color: var(--crm-muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.dashboard-gauge strong {
  color: var(--crm-heading);
  font-size: 28px;
}

.dashboard-rank-row,
.dashboard-alert,
.dashboard-correction,
.dashboard-trend-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-muted);
}

.dashboard-rank-row {
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
}

.dashboard-rank-row .rank {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
  font-weight: 850;
}

.dashboard-alert.critical,
.dashboard-correction.critical {
  border-color: color-mix(in srgb, var(--crm-danger) 35%, var(--crm-border));
  background: var(--crm-danger-soft);
}

.dashboard-alert.warning,
.dashboard-correction.warning {
  border-color: color-mix(in srgb, var(--crm-warning) 35%, var(--crm-border));
  background: var(--crm-warning-soft);
}

.dashboard-trend-row {
  grid-template-columns: 160px minmax(0, 1fr);
}

.trend-label {
  display: grid;
  align-content: start;
  gap: 2px;
}

.trend-lines {
  display: grid;
  gap: 6px;
}

@media (max-width: 1180px) {
  .dashboard-filter-panel .dashboard-filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .dashboard-filter-panel .dashboard-filters,
  .dashboard-trend-row,
  .dashboard-rank-row {
    grid-template-columns: 1fr;
  }

  .dashboard-subnav {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .dashboard-subnav a {
    white-space: nowrap;
  }
}

/* Final layout guards: keep the workspace inside every viewport. */
.main,
.content,
.page,
.grid-4,
.grid-3,
.grid-2,
.card,
.panel {
  min-width: 0;
}

.content {
  box-sizing: border-box;
}

.card {
  overflow: hidden;
}

.dashboard-filter-toolbar {
  justify-content: flex-end;
}

.dashboard-filter-panel {
  position: fixed;
  z-index: 160;
  inset: var(--crm-topbar) 0 0 auto;
  width: min(420px, 100vw);
  max-height: calc(100vh - var(--crm-topbar));
  border-radius: 18px 0 0 18px !important;
  box-shadow: -18px 0 50px rgba(10, 30, 50, .18) !important;
  overflow-y: auto;
}

.dashboard-filter-panel .dashboard-filters {
  grid-template-columns: 1fr !important;
}

.app-filter-toolbar {
  justify-content: flex-end;
}

.app-filter-drawer {
  position: fixed;
  z-index: 160;
  inset: var(--crm-topbar) 0 0 auto;
  width: min(420px, 100vw);
  max-height: calc(100vh - var(--crm-topbar));
  border-radius: 18px 0 0 18px !important;
  box-shadow: -18px 0 50px rgba(10, 30, 50, .18) !important;
  overflow-y: auto;
}

.app-filter-drawer form,
.app-filter-drawer .form,
.app-filter-drawer .inline-form {
  grid-template-columns: 1fr !important;
}

@media (max-width: 900px) {
  .dashboard-filter-panel,
  .app-filter-drawer {
    inset: auto 0 0;
    width: 100%;
    max-height: 88vh;
    border-radius: 22px 22px 0 0 !important;
  }
}

@media (max-width: 700px) {
  .modal-backdrop {
    display: flex;
    align-items: flex-end;
    padding: 0 !important;
  }

  .modal {
    width: 100% !important;
    min-height: 0 !important;
    max-height: 92vh !important;
    border: 1px solid var(--crm-border) !important;
    border-bottom: 0 !important;
    border-radius: 22px 22px 0 0 !important;
  }

  .modal-body {
    overflow-y: auto;
  }
}

/* Responsive interaction polish */
.workday-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.workday-active,
.workday-active:disabled {
  border-color: color-mix(in srgb, var(--crm-success) 55%, var(--crm-border)) !important;
  background: var(--crm-success-soft) !important;
  color: var(--crm-success) !important;
  opacity: 1 !important;
}

.voice-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.voice-btn.listening {
  border-color: color-mix(in srgb, var(--crm-success) 55%, var(--crm-border)) !important;
  background: var(--crm-success-soft) !important;
  color: var(--crm-success) !important;
}

.voice-btn.disabled,
.voice-btn:disabled {
  pointer-events: none;
}

.page-head,
.panel-head {
  min-width: 0;
}

.page-head .actions,
.panel-head .actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.modal-head {
  position: sticky;
  z-index: 3;
  top: 0;
}

.modal-head .modal-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

@media (max-width: 760px) {
  .page-head,
  .panel-head {
    align-items: stretch !important;
    flex-direction: column;
    gap: 10px;
  }

  .page-head .actions,
  .panel-head .actions,
  .workday-actions {
    width: 100%;
    justify-content: stretch;
  }

  .page-head .actions > *,
  .panel-head .actions > *,
  .workday-actions > * {
    min-width: min(100%, 150px);
    flex: 1 1 150px;
    justify-content: center;
  }

  .form.two,
  .form.three,
  .form.four,
  .line-row {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .field,
  .field input,
  .field select,
  .field textarea {
    min-width: 0;
    max-width: 100%;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* SKY UI final correction layer */
:root {
  --sky-modal-z: 1400;
  --sky-overlay-z: 1300;
  --sky-drawer-z: 1200;
  --sky-topbar-z: 300;
}

:root[data-theme="dark"] {
  --crm-bg: #182230;
  --crm-surface: #202c3b;
  --crm-surface-muted: #263548;
  --crm-surface-strong: #2d3d52;
  --crm-border: #3b4d63;
  --crm-border-strong: #52677f;
  --crm-text: #edf4fb;
  --crm-muted: #b3c0ce;
  --crm-heading: #f7fbff;
  --crm-primary: #7db7e8;
  --crm-primary-hover: #9bccf2;
  --crm-accent: #6ed3c6;
  --crm-success: #79d7aa;
  --crm-warning: #f0c573;
  --crm-danger: #f09b9b;
  --crm-info-soft: #223e58;
  --crm-success-soft: #213d35;
  --crm-warning-soft: #433720;
  --crm-danger-soft: #43292d;
  --crm-focus: 0 0 0 3px rgba(125, 183, 232, .26);
  color-scheme: dark;
}

:root[data-theme="dark"] body,
:root[data-theme="dark"] .shell,
:root[data-theme="dark"] .page {
  background: var(--crm-bg);
  color: var(--crm-text);
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .mini-card,
:root[data-theme="dark"] .report-section-card,
:root[data-theme="dark"] .performance-item,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .modal-body,
:root[data-theme="dark"] .table-wrap,
:root[data-theme="dark"] .entity-detail-grid article,
:root[data-theme="dark"] .entity-detail-metrics article,
:root[data-theme="dark"] .comment-item {
  background: var(--crm-surface);
  border-color: var(--crm-border);
  color: var(--crm-text);
}

:root[data-theme="dark"] .subtle,
:root[data-theme="dark"] .muted,
:root[data-theme="dark"] small,
:root[data-theme="dark"] .entity-detail-hero p,
:root[data-theme="dark"] .performance-item span,
:root[data-theme="dark"] .performance-item p,
:root[data-theme="dark"] .detail-grid dt {
  color: var(--crm-muted) !important;
}

:root[data-theme="dark"] .btn.primary {
  background: var(--crm-primary) !important;
  border-color: var(--crm-primary) !important;
  color: #102033 !important;
}

:root[data-theme="dark"] .btn.danger {
  background: var(--crm-danger-soft) !important;
  border-color: color-mix(in srgb, var(--crm-danger) 45%, var(--crm-border)) !important;
  color: var(--crm-danger) !important;
}

:root[data-theme="dark"] .chip,
:root[data-theme="dark"] .filter-chip {
  background: var(--crm-surface-muted);
  border-color: var(--crm-border);
  color: var(--crm-text);
}

.topbar {
  z-index: var(--sky-topbar-z);
}

.mobile-drawer,
.sidebar.open {
  z-index: var(--sky-drawer-z);
}

.modal-backdrop {
  z-index: var(--sky-overlay-z);
}

.modal,
.toast-stack {
  z-index: var(--sky-modal-z);
}

.directory-filter-panel {
  position: relative;
  z-index: 20;
}

.visit-detail-modal,
.entity-detail-modal {
  width: min(1120px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
}

.visit-detail-modal .modal-body,
.entity-detail-modal .modal-body {
  max-height: min(78vh, 820px);
  overflow: auto;
  overscroll-behavior: contain;
}

.visit-detail-view,
.entity-detail-view {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.visit-detail-view > section,
.entity-detail-view > section {
  min-width: 0;
}

.visit-detail-view .grid-2 {
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, .75fr);
  align-items: start;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(120px, .38fr) minmax(0, 1fr);
  gap: 8px 14px;
  min-width: 0;
}

.detail-grid dt {
  color: var(--crm-muted);
  font-weight: 700;
}

.detail-grid dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-grid.compact {
  grid-template-columns: minmax(110px, .42fr) minmax(0, 1fr);
}

.stamp-preview-large {
  display: block;
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  background: var(--crm-surface-muted);
}

.product-list,
.report-cards,
.report-section-list,
.entity-detail-metrics,
.entity-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  min-width: 0;
}

.mini-card,
.report-cards article,
.report-section-card,
.entity-detail-metrics article,
.entity-detail-grid article {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  background: var(--crm-surface);
}

.mini-card,
.report-cards article,
.report-section-card,
.entity-detail-grid article {
  padding: 14px;
}

.mini-card strong,
.report-cards strong,
.report-section-card strong,
.entity-detail-metrics strong,
.entity-detail-grid dd {
  overflow-wrap: anywhere;
}

.report-section-card h5,
.entity-detail-grid h5 {
  margin: 0 0 10px;
}

.report-section-card ul,
.entity-history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.report-section-card li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.report-section-card p,
.report-section-card small,
.mini-card p {
  margin: 0;
}

.ok-dot,
.muted-dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.ok-dot {
  background: var(--crm-success);
}

.muted-dot {
  background: var(--crm-border-strong);
}

.entity-detail-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--crm-info-soft), var(--crm-surface));
}

.entity-detail-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--crm-primary);
  color: #fff;
}

.entity-detail-mark svg {
  width: 28px;
  height: 28px;
}

.entity-detail-hero h4,
.entity-detail-hero p,
.entity-detail-metrics article span,
.entity-detail-metrics article strong {
  margin: 0;
}

.entity-detail-status {
  justify-self: end;
}

.entity-detail-metrics article {
  padding: 14px;
}

.entity-detail-metrics span {
  display: block;
  color: var(--crm-muted);
  font-size: 12px;
}

.entity-detail-metrics strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.row-actions,
td.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  min-width: 180px;
}

.btn,
.icon-btn,
.theme-card {
  min-width: 0;
}

.btn svg,
.icon-btn svg,
.theme-card svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.btn {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
}

table {
  max-width: 100%;
}

th,
td {
  min-width: 0;
  overflow-wrap: anywhere;
  vertical-align: top;
}

input,
select,
textarea,
.search,
.directory-query {
  max-width: 100%;
  min-width: 0;
}

.directory-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.directory-search {
  flex: 1 1 280px;
  min-width: min(100%, 240px);
}

.directory-toolbar .btn {
  flex: 0 1 auto;
}

.theme-choice {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 12px;
}

.theme-card span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--crm-info-soft);
  color: var(--crm-primary);
}

@media (max-width: 760px) {
  .visit-detail-modal,
  .entity-detail-modal {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .visit-detail-modal .modal-body,
  .entity-detail-modal .modal-body {
    max-height: calc(100vh - 112px);
  }

  .visit-detail-view .grid-2,
  .entity-detail-hero,
  .detail-grid,
  .detail-grid.compact {
    grid-template-columns: minmax(0, 1fr);
  }

  .entity-detail-status {
    justify-self: start;
  }

  .directory-toolbar {
    align-items: stretch;
  }

  .directory-search,
  .directory-toolbar .btn {
    flex: 1 1 100%;
  }

  .row-actions,
  td.row-actions {
    justify-content: flex-start;
    min-width: 0;
  }

  .row-actions .btn {
    flex: 1 1 120px;
  }
}

@media (max-width: 760px) {
  .topbar .theme-toggle .theme-label,
  .topbar .logout-button .logout-label,
  .drawer-user .theme-toggle .theme-label,
  .drawer-user .logout-button .logout-label {
    display: none !important;
  }

  .topbar .theme-toggle,
  .topbar .logout-button,
  .drawer-user .theme-toggle,
  .drawer-user .logout-button {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px;
    padding: 0 !important;
    flex: 0 0 42px !important;
  }

  .topbar .theme-toggle > span:first-child,
  .drawer-user .theme-toggle > span:first-child {
    display: grid;
    place-items: center;
  }
}
