:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #687482;
  --line: #d9dee5;
  --accent: #226c67;
  --accent-dark: #174d49;
  --danger: #a33a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

a {
  color: var(--accent-dark);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.brand-icon {
  display: block;
  width: 30px;
  height: 30px;
}

.mainnav {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  align-items: center;
}

.nav-menu {
  position: relative;
}

.nav-menu summary {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

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

.nav-menu summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.nav-menu[open] summary,
.nav-menu summary:hover {
  background: #eef2f4;
}

.nav-menu-items {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(31, 41, 51, 0.14);
}

.mainnav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.mainnav a:hover {
  background: #eef2f4;
}

.mainnav .muted {
  color: var(--muted);
}

.logout button,
.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.button.secondary,
button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.button.danger,
button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

.button.neutral-danger,
button.neutral-danger {
  border-color: #3f454d;
  background: #3f454d;
  color: #fff;
}

.button.paperless-action,
button.paperless-action {
  border-color: #b8d8bd;
  background: #e8f5e9;
  color: #174d24;
}

.button.carddav-action,
button.carddav-action {
  border-color: #b8d2ef;
  background: #e7f2ff;
  color: #143a63;
}

.button.success-action,
button.success-action {
  border-color: #b8d8bd;
  background: #e8f5e9;
  color: #174d24;
}

.button.paperless-action:hover,
button.paperless-action:hover {
  background: #d8eedc;
}

.button.success-action:hover,
button.success-action:hover {
  background: #d8eedc;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button svg,
button svg {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex: 0 0 auto;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

.icon-button svg {
  margin-right: 0;
}

.inline-icon {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  vertical-align: -3px;
}

.service-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  object-fit: contain;
  vertical-align: -3px;
}

.title-service-icon {
  width: 24px;
  height: 24px;
  vertical-align: -4px;
}

.about-icon {
  display: inline-block;
  width: 32px;
  height: 32px;
  margin-right: 10px;
  vertical-align: -7px;
}

.button .service-icon,
button .service-icon {
  margin-right: 8px;
}

.path-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.path-breadcrumbs a {
  padding: 2px 6px;
  border-radius: 5px;
  text-decoration: none;
}

.path-breadcrumbs a:hover {
  background: #eef2f4;
}

.pcloud-preview-panel {
  min-height: 70vh;
}

.pcloud-preview-frame {
  display: block;
  width: 100%;
  min-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.pcloud-preview-image {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  margin: 0 auto;
  object-fit: contain;
}

.docx-preview {
  max-width: 760px;
  min-height: 72vh;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  line-height: 1.55;
}

.attachment-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.attachment-source-row p,
.attachment-source-section p {
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(220px, 420px);
  gap: 16px;
  align-items: center;
  margin: 0 0 12px;
}

.attachment-source-section {
  margin-top: 12px;
}

.attachment-source-section[hidden] {
  display: none;
}

.attachment-results-scroll {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.attachment-results-scroll .data-table {
  border: 0;
}

.attachment-results-scroll .data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.pcloud-browser-scroll {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.pcloud-browser-scroll .data-table {
  border: 0;
}

.pcloud-browser-scroll .data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.scrollable-table {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.scrollable-table .data-table {
  border: 0;
}

.scrollable-table .data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.button-stack {
  display: grid;
  gap: 10px;
}

.button-stack .button {
  justify-content: flex-start;
  width: 100%;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.email-send-grid {
  display: grid;
  gap: 14px;
}

.email-field-row,
.email-send-at {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin: 0;
}

.email-field-row label,
.email-send-at label {
  color: var(--muted);
  font-weight: 700;
}

.email-send-form input,
.email-send-form select,
.email-send-form textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

.email-body-section {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

.email-body-section h2 {
  margin-bottom: 0;
}

.email-body-section textarea {
  min-height: 150px;
}

.email-send-actions {
  display: grid;
  grid-template-columns: max-content minmax(240px, 360px);
  gap: 18px;
  align-items: center;
  justify-content: start;
}

.ai-summary-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.ai-summary-generate-form {
  display: none;
}

.ai-summary-length {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.ai-summary-length select {
  width: auto;
  min-width: 120px;
  padding: 8px 28px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

.ai-summary-form {
  display: grid;
  gap: 10px;
}

.ai-summary-textarea {
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
  resize: vertical;
}

.ai-summary-meta {
  margin: 8px 0 0;
  font-size: 13px;
}

.email-send-at {
  grid-template-columns: 86px minmax(0, 1fr);
}

.compact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-actions form {
  margin: 0;
}

.compact-actions .button,
.compact-actions button {
  min-width: 108px;
}

.paperless-contact-create {
  display: grid;
  gap: 10px;
  margin: 12px 0 18px;
}

.paperless-contact-create p {
  margin: 0;
}

.toggle-stack {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.toggle-panel summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-panel summary.summary-with-action {
  justify-content: space-between;
}

.toggle-panel summary.summary-with-action .button {
  margin-left: auto;
  font-size: 16px;
  font-weight: 400;
}

.toggle-panel summary + * {
  margin-top: 14px;
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.panel,
.auth-panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.auth-panel,
.narrow {
  max-width: 620px;
}

.auth-logo {
  display: block;
  width: min(260px, 72vw);
  height: auto;
  margin: 0 0 18px;
}

.metrics,
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.dashboard-header {
  align-items: end;
}

.dashboard-header > div {
  display: grid;
  gap: 8px;
}

.dashboard-logo {
  display: block;
  width: min(260px, 72vw);
  height: auto;
}

.dashboard-alert-panel {
  margin-bottom: 18px;
  border-color: #ecd99b;
  background: #fffdf6;
}

.dashboard-alert-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.dashboard-alert-heading h2 {
  margin-bottom: 0;
}

.metrics article {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metrics span {
  display: block;
  font-size: 30px;
  font-weight: 700;
}

.placeholder,
.muted-text {
  color: var(--muted);
}

.danger-text {
  color: var(--danger);
}

.section-label {
  margin: 18px 0 8px;
  font-size: 15px;
}

.scheduled-panel + .scheduled-panel {
  margin-top: 18px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
}

.data-table th,
.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.data-table th {
  background: #eef2f4;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.pagination-status {
  color: var(--muted);
  font-weight: 700;
}

.button.disabled {
  opacity: 0.45;
  cursor: default;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  color: #1f2933;
  font-size: 13px;
  font-weight: 700;
}

.count-total {
  background: #eef0f3;
}

.count-incoming {
  background: #dcecff;
}

.count-outgoing {
  background: #eee4ff;
}

.style-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
}

.style-formal {
  background: #111827;
  color: #fff;
}

.style-informal {
  background: #e5e7eb;
  color: #1f2937;
}

.style-familiar {
  background: #dff6e8;
  color: #14532d;
}

.style-anonymous {
  background: #fff;
  border-color: #cbd5e1;
  color: #334155;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 9px;
  border: 1px solid #cfd8e3;
  border-radius: 999px;
  background: #f4f8fb;
  color: #3c4a57;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.tag-badge:hover,
.tag-badge:focus-visible {
  text-decoration: none;
  background: #e8f1f7;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(31, 41, 51, 0.08);
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.7;
}

.status-open {
  background: #fff6db;
  border-color: #ecd99b;
  color: #6b5a24;
}

.status-terminal {
  background: #edf8f0;
  border-color: #c9dfd0;
  color: #315d3d;
}

.integration-status-badge {
  justify-self: start;
  margin-bottom: 8px;
}

.integration-status-ok {
  background: #e9f8ee;
  border-color: #bfe4c8;
  color: #236338;
}

.integration-status-checking {
  background: #f3f5f7;
  border-color: #d8dee6;
  color: #4b5563;
}

.integration-status-error {
  background: #fdeeee;
  border-color: #efc4c4;
  color: #8a2f2f;
}

.integration-status-inactive {
  background: #f5f5f4;
  border-color: #d6d3d1;
  color: #57534e;
}

.paperless-export-not_prepared {
  background: #f4f6f8;
  border-color: #d8dee6;
  color: #4b5563;
}

.paperless-export-ready {
  background: #eef6ff;
  border-color: #c7dff7;
  color: #2f5f8f;
}

.paperless-export-processing {
  background: #f5f1ff;
  border-color: #ddd2f7;
  color: #5b4b86;
}

.paperless-export-exported {
  background: #edf8f0;
  border-color: #c9dfd0;
  color: #315d3d;
}

.paperless-export-failed {
  background: #fff1f1;
  border-color: #f1c7c7;
  color: #8a3a3a;
}

.stack-title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: #1f2933;
}

.stack-title-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.timeline-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  display: grid;
  grid-template-columns: 34px 110px minmax(220px, 1fr) minmax(180px, 260px);
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.timeline-item:last-child {
  border-bottom: 0;
}

.timeline-date {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timeline-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  color: #1f2933;
}

.timeline-incoming {
  background: #dcecff;
}

.timeline-outgoing {
  background: #eee4ff;
}

.timeline-kind svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.timeline-body {
  min-width: 0;
}

.timeline-body a,
.timeline-party {
  overflow-wrap: anywhere;
}

.form p {
  display: grid;
  gap: 6px;
}

.form input,
.form select,
.form textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

.mobile-select-wrapper {
  display: block;
  position: relative;
}

.mobile-select-wrapper select[hidden] {
  display: none;
}

.mobile-select-trigger {
  width: 100%;
  min-height: 42px;
  padding: 9px 34px 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  text-align: left;
  position: relative;
}

.mobile-select-trigger::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
}

.mobile-select-menu {
  display: none;
  position: fixed;
  z-index: 1000;
  max-height: 45vh;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.mobile-select-menu.is-open {
  display: grid;
  gap: 2px;
}

.mobile-select-menu button {
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
}

.mobile-select-menu button[aria-selected="true"] {
  background: #eaf3f8;
}

.mobile-select-menu button:disabled {
  color: var(--muted);
}

.form textarea {
  min-height: 120px;
}

.layout-section {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.layout-section > summary {
  cursor: pointer;
  list-style: none;
  font-size: 17px;
  font-weight: 700;
}

.layout-section > summary::-webkit-details-marker {
  display: none;
}

.layout-section > summary::before {
  content: "▸";
  display: inline-block;
  width: 18px;
  color: var(--muted);
}

.layout-section[open] > summary::before {
  content: "▾";
}

.layout-section:first-of-type {
  margin-top: 12px;
}

.layout-section h3 {
  margin: 16px 0 0;
  font-size: 15px;
}

.layout-row {
  display: grid;
  gap: 10px;
  align-items: start;
}

.layout-row-general {
  grid-template-columns: minmax(160px, 1.2fr) minmax(180px, 1.4fr) minmax(120px, 0.8fr) minmax(150px, 1fr);
}

.layout-row-page {
  grid-template-columns: 110px repeat(4, minmax(90px, 120px));
}

.layout-row-element {
  grid-template-columns: repeat(4, minmax(90px, 120px));
}

.layout-row-footer {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.layout-row p,
.layout-section > p {
  margin: 0;
}

.layout-file-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.layout-file-field input[type="file"] {
  min-width: 0;
  flex: 1 1 220px;
}

.layout-file-field input[type="checkbox"] {
  width: auto;
  flex: 0 0 auto;
  padding: 0;
}

.layout-file-field label {
  width: auto;
}

.layout-row input[type="number"],
.layout-row input[type="text"],
.layout-row select {
  max-width: 130px;
}

.layout-row-general input[type="text"],
.layout-row-general select {
  max-width: none;
}

.layout-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.layout-checks label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--text);
}

.markdown-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #f8fafb;
}

.markdown-toolbar + textarea.markdown-editor {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.contact-filter {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.form-section:first-of-type {
  padding-top: 0;
}

.form-section:last-of-type {
  border-bottom: 0;
}

.form-section h2 {
  margin: 0;
  font-size: 17px;
}

.contact-form .form-section:first-of-type {
  gap: 8px;
}

.contact-form .form-section:first-of-type p {
  margin: 0;
}

.inline-formset {
  display: grid;
  gap: 10px;
}

.inline-form-row {
  display: grid;
  grid-template-columns: minmax(120px, 160px) minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.inline-form-row.is-deleted {
  opacity: 0.48;
}

.inline-form-row.address-form-row {
  grid-template-columns: minmax(100px, 140px) minmax(180px, 1.2fr) minmax(80px, 110px) minmax(140px, 1fr) minmax(120px, 160px) auto auto;
}

.inline-form-row p {
  margin: 0;
}

.checkbox-field {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 38px;
}

.add-formset-row {
  justify-self: start;
}

.integration-list {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.integration-item {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.integration-item:last-child {
  border-bottom: 0;
}

.breakable {
  overflow-wrap: anywhere;
}

.search-panel {
  margin-bottom: 18px;
}

.search-results {
  display: grid;
  gap: 10px;
}

.search-result-card {
  display: grid;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.search-result-card:last-child {
  border-bottom: 0;
}

.search-result-card h3,
.search-result-card p {
  margin: 0;
}

.search-result-card h3 {
  font-size: 16px;
}

.search-result-card p {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  color: var(--muted);
}

.search-result-card a {
  overflow-wrap: anywhere;
}

.template-form-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.placeholder-palette {
  position: sticky;
  top: 82px;
}

.placeholder-buttons {
  display: grid;
  gap: 8px;
}

.placeholder-token {
  justify-content: flex-start;
  width: 100%;
  min-height: 34px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 220px) minmax(100px, 140px) auto;
  gap: 10px;
  align-items: end;
}

.search-form p {
  margin: 0;
}

.search-errors {
  margin: 14px 0 0;
}

.search-errors p {
  margin: 0;
}

.search-errors p + p {
  margin-top: 4px;
}

.contact-search {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.contact-search p {
  margin: 0;
}

.template-choice-list {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
  margin-top: 10px;
}

.template-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.template-choice:hover {
  border-color: #b7c6d8;
  background: #f8fafc;
}

.template-choice.selected {
  border-color: #93b3d6;
  background: #edf5ff;
}

.template-choice small {
  color: var(--muted);
}

.initial-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.initial-filter a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.initial-filter a.active,
.initial-filter a:hover {
  border-color: var(--accent);
  background: #e9f3f1;
  color: var(--accent-dark);
}

.empty-state {
  text-align: center;
}

.contact-inline-search {
  display: grid;
  gap: 12px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

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

.result-item {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-item h3,
.result-item p {
  margin: 0;
}

.inline-note-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.inline-note-form textarea {
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}

.print-options-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}

.print-options-form label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.outgoing-print-options {
  display: flex !important;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  margin: 4px 0 12px;
}

.form .outgoing-print-options label {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 6px;
  align-items: center;
  width: auto;
  white-space: nowrap;
}

.form .outgoing-print-options input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
}

.outgoing-primary-case {
  display: grid;
  gap: 6px;
  margin: 0 0 18px;
}

.outgoing-primary-case select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

@media (max-width: 720px) {
  .contact-search {
    grid-template-columns: 1fr;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

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

  .layout-row,
  .layout-row-general,
  .layout-row-page,
  .layout-row-element,
  .layout-row-footer {
    grid-template-columns: 1fr;
  }

  .placeholder-palette {
    position: static;
  }

  .result-item {
    grid-template-columns: 1fr;
  }

  .inline-note-form {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 34px 1fr;
  }

  .timeline-date,
  .timeline-body,
  .timeline-party {
    grid-column: 2;
  }
}

.details {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 18px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
}

.scrollable-document-text {
  overflow: auto;
  max-height: 320px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  overflow-wrap: anywhere;
}

.signature-thumb {
  display: block;
  width: auto;
  max-width: 90px;
  max-height: 36px;
  object-fit: contain;
}

.identity-logo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.identity-logo-list li {
  display: grid;
  gap: 6px;
  min-width: 140px;
  color: var(--muted);
}

.identity-logo-preview {
  display: block;
  width: auto;
  max-width: 220px;
  height: auto;
  max-height: 80px;
  object-fit: contain;
}

.letter-signature {
  display: block;
  min-height: 22mm;
  margin-top: 12mm;
}

.letter-signature img {
  display: block;
  width: auto;
  max-width: 55mm;
  max-height: 18mm;
  object-fit: contain;
}

.list {
  padding-left: 18px;
}

.identity-contact-stack {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-title-row,
.identity-entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-title-row {
  margin-bottom: 14px;
}

.panel-title-row h2 {
  margin: 0;
}

.identity-entry-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.identity-entry-row {
  min-height: 38px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.identity-entry-row:last-child {
  border-bottom: 0;
}

.identity-entry-main {
  min-width: 0;
}

.identity-entry-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.identity-entry-actions .button {
  min-height: 30px;
  padding: 5px 10px;
}

@media (max-width: 700px) {
  .panel-title-row,
  .identity-entry-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

.dashboard-list {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.dashboard-list li {
  display: grid;
  gap: 5px;
  align-items: start;
  min-height: 34px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.dashboard-list li:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.dashboard-list a {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.dashboard-list span:not(.status-badge) {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.message {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #e8f2ef;
}

.message.error {
  background: #f8e7e7;
}

.secret {
  display: block;
  overflow-wrap: anywhere;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.code-list {
  columns: 2;
}

.state-good {
  color: #16633c;
  font-weight: 700;
}

.compact-details {
  grid-template-columns: 120px 1fr;
}

.ocr-text {
  overflow: auto;
  white-space: pre-wrap;
  max-height: 70vh;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.pdf-viewer {
  height: calc(100vh - 150px);
  min-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.pdf-preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.pdf-fallback {
  margin: 24px;
}

.pdf-mobile-open {
  display: none;
}

@media (max-width: 720px) {
  .pdf-mobile-open {
    display: block;
  }

  .pdf-viewer {
    height: 70vh;
    min-height: 420px;
  }

  .pdf-preview-panel {
    min-height: 420px;
  }
}

.settings-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.settings-grid p {
  margin-bottom: 0;
  color: var(--muted);
}

.letter-page {
  min-height: 297mm;
  max-width: 210mm;
  margin: 0 auto;
  padding: 28mm 24mm 24mm;
  border: 1px solid var(--line);
  background: #fff;
  color: #111827;
  break-after: page;
  page-break-after: always;
}

.letter-page:last-child {
  break-after: auto;
  page-break-after: auto;
}

.letter-page + .letter-page {
  margin-top: 20px;
}

.letter-page-layouted {
  isolation: isolate;
  position: relative;
  width: 210mm;
  max-width: none;
}

.letter-page-layouted .letter-logo {
  position: absolute;
  left: var(--letter-logo-left);
  top: var(--letter-logo-top);
  width: var(--letter-logo-width);
  height: var(--letter-logo-height, auto);
  object-fit: contain;
}

.letter-page-layouted .letter-logo-right {
  right: var(--letter-logo-right);
  left: auto;
}

.letter-page-layouted .letter-postage-stamp {
  position: absolute;
  left: var(--letter-postage-stamp-left);
  top: var(--letter-postage-stamp-top);
  width: var(--letter-postage-stamp-width);
  height: var(--letter-postage-stamp-height, auto);
  z-index: 0;
  object-fit: contain;
}

.letter-page-layouted .letter-page-mark {
  border-top: 0.25pt solid #6b7280;
  height: 0;
  left: var(--letter-page-mark-left);
  position: absolute;
  width: 5mm;
  z-index: 2;
}

.letter-page-layouted .letter-fold-mark {
  top: var(--letter-fold-mark-top);
}

.letter-page-layouted .letter-punch-mark {
  top: var(--letter-punch-mark-top);
}

.letter-sender,
.letter-address {
  display: grid;
  gap: 2px;
}

.letter-sender {
  min-height: 34mm;
  font-size: 13px;
}

.letter-address {
  min-height: 48mm;
}

.letter-sender-short-line {
  overflow: hidden;
  font-size: 6pt;
  line-height: 1.15;
  text-transform: uppercase;
  white-space: nowrap;
}

.letter-meta {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18mm;
}

.letter-reference-field {
  display: grid;
  gap: 2px;
  font-size: 8pt;
  line-height: 1.2;
}

.letter-reference-field strong {
  font-size: 7pt;
  font-weight: 600;
}

.letter-bank-details {
  display: grid;
  gap: 1px;
  font-size: 8pt;
  line-height: 1.2;
}

.letter-bank-details strong {
  font-size: 7pt;
  font-weight: 600;
}

.letter-subject {
  margin-bottom: 12mm;
  font-size: 18px;
}

.letter-body {
  line-height: 1.55;
  white-space: normal;
}

.letter-body p {
  margin: 0 0 10px;
}

.letter-body ul,
.letter-body ol {
  margin: 0 0 10px 22px;
  padding: 0;
}

.letter-body .text-left {
  text-align: left;
}

.letter-body .text-center {
  text-align: center;
}

.letter-body .text-right {
  text-align: right;
}

.letter-page-layouted .text-right {
  text-align: right;
}

.letter-body .text-justify {
  text-align: justify;
}

.letter-body.text-justify {
  text-align: justify;
}

.letter-page-layouted .letter-sender,
.letter-page-layouted .letter-address,
.letter-page-layouted .letter-sender-short-line,
.letter-page-layouted .letter-meta,
.letter-page-layouted .letter-reference-field,
.letter-page-layouted .letter-bank-details,
.letter-page-layouted .letter-subject,
.letter-page-layouted .letter-body,
.letter-page-layouted .letter-footer {
  position: absolute;
  z-index: 1;
  margin: 0;
}

.letter-page-layouted .letter-sender {
  left: var(--letter-sender-left);
  top: var(--letter-sender-top);
  width: var(--letter-sender-width);
  min-height: auto;
}

.letter-page-layouted .letter-sender.text-right {
  right: var(--letter-sender-right);
  left: auto;
}

.letter-page-layouted .letter-address {
  left: var(--letter-address-left);
  top: var(--letter-address-top);
  width: var(--letter-address-width);
  min-height: auto;
}

.letter-page-layouted .letter-sender-short-line {
  left: var(--letter-sender-short-line-left);
  top: var(--letter-sender-short-line-top);
  width: var(--letter-sender-short-line-width);
}

.letter-page-layouted .letter-meta {
  left: var(--letter-meta-left);
  top: var(--letter-meta-top);
}

.letter-page-layouted .letter-meta.text-right {
  right: var(--letter-meta-right);
  left: auto;
}

.letter-page-layouted .letter-recipient-reference {
  left: var(--letter-recipient-reference-left);
  top: var(--letter-recipient-reference-top);
  width: var(--letter-recipient-reference-width);
}

.letter-page-layouted .letter-incoming-date {
  left: var(--letter-incoming-date-left);
  top: var(--letter-incoming-date-top);
  width: var(--letter-incoming-date-width);
}

.letter-page-layouted .letter-sender-reference {
  left: var(--letter-sender-reference-left);
  top: var(--letter-sender-reference-top);
  width: var(--letter-sender-reference-width);
}

.letter-page-layouted .letter-sender-reference.text-right {
  right: var(--letter-sender-reference-right);
  left: auto;
}

.letter-page-layouted .letter-bank-details {
  left: var(--letter-bank-details-left);
  top: var(--letter-bank-details-top);
  width: var(--letter-bank-details-width);
}

.letter-page-layouted .letter-bank-details.text-right {
  right: var(--letter-bank-details-right);
  left: auto;
}

.letter-page-layouted .letter-subject {
  left: var(--letter-subject-left);
  top: var(--letter-subject-top);
}

.letter-page-layouted .letter-body {
  left: var(--letter-body-left);
  top: var(--letter-body-top);
  width: var(--letter-body-width);
}

.letter-page-layouted .letter-footer {
  left: var(--letter-footer-left);
  top: var(--letter-footer-top);
  display: grid;
  grid-template-columns: repeat(3, var(--letter-footer-column-width));
  width: var(--letter-footer-width);
  color: var(--muted);
  font-size: 13px;
}

.letter-footer-center {
  text-align: center;
}

.letter-footer-right {
  text-align: right;
}

.page-number::after {
  content: counter(page);
}

.page-count::after {
  content: counter(pages);
}

.pdf-preview-panel {
  padding: 0;
  height: calc(100vh - 210px);
  min-height: 620px;
  overflow: hidden;
}

.pdf-preview-panel .pdf-preview-frame {
  min-height: inherit;
}

@media (max-width: 720px) {
  .pdf-preview-panel {
    height: 70vh;
    min-height: 420px;
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .mainnav {
    flex-wrap: wrap;
    width: 100%;
  }

  .nav-menu {
    position: static;
  }

  .nav-menu-items {
    left: 14px;
    right: 14px;
    width: auto;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .details {
    grid-template-columns: 1fr;
  }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .messages,
  .print-controls {
    display: none;
  }

  .page {
    width: auto;
    margin: 0;
  }

  .letter-page {
    min-height: auto;
    max-width: none;
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  .letter-page + .letter-page {
    margin-top: 0;
  }
}
