.briefe-workspace {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  overflow: hidden;
  background: #f5f7fb;
  color: #1f2937;
  font-family: Arial, Helvetica, sans-serif;
}

.briewe-workspace *,
.briefe-workspace * {
  box-sizing: border-box;
}

.briefe-workspace.is-open {
  display: flex;
  flex-direction: column;
}

.briefe-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 12px 22px;
  border-bottom: 1px solid #dce4ee;
  background: #fff;
}

.briefe-header-main {
  min-width: 0;
}

.briefe-title {
  margin: 0;
  color: #063f6c;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
}

.briefe-subtitle {
  margin-top: 4px;
  color: #64748b;
  font-size: 13px;
}

.briefe-header-actions,
.briefe-editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.briefe-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #23384d;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.briefe-button:hover {
  border-color: #91a7bb;
  background: #f8fafc;
}

.briefe-button:disabled {
  cursor: default;
  opacity: .55;
}

.briefe-button-primary {
  border-color: #063f6c;
  background: #063f6c;
  color: #fff;
}

.briefe-button-primary:hover {
  border-color: #063f6c;
  background: #0a4f83;
}

.briefe-button-accent {
  border-color: #cc7588;
  background: #fff7f9;
  color: #8f3348;
}

.briefe-button .material-icons {
  font-size: 18px;
}

.briefe-main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 295px minmax(0, 1fr);
}

.briefe-sidebar {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #dce4ee;
  background: #fff;
}

.briefe-search-wrap {
  padding: 14px;
  border-bottom: 1px solid #edf1f5;
}

.briefe-search {
  width: 100%;
  height: 38px;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  outline: 0;
  background: #fff;
  color: #1f2937;
  font: inherit;
  font-size: 13px;
}

.briefe-search:focus,
.briefe-field input:focus,
.briefe-field select:focus,
.briefe-recipient-input:focus {
  border-color: #4f7899;
  box-shadow: 0 0 0 2px rgba(6, 63, 108, .08);
}

.briefe-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.briefe-list-empty {
  padding: 24px 14px;
  color: #64748b;
  font-size: 13px;
  text-align: center;
}

.briefe-list-item {
  width: 100%;
  margin: 0 0 5px;
  padding: 11px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.briefe-list-item:hover {
  background: #f4f7fa;
}

.briefe-list-item.is-active {
  border-color: #b8cad9;
  background: #edf4f8;
}

.briefe-list-subject {
  overflow: hidden;
  color: #1f3347;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.briefe-list-recipient {
  overflow: hidden;
  margin-top: 4px;
  color: #52677a;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.briefe-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  color: #7a8794;
  font-size: 11px;
}

.briefe-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2f6;
  color: #52677a;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.briefe-status.is-archived {
  background: #edf7f0;
  color: #2e6c43;
}

.briefe-content {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.briefe-empty-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
}

.briefe-empty-card {
  max-width: 520px;
  padding: 34px;
  border: 1px solid #dce4ee;
  border-radius: 12px;
  background: #fff;
  text-align: center;
  box-shadow: 0 8px 24px rgba(48, 68, 87, .06);
}

.briefe-empty-icon {
  color: #6c8aa1;
  font-size: 42px;
}

.briefe-empty-card h2 {
  margin: 10px 0 8px;
  color: #183a58;
  font-size: 20px;
}

.briefe-empty-card p {
  margin: 0 0 18px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.briefe-editor {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

.briefe-meta-panel {
  flex: 0 0 auto;
  padding: 12px 16px 10px;
  border-bottom: 1px solid #dce4ee;
  background: #fff;
}

.briefe-meta-grid {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(220px, 1.35fr) minmax(150px, .65fr) minmax(220px, 1fr);
  gap: 10px;
  align-items: end;
}

.briefe-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #52677a;
  font-size: 11px;
  font-weight: 700;
}

.briefe-field input,
.briefe-field select,
.briefe-recipient-input {
  width: 100%;
  height: 36px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: #1f2937;
  font: inherit;
  font-size: 13px;
  font-weight: 400;
}

.briefe-recipient-wrap {
  position: relative;
}

.briefe-recipient-results {
  position: absolute;
  z-index: 90;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: none;
  max-height: 260px;
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(25, 48, 70, .16);
}

.briefe-recipient-results.is-open {
  display: block;
}

.briefe-recipient-option {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid #eef2f6;
  background: #fff;
  color: #1f2937;
  text-align: left;
  cursor: pointer;
}

.briefe-recipient-option:last-child {
  border-bottom: 0;
}

.briefe-recipient-option:hover {
  background: #f4f7fa;
}

.briefe-recipient-option strong {
  display: block;
  font-size: 12.5px;
}

.briefe-recipient-option span {
  display: block;
  margin-top: 2px;
  color: #64748b;
  font-size: 11px;
}

.briefe-toolbar-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 48px;
  padding: 6px 16px;
  border-bottom: 1px solid #dce4ee;
  background: #fdfefe;
}

.briefe-toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding-right: 7px;
  margin-right: 3px;
  border-right: 1px solid #e3e9ef;
}

.briefe-toolbar-group:last-child {
  border-right: 0;
}

.briefe-tool {
  display: inline-flex;
  width: 32px;
  height: 31px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #334b61;
  cursor: pointer;
}

.briefe-tool:hover,
.briefe-tool.is-active {
  border-color: #c9d7e2;
  background: #edf4f8;
}

.briefe-tool .material-icons {
  font-size: 19px;
}

.briefe-format-select,
.briefe-placeholder-select {
  height: 31px;
  padding: 4px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: #334b61;
  font-size: 12px;
}

.briefe-placeholder-select {
  max-width: 210px;
}

.briefe-mode-switch {
  margin-left: auto;
  display: inline-flex;
  padding: 2px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #f3f6f9;
}

.briefe-mode-button {
  min-height: 28px;
  padding: 4px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #52677a;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.briefe-mode-button.is-active {
  background: #fff;
  color: #063f6c;
  box-shadow: 0 1px 3px rgba(45, 65, 84, .15);
}

.briefe-document-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 24px 26px 50px;
  background: #e8edf2;
}

.briefe-page-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.briefe-page,
.briefe-preview-page {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 20mm 20mm 20mm 25mm;
  background: #fff;
  color: #111827;
  box-shadow: 0 2px 10px rgba(20, 38, 55, .16);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10.5pt;
}

.briefe-editor-page {
  min-height: 297mm;
}

.briefe-letter-sender {
  display: inline-block;
  min-width: 85mm;
  padding-bottom: 1mm;
  border-bottom: .2mm solid #cbd5e1;
  color: #64748b;
  font-size: 7.5pt;
}

.briefe-letter-recipient {
  min-height: 36mm;
  margin-top: 3mm;
  line-height: 1.38;
}

.briefe-letter-date {
  margin: 0 0 9mm;
  text-align: right;
}

.briefe-letter-subject {
  margin: 0 0 7mm;
  font-size: 11.5pt;
  font-weight: 700;
  line-height: 1.35;
}

.briefe-rich-editor,
.briefe-preview-content {
  min-height: 115mm;
  outline: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.briefe-rich-editor:empty::before {
  content: "Brieftext eingeben …";
  color: #9aa7b4;
}

.briefe-rich-editor p,
.briefe-preview-content p {
  margin: 0 0 4mm;
}

.briefe-rich-editor ul,
.briefe-rich-editor ol,
.briefe-preview-content ul,
.briefe-preview-content ol {
  margin: 0 0 4mm;
  padding-left: 7mm;
}

.briefe-rich-editor h1,
.briefe-preview-content h1 {
  margin: 0 0 5mm;
  font-size: 15pt;
}

.briefe-rich-editor h2,
.briefe-preview-content h2 {
  margin: 0 0 4mm;
  font-size: 13pt;
}

.briefe-rich-editor h3,
.briefe-preview-content h3 {
  margin: 0 0 3mm;
  font-size: 11.5pt;
}

.briefe-preview-page.is-following {
  padding-top: 25mm;
}

.briefe-message {
  display: none;
  margin: 0 16px 9px;
  padding: 9px 11px;
  border: 1px solid #d7e0e8;
  border-radius: 6px;
  background: #f7fafc;
  color: #42576a;
  font-size: 12px;
}

.briefe-message.is-visible {
  display: block;
}

.briefe-message.is-error {
  border-color: #e5b2bd;
  background: #fff4f6;
  color: #8a2940;
}

.briefe-message.is-success {
  border-color: #b9dac3;
  background: #f1faf4;
  color: #2f6a43;
}

.briefe-modal {
  position: fixed;
  z-index: 100120;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(19, 36, 53, .42);
}

.briefe-modal.is-open {
  display: flex;
}

.briefe-modal-dialog {
  width: min(720px, 96vw);
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(18, 35, 52, .26);
}

.briefe-modal-header,
.briefe-modal-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 17px;
  border-bottom: 1px solid #e3e9ef;
}

.briefe-modal-footer {
  justify-content: flex-end;
  border-top: 1px solid #e3e9ef;
  border-bottom: 0;
}

.briefe-modal-title {
  color: #183a58;
  font-size: 17px;
  font-weight: 700;
}

.briefe-modal-body {
  min-height: 0;
  overflow: auto;
  padding: 16px 17px;
}

.briefe-template-list {
  margin-top: 14px;
  border-top: 1px solid #edf1f5;
}

.briefe-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f5;
}

.briefe-template-name {
  overflow: hidden;
  color: #273f55;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.briefe-template-actions {
  display: flex;
  gap: 6px;
}

.briefe-icon-button {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #d6dee7;
  border-radius: 6px;
  background: #fff;
  color: #52677a;
  cursor: pointer;
}

.briefe-icon-button .material-icons {
  font-size: 17px;
}

.briefe-saving-indicator {
  min-width: 88px;
  color: #64748b;
  font-size: 11px;
  text-align: right;
}

.briefe-navigation-group .material-icons {
  font-size: 20px;
}

@media (max-width: 1100px) {
  .briefe-main {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .briefe-meta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .briefe-page,
  .briefe-preview-page {
    transform-origin: top center;
  }
}

@media (max-width: 820px) {
  .briefe-main {
    grid-template-columns: 1fr;
  }

  .briefe-sidebar {
    display: none;
  }

  .briefe-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .briefe-title {
    font-size: 20px;
  }

  .briefe-meta-panel,
  .briefe-toolbar-row {
    padding-left: 10px;
    padding-right: 10px;
  }

  .briefe-toolbar-row {
    overflow-x: auto;
  }

  .briefe-document-stage {
    padding: 14px 8px 40px;
  }
}


/* Briefe: gleiche visuelle Hierarchie wie Beleg- und Stammdatenbereiche. */
.briefe-header {
  min-height: 78px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--kk-header-border, rgba(6, 63, 108, .14));
  background: var(--kk-header-surface, #f3f6f8);
  box-shadow: var(--kk-header-shadow, 0 5px 14px rgba(6, 63, 108, .14));
}

.briefe-header-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.briefe-header-titleblock {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.briefe-title {
  min-width: 0;
  max-width: min(620px, 48vw);
  padding-left: 8px;
  border-left: 3px solid var(--kk-orange, #f28c18);
  color: var(--kk-blue, #063f6c);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.briefe-subtitle {
  margin: 0 0 0 11px;
  max-width: min(660px, 52vw);
  color: #64748b;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.briefe-back-button {
  flex: 0 0 auto;
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #cfd9e2;
  border-radius: 5px;
  background: #fff;
  color: var(--kk-blue, #063f6c);
  cursor: pointer;
}

.briefe-back-button:hover {
  border-color: rgba(6, 63, 108, .34);
  background: #fbfdff;
}

.briefe-back-button .material-icons { font-size: 19px; }

.briefe-overview {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.briefe-overview .briefe-search-wrap {
  padding: 0 0 14px;
  border: 0;
}

.briefe-overview .briefe-search {
  max-width: 520px;
}

.briefe-overview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 12px;
  padding: 0;
  overflow: visible;
}

.briefe-overview-card {
  min-height: 112px;
  margin: 0;
  padding: 14px 15px;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(6, 63, 108, .05);
}

.briefe-overview-card:hover {
  border-color: #b8cad9;
  background: #fbfdff;
  box-shadow: 0 4px 12px rgba(6, 63, 108, .09);
}

.briefe-meta-panel {
  background: #fff;
}

@media (max-width: 820px) {
  .briefe-header {
    min-height: 68px;
    padding: 10px 12px;
  }
  .briefe-title,
  .briefe-subtitle {
    max-width: calc(100vw - 150px);
  }
  .briefe-overview {
    padding: 12px;
  }
  .briefe-overview-list {
    grid-template-columns: 1fr;
  }
}


/* Briefe: Listenuebersicht analog zu den uebrigen Office-Uebersichten. */
.briefe-header-search {
  width: min(360px, 34vw);
  height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid #cfd9e2;
  border-radius: 6px;
  background: #fff;
}

.briefe-header-search .material-icons {
  flex: 0 0 auto;
  color: #7890a4;
  font-size: 18px;
}

.briefe-header-search .briefe-search {
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.briefe-header-search .briefe-search:focus {
  border: 0;
  box-shadow: none;
}

.briefe-header-add {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--kk-blue, #063f6c);
  border-radius: 6px;
  background: var(--kk-blue, #063f6c);
  color: #fff;
  cursor: pointer;
}

.briefe-header-add:hover {
  background: var(--kk-blue-dark, #052f50);
  border-color: var(--kk-blue-dark, #052f50);
}

.briefe-header-add .material-icons { font-size: 20px; }

.briefe-overview {
  padding: 14px 18px 22px;
}

.briefe-overview-list {
  display: block;
  padding: 0;
  overflow: visible;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  background: #fff;
}

.briefe-overview-row {
  min-height: 66px;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 105px 24px;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid #e7edf2;
  border-radius: 0;
  background: #fff;
}

.briefe-overview-row:first-child { border-radius: 8px 8px 0 0; }
.briefe-overview-row:last-child {
  border-bottom: 0;
  border-radius: 0 0 8px 8px;
}

.briefe-overview-row:hover {
  background: #f7fafc;
}

.briefe-row-main { min-width: 0; }
.briefe-overview-row .briefe-list-recipient { margin-top: 3px; }

.briefe-row-date {
  color: #52677a;
  font-size: 12px;
  text-align: right;
}

.briefe-row-status {
  display: flex;
  justify-content: flex-end;
}

.briefe-row-chevron {
  color: #91a2b1;
  font-size: 20px;
}

@media (max-width: 820px) {
  .briefe-header-search {
    width: min(250px, 45vw);
  }
  .briefe-overview {
    padding: 10px 12px 18px;
  }
  .briefe-overview-row {
    grid-template-columns: minmax(0, 1fr) 24px;
  }
  .briefe-row-date,
  .briefe-row-status {
    display: none;
  }
}


/* Briefe: Such-/Neu-Zeile unterhalb des Seitenkopfs wie in der Adressenuebersicht. */
.briefe-overview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.briefe-overview-search {
  flex: 1 1 auto;
  max-width: 520px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid #cfd9e2;
  border-radius: 6px;
  background: #fff;
}

.briefe-overview-search .material-icons {
  flex: 0 0 auto;
  color: #7890a4;
  font-size: 18px;
}

.briefe-overview-search .briefe-search {
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.briefe-overview-search .briefe-search:focus {
  border: 0;
  box-shadow: none;
}

.briefe-header-main > .briefe-title {
  margin-left: 0;
}

@media (max-width: 820px) {
  .briefe-overview-search {
    max-width: none;
  }
}


/* Briefe: Headeraufbau wie Adressen – Titel oben, Werkzeugzeile darunter. */
.briefe-workspace:not(:has(.briefe-content[style*="display: block"])) .briefe-header {
  align-items: stretch;
}

.briefe-workspace:not(:has(.briefe-content[style*="display: block"])) .briefe-header-main {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.briefe-header-toolbar {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.briefe-header-toolbar .briefe-overview-search {
  flex: 1 1 auto;
  max-width: none;
}

.briefe-overview-menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.briefe-overview-menu-button {
  width: auto;
  min-width: 0;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 12px;
  border: 1px solid #cfd9e2;
  border-radius: 5px;
  background: #fff;
  color: var(--kk-blue, #063f6c);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.briefe-overview-menu-button:hover {
  background: rgba(6, 63, 108, .07);
}

.briefe-overview-menu-button .material-icons {
  font-size: 18px;
}

.briefe-overview-menu-popup {
  position: absolute;
  z-index: 120;
  top: calc(100% + 6px);
  right: 0;
  display: none;
  min-width: 190px;
  padding: 5px;
  border: 1px solid #d7e0e8;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 38, 58, .16);
}

.briefe-overview-menu-popup.is-open {
  display: block;
}

.briefe-overview-menu-popup button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #334b61;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.briefe-overview-menu-popup button:hover {
  background: #f2f6f9;
}

.briefe-overview-menu-popup .material-icons {
  color: #607d94;
  font-size: 18px;
}

.briefe-overview {
  padding-top: 14px;
}

@media (max-width: 820px) {
  .briefe-header-toolbar {
    gap: 6px;
  }
}


/* Gemeinsames Dokumentlayout: Briefpapier liegt hinter allen Layoutelementen. */
.briefe-layout-letterhead {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 210mm;
  height: 297mm;
  object-fit: fill;
  pointer-events: none;
}

.briefe-layout-element,
.briefe-rich-editor,
.briefe-preview-content {
  z-index: 2;
}

.briefe-page:has(.briefe-layout-letterhead),
.briefe-preview-page:has(.briefe-layout-letterhead) {
  padding: 0;
}


/* Briefbearbeitung kompakt wie Adresse bearbeiten; Dokumentbereich scrollt separat. */
.briefe-content[style*="display: block"] {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.briefe-editor {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.briefe-meta-panel {
  position: relative;
  padding: 8px 44px 8px 16px;
}

.briefe-meta-body {
  display: block;
}

.briefe-meta-panel.is-collapsed {
  min-height: 34px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.briefe-meta-panel.is-collapsed .briefe-meta-body {
  display: none;
}

.briefe-meta-toggle {
  position: absolute;
  z-index: 3;
  top: 6px;
  right: 10px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #cfd9e2;
  border-radius: 5px;
  background: #fff;
  color: var(--kk-blue, #063f6c);
  cursor: pointer;
}

.briefe-meta-toggle:hover {
  background: #f7fafc;
}

.briefe-meta-toggle .material-icons {
  font-size: 19px;
}

.briefe-meta-grid {
  grid-template-columns: minmax(150px,.72fr) minmax(260px,1.25fr) minmax(130px,.58fr) minmax(190px,.9fr) minmax(170px,.75fr);
  gap: 7px 10px;
}

.briefe-field {
  gap: 3px;
  font-size: 11px;
}

.briefe-field input,
.briefe-field select,
.briefe-recipient-input {
  height: 32px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
}

.briefe-meta-panel .briefe-meta-grid + div {
  margin-top: 6px !important;
}

.briefe-toolbar-row {
  min-height: 44px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.briefe-document-stage {
  flex: 1 1 0;
  height: 0;
  min-height: 0;
  overflow: auto !important;
  overscroll-behavior: contain;
}

.briefe-page-stack {
  min-height: max-content;
}

@media (max-width: 1250px) {
  .briefe-meta-grid {
    grid-template-columns: repeat(3, minmax(0,1fr));
  }
}

@media (max-width: 820px) {
  .briefe-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}


/* Brief: Betreff und Richtext bilden gemeinsam den dynamischen Inhaltsfluss. */
.briefe-dynamic-content {
  z-index: 2;
  overflow: visible;
  line-height: 1.5;
}

.briefe-document-subject {
  margin: 0 0 7mm;
  font-size: 11.5pt;
  font-weight: 700;
  line-height: 1.35;
  min-height: 1.35em;
}

.briefe-dynamic-content .briefe-rich-editor,
.briefe-dynamic-content .briefe-preview-content {
  position: static !important;
  width: auto !important;
  min-height: 0;
  z-index: auto;
}


.briefe-unsaved-overlay {
  z-index: 10050;
}

.briefe-unsaved-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: 440px;
}

.briefe-unsaved-question {
  margin: 4px 0;
  color: #253b4d;
  font-size: 14px;
  line-height: 1.45;
}


/* Eigenstaendiger Speichern/Verwerfen-Dialog fuer Briefnavigation. */
.briefe-unsaved-overlay {
  position: fixed !important;
  z-index: 2147483000 !important;
  inset: 0 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, .42);
}

.briefe-unsaved-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: 440px;
  overflow: hidden;
  border: 1px solid #d7e0e8;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(15, 23, 42, .28);
}

.briefe-unsaved-header {
  padding: 15px 18px 12px;
  border-bottom: 1px solid #e5ebf0;
}

.briefe-unsaved-title {
  color: var(--kk-blue, #063f6c);
  font-size: 16px;
  font-weight: 700;
}

.briefe-unsaved-body {
  padding: 20px 18px;
  color: #253b4d;
  font-size: 14px;
  line-height: 1.45;
}

.briefe-unsaved-body p {
  margin: 0;
}

.briefe-unsaved-footer {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 18px 15px;
  border-top: 1px solid #e5ebf0;
  background: #f8fafc;
}


.briefe-project-name {
  margin-bottom: 4mm;
  font-weight: 600;
}

.briefe-project-site {
  margin-bottom: 4mm;
  line-height: 1.4;
}


/* Inline-Bildbearbeitung im Briefeditor. */
.briefe-rich-editor img {
  max-width: 100%;
  height: auto;
  cursor: pointer;
}

.briefe-rich-editor img.is-selected {
  outline: 2px solid var(--kk-blue, #063f6c);
  outline-offset: 2px;
}

.briefe-image-tools {
  position: fixed;
  z-index: 2147482000;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid #cfd9e2;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 38, 58, .18);
}

.briefe-image-tools button {
  min-width: 30px;
  height: 29px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #334b61;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.briefe-image-tools button:hover {
  background: #eef4f8;
  color: var(--kk-blue, #063f6c);
}

.briefe-image-tools .material-icons {
  font-size: 18px;
}

.briefe-image-tools-separator {
  width: 1px;
  height: 20px;
  margin: 0 2px;
  background: #dce4ea;
}

.briefe-image-resize-handle {
  position: fixed;
  z-index: 2147482100;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: var(--kk-blue, #063f6c);
  box-shadow: 0 1px 4px rgba(15, 38, 58, .25);
  cursor: nwse-resize;
  touch-action: none;
}


.briefe-image-wrap-side {
  min-width: 10px;
  color: #64748b;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.briefe-rich-editor::after,
.briefe-preview-content::after {
  display: block;
  clear: both;
  content: "";
}


.briefe-image-source-menu{position:fixed;z-index:2147482500;min-width:220px;padding:5px;border:1px solid #d7e0e8;border-radius:7px;background:#fff;box-shadow:0 8px 24px rgba(15,38,58,.18)}
.briefe-image-source-menu button{width:100%;display:flex;align-items:center;gap:8px;padding:8px;border:0;border-radius:5px;background:transparent;text-align:left;cursor:pointer}
.briefe-image-source-menu button:hover{background:#eef4f8}
.briefe-image-source-menu .material-icons{font-size:18px}
.briefe-image-library-dialog{width:min(980px,calc(100vw - 40px));height:min(680px,calc(100vh - 40px));display:flex;flex-direction:column;border-radius:10px;background:#fff;box-shadow:0 22px 60px rgba(15,23,42,.28);overflow:hidden}
.briefe-image-library-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid #e5ebf0;color:var(--kk-blue,#063f6c)}
.briefe-image-library-header button{border:0;background:transparent;font-size:25px;cursor:pointer}
.briefe-image-library-search{padding:10px 14px;border-bottom:1px solid #e5ebf0}
.briefe-image-library-search input{width:100%;height:34px;padding:6px 9px;border:1px solid #cfd9e2;border-radius:5px}
.briefe-image-library-body{flex:1;min-height:0;display:grid;grid-template-columns:280px 1fr}
#briefeImageLibraryContexts{overflow:auto;padding:8px;border-right:1px solid #e5ebf0}
.briefe-image-library-context,.briefe-image-library-folder,.briefe-image-library-file{width:100%;display:flex;align-items:center;gap:8px;padding:9px;border:0;border-radius:5px;background:transparent;text-align:left;cursor:pointer}
.briefe-image-library-context:hover,.briefe-image-library-folder:hover,.briefe-image-library-file:hover{background:#eef4f8}
.briefe-image-library-body main{min-width:0;overflow:auto;padding:10px}
#briefeImageLibraryBreadcrumbs{padding:4px 8px 10px;color:#64748b;font-size:12px}


.briefe-image-library-controls{display:grid;grid-template-columns:minmax(280px,1.2fr) minmax(240px,1fr);gap:12px;padding:12px 14px;border-bottom:1px solid #e5ebf0}
.briefe-image-library-address-wrap{position:relative}
.briefe-image-library-address-results{position:absolute;z-index:4;top:calc(100% + 4px);left:0;right:0;display:none;max-height:260px;overflow:auto;padding:4px;border:1px solid #d7e0e8;border-radius:6px;background:#fff;box-shadow:0 8px 22px rgba(15,38,58,.16)}
.briefe-image-library-address-results.is-open{display:block}
.briefe-image-library-address{width:100%;display:flex;flex-direction:column;gap:2px;padding:8px;border:0;border-radius:4px;background:transparent;text-align:left;cursor:pointer}
.briefe-image-library-address:hover{background:#eef4f8}
.briefe-image-library-address span{color:#64748b;font-size:11px}
.briefe-image-library-location{padding:8px 14px;border-bottom:1px solid #e5ebf0;background:#f8fafc}
#briefeImageLibraryBreadcrumbs{display:flex;align-items:center;gap:6px;padding:0}
#briefeImageLibraryBreadcrumbs button{padding:3px 5px;border:0;background:transparent;color:var(--kk-blue,#063f6c);font-size:12px;cursor:pointer}
#briefeImageLibraryBreadcrumbs span{color:#94a3b8}
.briefe-image-library-files{flex:1;overflow:auto;padding:10px 14px}
.briefe-image-library-folder,.briefe-image-library-file{border-bottom:1px solid #edf1f4;border-radius:0}
.briefe-image-library-empty{padding:24px;color:#64748b;text-align:center}
@media(max-width:760px){.briefe-image-library-controls{grid-template-columns:1fr}}


/* Speichern-Rückfrage: bewusst identisch zu den Standard-Bearbeitungs-Overlays. */
.briefe-unsaved-overlay.address-edit-overlay {
  z-index: 100100 !important;
  display: flex !important;
}

.briefe-unsaved-dialog.address-edit-dialog {
  width: min(520px, calc(100vw - 40px));
}

.briefe-unsaved-body.address-edit-body {
  min-height: 74px;
}

.briefe-unsaved-hint {
  color: #64748b;
  font-size: 12px;
  line-height: 1.45;
}


/* Einheitlicher Control-Standard: identisch zu Adresse bearbeiten. */
.briefe-meta-panel .briefe-field {
  gap: 4px;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
}

.briefe-meta-panel .briefe-field input,
.briefe-meta-panel .briefe-field select,
.briefe-meta-panel .briefe-recipient-input,
.briefe-image-library-controls .briefe-field input,
.briefe-image-library-controls .briefe-field select {
  width: 100%;
  height: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  box-sizing: border-box;
  padding: 4px 8px !important;
  border: 1px solid var(--color-border, #cbd5e1) !important;
  border-radius: 2px !important;
  outline: none !important;
  background: #fafafa !important;
  color: #0f172a;
  box-shadow: none !important;
  font-family: inherit;
  font-size: 14px !important;
  font-weight: 400;
  line-height: 1.25;
}

.briefe-meta-panel .briefe-field input:focus,
.briefe-meta-panel .briefe-field select:focus,
.briefe-meta-panel .briefe-recipient-input:focus,
.briefe-image-library-controls .briefe-field input:focus,
.briefe-image-library-controls .briefe-field select:focus {
  border-color: var(--color-primary, #063f6c) !important;
  background: #fff !important;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-primary, #063f6c) 18%, transparent) !important;
}

.briefe-meta-panel .briefe-field input:disabled,
.briefe-meta-panel .briefe-field select:disabled,
.briefe-image-library-controls .briefe-field input:disabled,
.briefe-image-library-controls .briefe-field select:disabled {
  background: #f1f5f9 !important;
  color: #64748b;
  cursor: default;
}

/* Trefferlisten ebenfalls wie die vorhandenen Adress-Picker. */
.briefe-recipient-results,
.briefe-image-library-address-results {
  margin-top: 4px;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15,23,42,.12);
}

.briefe-recipient-option,
.briefe-image-library-address {
  min-height: 36px;
  padding: 7px 9px;
  border: 0;
  border-bottom: 1px solid #edf2f7;
  border-radius: 0;
  background: #fff;
}

.briefe-recipient-option:last-child,
.briefe-image-library-address:last-child {
  border-bottom: 0;
}

.briefe-recipient-option:hover,
.briefe-image-library-address:hover {
  background: #f8fafc;
}

/* Bild aus Dateiablage: Standard-Overlay statt eigenem Sonderdesign. */
.briefe-image-library-dialog {
  width: min(920px, calc(100vw - 40px));
  height: min(680px, calc(100vh - 40px));
  max-height: calc(100vh - 40px);
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15,23,42,.24);
}

.briefe-image-library-header {
  min-height: 55px;
  box-sizing: border-box;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  color: #0f172a;
}

.briefe-image-library-header strong {
  font-size: 17px;
  font-weight: 700;
}

.briefe-image-library-header button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #d5dee8;
  border-radius: 2px;
  background: #f8fafc;
  color: #334155;
  font-size: 21px;
  line-height: 1;
}

.briefe-image-library-controls {
  grid-template-columns: minmax(280px,1.2fr) minmax(240px,1fr);
  gap: 8px 12px;
  padding: 12px 16px 14px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
}

.briefe-image-library-controls .briefe-field {
  gap: 4px;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
}

.briefe-image-library-location {
  padding: 7px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
}

#briefeImageLibraryBreadcrumbs button {
  border-radius: 2px;
  color: var(--color-primary, #063f6c);
}

#briefeImageLibraryBreadcrumbs button:hover {
  background: #eef3f8;
}

.briefe-image-library-files {
  padding: 8px 16px 14px;
  background: #f8fafc;
}

.briefe-image-library-folder,
.briefe-image-library-file {
  min-height: 38px;
  padding: 7px 9px;
  border-bottom: 1px solid #edf2f7;
  border-radius: 0;
  background: #fff;
  color: #0f172a;
  font-size: 13px;
}

.briefe-image-library-folder:hover,
.briefe-image-library-file:hover {
  background: #f1f5f9;
}

@media(max-width:760px) {
  .briefe-image-library-controls {
    grid-template-columns: 1fr;
  }
}


/* Tabellen in der Brief-/Angebotstextverarbeitung */
.briefe-rich-editor table,
.briefe-dynamic-content table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 12px 0;
}
.briefe-rich-editor th,
.briefe-rich-editor td,
.briefe-dynamic-content th,
.briefe-dynamic-content td {
  border: 1px solid #c9d3dc;
  padding: 7px 9px;
  vertical-align: top;
  overflow-wrap: anywhere;
  min-width: 35px;
}
.briefe-rich-editor th,
.briefe-dynamic-content th {
  background: #f1f5f9;
  font-weight: 700;
}
.briefe-table-menu {
  position: fixed;
  z-index: 100080;
  width: 218px;
  max-height: 75vh;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid #dce4eb;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20, 42, 65, .19);
}
.briefe-table-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 10px;
  text-align: left;
  font-size: 13px;
  color: #17324d;
  border-radius: 6px;
  cursor: pointer;
}
.briefe-table-menu button:hover,
.briefe-table-menu button:focus-visible {
  background: #eaf2f8;
}


/* Tabellen-Dialoge: einheitliche Overlays statt Browser-Prompts. */
.briefe-table-menu-separator {
  height: 1px;
  margin: 5px 4px;
  background: #e5ebf0;
}

.briefe-table-menu button:disabled {
  color: #94a3b8;
  cursor: default;
}

.briefe-table-menu button:disabled:hover {
  background: transparent;
}

.briefe-table-menu button.is-danger {
  color: #a53434;
}

.briefe-table-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #d7e0e8;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(15, 23, 42, .28);
}

.briefe-table-format-dialog {
  width: min(760px, calc(100vw - 32px));
}

.briefe-table-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 18px 13px;
  border-bottom: 1px solid #e5ebf0;
  color: var(--kk-blue, #063f6c);
}

.briefe-table-dialog-header strong {
  display: block;
  font-size: 16px;
}

.briefe-table-dialog-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #52677a;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.briefe-table-dialog-close:hover {
  background: #eef4f8;
  color: var(--kk-blue, #063f6c);
}

.briefe-table-dialog-body {
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.briefe-table-insert-grid,
.briefe-table-format-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.briefe-table-insert-grid {
  margin-bottom: 16px;
}

.briefe-table-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #253b4d;
  font-size: 13px;
  cursor: pointer;
}

.briefe-table-check input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.briefe-table-format-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.briefe-table-format-section {
  min-width: 0;
  padding: 14px;
  border: 1px solid #dce4eb;
  border-radius: 8px;
  background: #fbfcfd;
}

.briefe-table-format-heading {
  margin-bottom: 10px;
  color: #17324d;
  font-size: 13px;
  font-weight: 700;
}

.briefe-color-control {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.briefe-color-control input[type="color"] {
  width: 46px;
  height: 36px;
  padding: 3px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.briefe-color-control input[type="text"] {
  width: 100%;
  height: 36px;
  padding: 7px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #253b4d;
  font: inherit;
  font-size: 13px;
}

.briefe-color-control input.is-invalid {
  border-color: #c24141;
  box-shadow: 0 0 0 2px rgba(194, 65, 65, .08);
}

.briefe-table-dialog-error {
  min-height: 18px;
  margin-top: 12px;
  color: #b42318;
  font-size: 12px;
  line-height: 1.4;
}

.briefe-table-dialog-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 15px;
  border-top: 1px solid #e5ebf0;
  background: #f8fafc;
}

.briefe-table-dialog-footer-spacer {
  flex: 1 1 auto;
}

@media (max-width: 680px) {
  .briefe-table-format-grid,
  .briefe-table-insert-grid,
  .briefe-table-format-fields {
    grid-template-columns: 1fr;
  }

  .briefe-table-dialog-footer {
    flex-wrap: wrap;
  }

  .briefe-table-dialog-footer-spacer {
    display: none;
  }
}
