:root { --ink: #202d3b; --line: #dce5ec; --surface: #fff; --page: #f4f7fa; --nav: #18334d; }
body { margin: 0; min-height: 100vh; background: var(--page); color: var(--ink); }
button, input, select { font: inherit; }
label { display: grid; gap: .35rem; font-weight: 600; }
.form-control { width: 100%; box-sizing: border-box; min-height: 2.5rem; padding: .45rem .65rem; border: 1px solid #aebdc9; border-radius: .35rem; background: white; }
.form-control:focus { outline: 2px solid #2b7bbb; outline-offset: 1px; }
.auth-card { max-width: 440px; margin: 9vh auto; padding: 2rem; background: white; border: 1px solid var(--line); border-radius: .7rem; box-shadow: 0 15px 40px #13324b16; }
.auth-card form { display: grid; gap: 1rem; }
.form-error { color: #a72222; min-height: 1.4em; margin: 0; }
.app-header { min-height: 64px; padding: .75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: white; border-bottom: 1px solid var(--line); }
.app-header strong { display: block; font-size: 1.1rem; }
.header-context { display: block; color: #526b7d; font-size: .9rem; }
.header-user { display: flex; align-items: center; gap: 1rem; }
.app-body { display: grid; grid-template-columns: 230px minmax(0,1fr); min-height: calc(100vh - 64px); }
.app-sidebar { background: var(--nav); padding: 1rem .65rem; }
.app-sidebar ul { list-style: none; padding: 0; margin: 0; }
.app-sidebar li { margin: .25rem 0; }
.app-sidebar button { width: 100%; border: 0; border-radius: .35rem; padding: .75rem; text-align: left; color: #e8f3fb; background: transparent; cursor: pointer; }
.app-sidebar button:hover, .app-sidebar button.active { background: #2d5e86; }
.app-main { padding: 1.5rem; min-width: 0; }
.panel { padding: 1.4rem; margin-bottom: 1.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: .55rem; }
.panel h1, .panel h2 { margin-top: 0; }
.section-heading, .list-card, .row-actions, .inline-form { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.inline-form { justify-content: flex-start; flex-wrap: wrap; }
.inline-form label { min-width: min(350px,100%); }
.list-card { padding: 1rem 0; border-top: 1px solid var(--line); }
.list-card strong, .list-card small { display: block; }
.list-card small, .muted { color: #607688; }
.row-actions { justify-content: flex-end; flex-wrap: wrap; }
.edit-panel { border-color: #81b3d9; }
.edit-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.full-row { grid-column: 1 / -1; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: .5rem; }
.check-row { display: flex; align-items: center; gap: .3rem; font-weight: 400; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: .35rem; }
.policy-card { border-top: 1px solid var(--line); padding: 1.2rem 0; }
.policy-columns { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; margin-bottom: 1rem; }
.policy-columns fieldset > div { display: grid; gap: .5rem; }
.btn { min-height: 2.5rem; cursor: pointer; }
.btn:disabled { opacity: .55; cursor: default; }
.alert[hidden] { display: none; }
@media (max-width: 720px) {
  .app-header, .section-heading { align-items: flex-start; flex-direction: column; }
  .app-body { grid-template-columns: 1fr; }
  .app-sidebar { overflow-x: auto; }
  .app-sidebar ul { display: flex; gap: .3rem; }
  .app-sidebar button { white-space: nowrap; }
  .app-main { padding: .8rem; }
  .edit-grid, .policy-columns { grid-template-columns: 1fr; }
}

/* Compact application layer over the original e-crm styles. */
:root { --ink: #243347; --line: #dce4ec; --page: #f3f6f9; --nav: #1d344d; --accent: #2869a5; }
body { font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif; font-size: 14px; }
label { gap: 4px; margin: 0; }
.muted, .list-card small { color: #62758a; }
.form-control { min-height: 34px; padding: 5px 9px; border: 1px solid #b9c7d4; border-radius: 5px; color: var(--ink); font-size: 13px; }
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #2869a526; outline: 0; }
.btn { min-height: 34px; padding: 5px 11px; border-radius: 5px; font-size: 13px; font-weight: 600; line-height: 1.3; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #205989; border-color: #205989; color: #fff; }
.btn-outline-secondary { border-color: #b9c7d4; color: #354e66; background: #fff; }
.btn-outline-secondary:hover { background: #edf3f8; color: #243b53; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent) !important; outline-offset: 2px; }

.auth-card { width: min(400px, calc(100% - 32px)); max-width: none; margin: min(12vh, 90px) auto; padding: 24px; border-radius: 9px; box-shadow: 0 16px 40px #173a5914; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; }
.auth-card p { margin: 0 0 18px; color: #62758a; }
.auth-card form { gap: 12px; }
.auth-card form .btn { width: 100%; margin-top: 4px; }
.form-error { min-height: 1.2em; margin: 0; color: #a72a2a; }

.app-header { min-height: 54px; padding: 7px 18px; }
.app-header strong { color: #203a54; font-size: 15px; font-weight: 700; }
.header-context { max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #62758a; font-size: 12px; }
.header-user { gap: 12px; white-space: nowrap; color: #425a70; font-size: 13px; }
.header-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-brand > div { min-width: 0; }
.sidebar-toggle { width: 34px; min-width: 34px; padding: 3px; font-size: 19px; line-height: 1; }
.context-help-button { position: fixed; right: 16px; bottom: 16px; z-index: 900; width: 32px; height: 32px; border: 1px solid #9eb8cf; border-radius: 50%; background: #fff; color: #2869a5; font: 700 18px/1 system-ui, sans-serif; box-shadow: 0 2px 8px #18395422; cursor: pointer; }
.context-help-button:hover { background: #edf5fb; border-color: #2869a5; }
.context-help-button--inline { position: static; flex: 0 0 27px; width: 27px; height: 27px; box-shadow: none; font-size: 16px; margin-left: auto; }
.app-dialog__header .context-help-button--inline + .app-dialog__close { margin-left: 0; }
.header-organization-label { display: block; min-width: min(260px, 25vw); font-weight: 400; }
.header-organization-label select { min-width: 160px; max-width: min(330px, 31vw); cursor: pointer; }
.app-shell.vertical-collpsed .app-body { grid-template-columns: 0 minmax(0, 1fr); }
.app-shell.vertical-collpsed .app-sidebar { overflow: hidden; padding: 0; visibility: hidden; }
.app-body { grid-template-columns: 190px minmax(0, 1fr); min-height: calc(100vh - 54px); }
.app-sidebar { padding: 12px 8px; }
.app-sidebar li { margin: 2px 0; }
.app-sidebar button { min-height: 36px; padding: 7px 11px; border-radius: 5px; font-size: 13px; }
.app-sidebar button:hover, .app-sidebar button.active { background: #315675; color: #fff; }
.app-sidebar button.active { box-shadow: inset 3px 0 #77b9e8; font-weight: 650; }
.app-main { padding: 16px 20px; }
#workSpase { max-width: 1480px; }
#app-message { margin-bottom: 12px; }

.panel { margin: 0 0 12px; padding: 16px; border-radius: 7px; box-shadow: 0 1px 3px #18395408; }
.panel h1, .panel h2 { margin: 0; color: #243b53; font-weight: 650; }
.panel h1 { font-size: 19px; }
.panel h2 { font-size: 16px; }
.panel > p, .section-heading p { margin: 5px 0 12px; line-height: 1.4; }
.section-heading, .list-card, .row-actions, .inline-form { gap: 10px; }
.section-heading { margin-bottom: 12px; }
.section-heading p { margin-bottom: 0; }
.inline-form label { min-width: min(320px, 100%); }
.list-card { min-height: 48px; padding: 7px 0; }
.edit-panel { border-color: #9cc1df; box-shadow: 0 0 0 2px #2869a50d; }
.edit-panel h2 { margin-bottom: 12px; }
.edit-panel form, .edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 940px; }
.edit-panel #organization-edit .row-actions { grid-column: 1 / -1; }
.check-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 5px 12px; }
.check-row { gap: 7px; }
.check-row input { margin: 0; }
fieldset { margin: 0; padding: 9px 11px 11px; border-radius: 5px; }
legend { width: auto; padding: 0 4px; font-size: 13px; font-weight: 650; }
.policy-card { padding: 13px 0; }
.policy-card h2 { margin-bottom: 9px; }
.policy-card > .btn { margin-top: 9px; }
.policy-columns { gap: 12px; }
.policy-columns fieldset > div { gap: 5px; }

/* The table shell and headings come from the e-crm js/lib table component. */
.compact-table { width: 100%; max-width: 100%; }
.compact-table .head-table { min-height: 0; margin-bottom: 7px; gap: 10px; }
.compact-table .block_btn_table { display: flex; flex: 0 0 auto; align-items: flex-end; justify-content: flex-end; gap: 8px; flex-wrap: nowrap; }
.compact-table .resize_block_table { width: 100%; max-width: 100%; margin-left: 0 !important; overflow-x: auto; }
.compact-table .resize_block_table > div:last-child { width: 100%; }
.compact-table .table { width: 100%; min-width: 600px; max-width: none; margin: 0; font-size: 13px; }
.compact-table .table > :not(caption) > * > * { padding: 8px 10px; border-bottom: 1px solid #e6ecf1; vertical-align: middle; }
.compact-table .table thead th { color: #5b6e80; background: #f7f9fb; font-size: 12px; font-weight: 700; }
.compact-table .table thead tr { position: static !important; opacity: 1 !important; }
.compact-table .table tbody tr:hover { background: #f5f9fc; }
.compact-table .table tbody tr:last-child td { border-bottom: 0; }
.compact-table .table-nowrap th, .compact-table .table-nowrap td { white-space: normal; }
.compact-table .table-actions { width: 1%; white-space: nowrap !important; text-align: right; }
.compact-table .table-actions .btn + .btn { margin-left: 5px; }
.compact-table .table-empty { padding: 20px 10px !important; color: #62758a; text-align: center; }
.compact-table .table-primary { font-weight: 650; color: #213c55; }
.compact-table .data-grid .btn-sm { min-height: 30px; padding: 4px 8px; font-size: 12px; }
.compact-clickable-row { cursor: pointer; }
.compact-clickable-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; background: #edf5fb; }
.compact-table .block_btn_table .table-search { width: 220px; flex: 0 0 220px; margin: 0; font-size: 12px; }
.compact-search-panel { display: flex; align-items: end; gap: 9px; flex-wrap: wrap; margin: 0 0 9px; padding: 9px; border: 1px solid var(--line); border-radius: 5px; background: #f7f9fb; }
.compact-search-panel[hidden], .compact-search-panel.displayNone { display: none; }
.compact-search-panel .table-search { margin: 0; min-width: min(270px, 100%); }
.compact-search-panel .compact-search-reset { flex: 0 0 auto; }
.compact-sort-button { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: inherit; cursor: pointer; text-align: left; }
.compact-sort-button:hover { color: #205989; }
.compact-sort-indicator { min-width: 1em; color: #2869a5; }
.compact-pagination { display: flex; align-items: center; justify-content: flex-start; gap: 3px; flex-wrap: wrap; margin: 7px 0; }
.compact-pagination[hidden] { display: none; }
.compact-pagination-pages { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.compact-page-button { min-width: 29px; min-height: 29px; padding: 3px 7px; border: 1px solid #cbd8e4; border-radius: 4px; background: #fff; color: #315675; font-size: 12px; cursor: pointer; }
.compact-page-button:hover:not(:disabled) { background: #edf4fa; }
.compact-page-button[aria-current="page"] { border-color: #2869a5; background: #2869a5; color: #fff; }
.compact-page-button:disabled { opacity: .4; cursor: default; }
.compact-page-summary { margin-right: 8px; color: #62758a; font-size: 12px; }
.panel .table-search { width: min(280px, 100%); margin: 0 0 9px; font-size: 12px; }
.section-heading .table-search { margin-bottom: 0; }
.data-grid td:first-child strong, .data-grid td:first-child small { display: block; }
.data-grid td:first-child small { margin-top: 2px; color: #62758a; }
.status-pill { display: inline-block; padding: 2px 7px; border-radius: 999px; background: #e7f4ed; color: #22734e; font-size: 11px; font-weight: 650; white-space: nowrap; }
.status-pill.is-inactive { background: #f1f3f5; color: #677482; }
.status-pill.is-selected { background: #e7f0fa; color: #255e91; }
.status-pill.is-warning { background: #fff0d8; color: #83531b; }
.compact-table .status-pill.is-warning { white-space: normal; text-align: center; }

#progressBar { position: fixed; top: 13px; right: 14px; z-index: 1200; width: 23px; height: 23px; border: 3px solid #c9ddec; border-top-color: var(--accent); border-radius: 50%; animation: spinner-border .75s linear infinite; pointer-events: none; }
#progressBar.displayNone { display: none; }
.app-dialog #progressBar { position: absolute; top: 12px; right: 52px; }

.app-dialog { position: fixed; inset: 0; width: min(680px, calc(100vw - 32px)); max-width: none; max-height: min(82dvh, 760px); margin: auto; padding: 0; overflow: hidden; border: 1px solid #aac2d6; border-radius: 9px; background: #fff; color: var(--ink); box-shadow: 0 24px 70px #0e2c4590; }
html:has(.app-dialog[open]), body:has(.app-dialog[open]) { overflow: hidden; }
.app-dialog[open] { display: flex; flex-direction: column; }
.app-dialog::backdrop { background: #10283e8c; }
.app-dialog__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 10px 15px; border-bottom: 1px solid var(--line); background: #f7f9fb; user-select: none; }
.app-dialog__title { margin: 0; color: #243b53; font-size: 16px; font-weight: 700; }
.app-dialog__close { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: #536b80; font-size: 24px; line-height: 1; cursor: pointer; }
.app-dialog__close:hover { background: #e7eef4; color: #263e54; }
.app-dialog__body { min-height: 0; padding: 16px; overflow: auto; }
.app-dialog .dialog-form { max-width: none; }
.app-dialog .dialog-actions { position: sticky; bottom: -16px; z-index: 1; justify-content: flex-end; margin: 3px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--line); background: #fff; }
.app-dialog .policy-columns { margin: 0; }
.app-dialog .policy-columns fieldset > div { max-height: 38vh; overflow: auto; }
.app-dialog .menu-policy-form > .alert-danger { margin: 0 0 10px; padding: 9px 11px; border: 1px solid #edcb9b; border-radius: 5px; background: #fff7ea; color: #7b4818; }
.app-dialog .menu-policy-form .row-actions { position: sticky; bottom: -16px; justify-content: flex-end; margin: 10px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--line); background: #fff; }
@media (min-width: 768px) and (pointer: fine) { .app-dialog__header { cursor: grab; } .app-dialog__header:active { cursor: grabbing; } }

@media (max-width: 800px) {
  .app-body { display: block; min-height: calc(100vh - 54px); }
  .app-shell.vertical-collpsed .app-sidebar { display: none; }
  .app-sidebar { overflow-x: auto; padding: 6px 8px; }
  .app-sidebar ul { display: flex; gap: 4px; }
  .app-sidebar li { flex: 0 0 auto; margin: 0; }
  .app-sidebar button { width: auto; white-space: nowrap; }
  .app-sidebar button.active { box-shadow: inset 0 -3px #77b9e8; }
  .app-main { padding: 12px; }
}
@media (max-width: 580px) {
  .app-header { align-items: flex-start; flex-direction: row; flex-wrap: wrap; padding: 8px 12px; }
  .app-header strong { font-size: 13px; }
  .header-context { max-width: 56vw; }
  .header-user { gap: 5px; font-size: 12px; margin-left: auto; }
  .header-user-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .header-organization-label { min-width: min(220px, 52vw); }
  .header-organization-label select { min-width: 0; width: 100%; max-width: 52vw; }
  .header-user .btn { min-height: 32px; padding-inline: 7px; }
  .panel { padding: 12px; }
  .section-heading { align-items: flex-start; flex-wrap: wrap; flex-direction: row; }
  .edit-grid, .edit-panel form, .policy-columns { grid-template-columns: 1fr; }
  .compact-table .head-table { align-items: stretch; }
  .compact-table .block_btn_table { justify-content: stretch; width: 100%; flex-wrap: wrap; }
  .compact-table .block_btn_table .table-search { flex: 1 1 170px; width: 100%; min-width: 120px; }
  .panel .table-search { width: 100%; }
  .compact-table { width: 100%; }
  .compact-table .resize_block_table { width: 100%; max-width: 100%; overflow-x: auto; }
  .compact-table .resize_block_table > div:last-child { min-width: max-content; }
  .compact-table .table { display: table; width: max-content; min-width: 600px; }
  .compact-table .table thead { position: static; width: auto; height: auto; clip-path: none; white-space: normal; }
  .compact-table .table tbody { display: table-row-group; }
  .compact-table .table tr { display: table-row; margin: 0; padding: 0; border: 0; border-radius: 0; }
  .compact-table .table td { display: table-cell; width: auto; padding: 8px 10px; border-bottom: 1px solid #e6ecf1; text-align: left; overflow-wrap: normal; }
  .compact-table .table td::before { content: none; }
  .compact-table .table td.table-empty { text-align: center; }
  .compact-table .table td.table-actions { width: 1%; }
  .compact-pagination { align-items: flex-start; }
  .compact-pagination-pages { max-width: 100%; }
  .btn { min-height: 38px; }
  .compact-table .data-grid .btn-sm { min-height: 32px; }
}
@media (max-width: 767px) {
  .app-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); border-radius: 7px; }
  .app-dialog__header { min-height: 45px; padding: 8px 12px; cursor: default; }
  .app-dialog__body { padding: 12px; }
  .app-dialog .dialog-actions { bottom: -12px; margin: 3px -12px -12px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .app-dialog .dialog-actions .btn { flex: 1 1 100%; }
  .app-dialog .menu-policy-form .row-actions { bottom: -12px; margin: 10px -12px -12px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .app-dialog .menu-policy-form .row-actions .btn { flex: 1 1 100%; }
  .app-dialog .policy-columns fieldset > div { max-height: none; }
  .app-dialog .policy-columns { grid-template-columns: 1fr; }
}
