:root {
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  color: #23332f;
  background: #f0f3f2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #23332f;
  --muted: #6b7772;
  --line: #dce3e0;
  --paper: #fff;
  --teal: #159b8a;
  --teal-dark: #0f776b;
  --green: #245c49;
  --coral: #c85c43;
  --wash: #e7f2ef;
  --serif: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #fff; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.app-header { position: sticky; top: 0; z-index: 20; background: #fff; box-shadow: 0 1px 5px #152d2918; }
.identity-row { min-height: 57px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 max(20px, calc((100vw - 1440px) / 2)); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.brand-mark { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--teal); font-family: var(--serif); font-size: 19px; }
.local-badge { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.local-badge span { width: 7px; height: 7px; border-radius: 50%; background: #4a9a69; }
.header-account { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 11px; }
.header-account form { margin: 0; }
.auth-shell { min-height: calc(100vh - 57px); display: grid; place-items: center; padding: 24px 16px; }
.auth-panel { width: min(440px, 100%); border: 1px solid var(--line); background: #fff; }
.auth-panel-header { padding: 20px 22px 15px; border-bottom: 1px solid var(--line); background: #f5f7f6; }
.auth-panel-body { display: grid; gap: 15px; padding: 20px 22px; }
.auth-panel-body .hint { margin: 0; }
.auth-panel .notices { margin: 0 22px; }
@media (max-width: 560px) {
  .header-account { gap: 7px; }
  .header-account > span:first-child { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-account .local-badge { display: none; }
}
.module-nav { min-height: 47px; display: flex; align-items: stretch; gap: 3px; padding: 0 max(12px, calc((100vw - 1440px) / 2)); overflow-x: auto; background: var(--teal); }
.module-tab { position: relative; min-width: 112px; padding: 0 19px; border: 0; border-radius: 0; color: #effbf8; background: transparent; cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; }
.module-tab:hover { background: #ffffff19; }
.module-tab[aria-selected='true'] { color: #fff; background: #087c70; }
.module-tab[aria-selected='true']::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: #d2f3e8; content: ''; }
.app-main { max-width: 1480px; min-height: calc(100vh - 150px); margin: 0 auto; padding: 19px 16px 48px; }
.module-view[hidden] { display: none !important; }
.contacts-view { display: grid; grid-template-columns: minmax(0, 196px) minmax(0, 1fr); min-width: 0; min-height: 570px; border: 1px solid var(--line); background: var(--paper); }
.group-sidebar { min-width: 0; background: #f5f7f6; border-right: 1px solid var(--line); }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; min-height: 43px; padding: 0 12px; color: #485851; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.contact-count, .record-count { color: var(--muted); font-size: 12px; font-weight: 400; }
.group-nav { display: grid; min-width: 0; gap: 2px; padding: 9px 7px; }
.group-link { display: block; padding: 8px 10px; border-radius: 2px; color: #4c5a54; font-size: 12px; }
.group-link:hover { background: #e8efec; }
.group-link.active { color: #14594d; background: #d7eee8; font-weight: 700; }
.view-content { min-width: 0; padding: 21px 23px 28px; background: #fff; }
.contacts-view > .view-content { padding: 0; }
.view-toolbar { min-height: 74px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px; padding: 13px 17px; border-bottom: 1px solid var(--line); }
.contacts-view .view-toolbar { background: #f5f7f6; }
.eyebrow { margin: 0 0 5px; color: var(--teal-dark); font-size: 9px; font-weight: 700; letter-spacing: 1.1px; }
h1 { margin: 0; color: var(--ink); font-family: var(--serif); font-size: 25px; font-weight: 400; }
.record-count { font-family: 'Trebuchet MS', 'Segoe UI', sans-serif; }
.toolbar-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.toolbar-link, .action-menu > summary { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; border: 1px solid #d5ded9; border-radius: 2px; color: #315a4b; background: #fff; cursor: pointer; font-size: 12px; font-weight: 600; list-style: none; }
.action-menu > summary::-webkit-details-marker { display: none; }
.toolbar-link:hover, .action-menu > summary:hover { background: var(--wash); }
.action-menu { position: relative; }
.action-menu[open] { flex-basis: 100%; }
.action-menu[open] > summary { width: max-content; }
.action-menu .form-grid, .action-menu .import-form, .action-menu .hint { margin-top: 13px; }
.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border: 0; border-radius: 2px; cursor: pointer; font-size: 12px; font-weight: 600; }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: #194533; }
.button.secondary { color: #245c49; background: var(--wash); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.summary-chip { padding: 7px 10px; border: 1px solid var(--line); color: #52635b; background: #f8faf9; font-size: 11px; white-space: nowrap; }
.finance-tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); background: #f8faf9; }
.finance-tab { min-height: 39px; display: inline-flex; align-items: center; padding: 0 14px; border-bottom: 2px solid transparent; color: #596761; font-size: 12px; }
.finance-tab:hover { color: var(--teal-dark); }
.finance-tab.active { color: var(--teal-dark); border-bottom-color: var(--teal); background: #fff; font-weight: 700; }
.accounting-layout { display: grid; grid-template-columns: minmax(0, 245px) minmax(0, 1fr); min-width: 0; min-height: 420px; border-bottom: 1px solid var(--line); }
.account-sidebar { min-width: 0; border-right: 1px solid var(--line); background: #f6f8f7; }
.account-sidebar .sidebar-title { min-height: 39px; }
.account-tree { display: grid; gap: 2px; padding: 8px; }
.account-tree > details > summary { padding: 8px 10px; color: #4c5a54; cursor: pointer; font-size: 12px; font-weight: 600; }
.account-link { display: block; padding: 8px 10px; border-radius: 2px; color: #4c5a54; font-size: 12px; }
.account-link:hover, .account-tree > details > summary:hover { background: #e8efec; }
.account-link.active { color: #14594d; background: #d7eee8; font-weight: 700; }
.account-link.nested { margin-left: 12px; }
.accounting-content { min-width: 0; padding: 0; }
.empty-state { max-width: 600px; margin: 40px auto; padding: 25px; border: 1px solid var(--line); text-align: center; }
.empty-state h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 22px; font-weight: 400; }
.empty-state p { margin: 0; color: var(--muted); font-size: 12px; }
.record-dialog { width: min(1040px, calc(100vw - 28px)); max-width: none; max-height: min(92vh, 900px); padding: 0; overflow: auto; border: 1px solid #cbd6d1; background: #fff; box-shadow: 0 18px 70px #12292345; }
.record-dialog.narrow { width: min(560px, calc(100vw - 28px)); }
.record-dialog::backdrop { background: #16231f80; }
.record-dialog form { display: flex; min-height: 100%; flex-direction: column; }
.record-dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 21px 13px; border-bottom: 1px solid var(--line); }
.record-dialog-header h2 { margin: 0; font-family: var(--serif); font-size: 23px; font-weight: 400; }
.dialog-close { width: 34px; height: 34px; border: 0; color: #60716a; background: transparent; cursor: pointer; font-size: 24px; }
.record-tabs { display: flex; gap: 2px; padding: 0 15px; border-bottom: 1px solid var(--line); background: #f5f7f6; }
.record-tabs button { min-height: 39px; padding: 0 15px; border: 0; border-bottom: 2px solid transparent; color: #596761; background: transparent; cursor: pointer; font-size: 12px; }
.record-tabs button[aria-selected='true'] { color: var(--teal-dark); border-bottom-color: var(--teal); background: #fff; font-weight: 700; }
.record-panel { padding: 19px 22px; }
.record-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 17px; }
.record-grid[hidden] { display: none; }
.person-field[hidden], .company-field[hidden] { display: none; }
.span-two { grid-column: 1 / -1; }
.check-field { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 35px; }
.check-field input { width: 15px; min-height: 15px; height: 15px; accent-color: var(--green); }
.privacy-note { margin: 6px 0 0; padding: 10px 12px; border-left: 3px solid #cf9a43; color: #695b42; background: #faf6ed; font-size: 11px; line-height: 1.5; }
.record-dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: end; gap: 9px; padding: 12px 20px; border-top: 1px solid var(--line); background: #f8faf9; }
.record-dialog input:disabled, .record-dialog select:disabled { color: #89938e; background: #f0f2f1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; width: min(680px, 100%); padding: 3px 0 11px; }
label { display: grid; gap: 5px; color: #4e5d56; font-size: 11px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 35px; border: 1px solid #cfd8d0; border-radius: 2px; padding: 7px 9px; color: var(--ink); background: #fff; font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8eae9d; outline-offset: 1px; border-color: var(--green); }
textarea { resize: vertical; }
.wide { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 15px; }
.checks label, .confirm-check { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.checks input, .confirm-check input { width: 15px; min-height: 15px; height: 15px; accent-color: var(--green); }
.import-form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.import-form label { min-width: min(280px, 100%); }
.import-form input[type='file'] { border: 0; padding: 3px 0; }
.hint { max-width: 720px; margin-bottom: 8px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
th { padding: 10px 11px; color: #5b6863; border-bottom: 1px solid #dfe5e2; background: #f8f9f9; font-size: 10px; font-weight: 700; white-space: nowrap; }
td { padding: 10px 11px; border-bottom: 1px solid #e8ecea; color: #46534e; }
tbody tr:nth-child(even) { background: #f7f8f8; }
tbody tr:hover { background: #eef7f4; }
.editable-row { cursor: pointer; }
.name-cell { color: var(--ink); font-weight: 600; }
.contact-avatar { width: 32px; height: 32px; margin-right: 8px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.import-review { max-width: 1200px; margin: 28px auto; }
.possible-duplicate td { background: #fff2df; }
.import-review-actions { justify-content: flex-end; margin-top: 16px; }
.user-create-form { display: grid; grid-template-columns: minmax(200px, 2fr) minmax(150px, 1fr) auto; align-items: end; gap: 12px; max-width: 1000px; }
.user-role-form { display: flex; align-items: center; gap: 5px; }
.user-role-form select { min-width: 110px; }
@media (max-width: 760px) {
  .user-create-form { grid-template-columns: 1fr; }
}
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.row-action { padding: 3px 5px; border: 0; color: var(--teal-dark); background: transparent; cursor: pointer; font-size: 11px; }
.row-action:hover { text-decoration: underline; }
.row-action.danger { color: #a44736; }
td small { display: block; margin-top: 3px; color: var(--muted); }
.empty { padding: 24px 12px; color: var(--muted); text-align: center; }
.numeric { text-align: right; white-space: nowrap; }
.event-list { max-width: 900px; margin: 13px 0 0; padding: 0; list-style: none; }
.event-list li { align-items: center; display: flex; gap: 18px; padding: 13px 4px; border-bottom: 1px solid #e6eae4; }
.event-list time { min-width: 94px; color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.event-list strong, .event-list span { display: block; font-size: 13px; }
.event-list span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.status-pill { padding: 7px 10px; border-radius: 2px; color: #8a512f; background: #f7e9dd; font-size: 11px; font-weight: 600; }
.status-pill.ready { color: #245c49; background: #e2eee5; }
.mail-form { display: grid; gap: 13px; max-width: 700px; margin-top: 21px; }
.recipient-count { margin: -4px 0 0; color: var(--muted); font-size: 11px; }
.confirm-check { margin: 2px 0; color: #58665f; font-size: 11px; }
.notices { margin: 0 0 14px; }
.notice { margin: 0; padding: 10px 13px; border-left: 3px solid var(--green); background: #f2f7f4; font-size: 12px; }
.notice.error { border-color: var(--coral); background: #fbf3ef; }
footer { display: flex; justify-content: space-between; gap: 15px; padding: 13px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }

@media (max-width: 760px) {
  .identity-row { min-height: 49px; padding: 0 13px; }
  .module-nav { min-height: 43px; padding: 0 5px; }
  .module-tab { min-width: max-content; padding: 0 13px; font-size: 11px; }
  .app-main { padding: 12px 9px 35px; }
  .contacts-view { grid-template-columns: minmax(0, 1fr); }
  .accounting-layout { grid-template-columns: minmax(0, 1fr); }
  .account-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .account-tree { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .account-tree > details { grid-column: 1 / -1; }
  .finance-tabs { padding: 0 6px; }
  .finance-tab { min-height: 36px; padding: 0 9px; font-size: 11px; }
  .accounting-content .table-wrap { min-width: 0; }
  .group-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-title { min-height: 37px; }
  .group-nav { display: flex; min-width: 0; gap: 3px; overflow-x: auto; padding: 7px; }
  .group-link { flex: 0 0 auto; padding: 8px 9px; white-space: nowrap; }
  .view-content { padding: 15px 11px 22px; }
  .contacts-view > .view-content { padding: 0; }
  .view-toolbar { align-items: flex-start; padding: 12px; }
  h1 { font-size: 22px; }
  .toolbar-actions { width: 100%; }
  .action-menu[open] { flex-basis: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .record-panel { padding: 14px; }
  .record-grid { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .record-dialog-header { padding: 13px 15px; }
  .record-dialog-actions { padding: 10px 13px; }
  .checks { align-items: flex-start; flex-direction: column; }
  .summary-chip { font-size: 10px; }
  th, td { padding: 9px 8px; }
  footer { padding: 12px; }
}
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 4px 0 12px; }
.filter-bar label { display: grid; gap: 4px; font-size: 11px; font-weight: 600; color: var(--muted); }
.record-dialog.editing .create-only { display: none; }
.record-dialog select[multiple] { min-height: 110px; }
.record-dialog table { width: 100%; }
