.workspace-shell[hidden],
.staff-access[hidden] {
  display: none;
}

.staff-access {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.staff-sign-in-panel {
  width: min(100%, 26rem);
  padding: 1.75rem;
}

.staff-sign-in-panel form,
.staff-account {
  display: grid;
  gap: 0.75rem;
}

.staff-account {
  order: 1;
  font-size: 0.875rem;
}

.staff-sign-in-panel [role="status"] {
  min-height: 1.5em;
  margin: 0;
}

.personal-templates {
  margin-bottom: 1rem;
}

.personal-templates ul {
  display: grid;
  gap: 0.55rem;
  padding: 0;
}

.template-dialog fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.template-dialog textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  resize: vertical;
}

.existing-message-form fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

#company-message-editor .card-actions[hidden] {
  display: none;
}

.plain-message { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-mention-editor { position: relative; }
.message-mention-editor textarea,
.message-mention-mirror {
  box-sizing: border-box;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid transparent;
  font: inherit;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: scroll;
}
.message-mention-editor textarea {
  position: relative;
  display: block;
  width: 100%;
  border-color: var(--line, #78716c);
  border-radius: 0.5rem;
  color: transparent;
  caret-color: var(--text, CanvasText);
  -webkit-text-fill-color: transparent;
  background: transparent;
  resize: none;
}
.message-mention-mirror {
  position: absolute;
  inset: 0;
  pointer-events: none;
  scrollbar-color: transparent transparent;
}
.message-mention-mirror mark {
  color: inherit;
  background: color-mix(in srgb, #ff9765 32%, transparent);
  border-radius: 0.2em;
  box-shadow: 0 0 0 1px color-mix(in srgb, #ff9765 60%, transparent);
}
.message-mention-menu {
  position: absolute;
  z-index: 3;
  top: calc(100% + 0.25rem);
  left: 0;
  width: min(100%, 22rem);
  padding: 0.4rem;
  border: 1px solid var(--line, #78716c);
  border-radius: 0.5rem;
  background: var(--surface, Canvas);
  color: var(--text, CanvasText);
  box-shadow: 0 0.6rem 1.5rem #0004;
}
.message-mention-menu p { padding: 0.35rem 0.5rem; margin: 0; font-size: 0.85rem; }
.message-mention-menu [role=listbox] { position: relative; max-height: 15rem; overflow: auto; }
.message-mention-menu [role=option] { display: grid; padding: 0.45rem 0.55rem; border-radius: 0.3rem; cursor: pointer; }
.message-mention-menu [aria-selected=true],
.message-mention-menu [role=option]:hover { background: color-mix(in srgb, #ff9765 25%, transparent); }
.message-mention-menu [role=option] span { font-size: 0.8em; }


.template-settings [data-template-tab][aria-pressed="true"] {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

#company-message-editor,
.community-template {
  margin: 0.75rem 0;
}

.community-template summary {
  cursor: pointer;
  font-weight: 600;
}
.template-settings .template-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-bottom: 0.85rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.template-settings .template-tabs button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--surface-strong);
  border-color: var(--primary);
  outline: none;
}

.template-settings .template-tabs button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.template-card {
  padding: clamp(0.9rem, 2vw, 1.4rem);
  border: 1px solid var(--line);
  border-radius: 0.85rem;
}

.template-card + .template-card {
  margin-top: 1rem;
}

.template-card-heading,
.template-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.template-card-heading {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.template-card-heading h3,
.template-card-heading p {
  margin: 0;
}

.template-card-heading p,
.template-settings [role="status"] {
  color: var(--muted);
  font-size: 0.875rem;
}

.template-settings [role="status"]:empty {
  display: none;
}

.template-library {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(0, 2fr);
  gap: 1rem;
  align-items: start;
}

.template-library-sidebar {
  min-width: 0;
}

#company-message-picker {
  max-height: 19rem;
  overflow: auto;
}

#company-message-editor {
  margin: 0;
  min-width: 0;
}

#company-message-editor h4 {
  margin: 0 0 0.75rem;
}

.template-settings .personal-templates {
  margin-bottom: 0;
}

.template-settings .template-dialog form {
  max-width: 46rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--ui-subtle);
}

.template-settings .template-dialog textarea,
.template-toolbar select {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.template-toolbar .field {
  margin: 0;
}

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

  #company-message-picker {
    max-height: 12rem;
  }
}


.template-metadata {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  gap: 0.75rem;
  margin-block: 0.75rem;
}

.template-settings .template-dialog .message-mention-editor textarea {
  color: transparent;
  background: transparent;
  line-height: 1.55;
  padding: 0.75rem;
  resize: none;
}

.template-selection {
  padding: 0.65rem 0.85rem;
  background: var(--ui-subtle);
  border-radius: 0.55rem;
  justify-content: space-between;
}

.template-selection[hidden] {
  display: none;
}

.template-library-row {
  --tag-color: var(--muted);
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-inline-start: 3px solid color-mix(in srgb, var(--tag-color) 55%, var(--line));
  border-radius: 0.7rem;
  background: var(--surface);
}

.template-library-row[data-template-tag="clinic callback"] { --tag-color: #a95128; }
.template-library-row[data-template-tag="follow-up"] { --tag-color: #4d52a5; }
.template-library-row[data-template-tag="appointments"] { --tag-color: #217360; }
.template-library-row[data-template-tag="treatment information"] { --tag-color: #8a4272; }
.template-library-row[data-template-tag="financing"] { --tag-color: #84621d; }
[data-theme="dark"] .template-library-row[data-template-tag="clinic callback"] { --tag-color: #ffb68f; }
[data-theme="dark"] .template-library-row[data-template-tag="follow-up"] { --tag-color: #bec3ff; }
[data-theme="dark"] .template-library-row[data-template-tag="appointments"] { --tag-color: #9bdac5; }
[data-theme="dark"] .template-library-row[data-template-tag="treatment information"] { --tag-color: #eeb7d6; }
[data-theme="dark"] .template-library-row[data-template-tag="financing"] { --tag-color: #ebcc82; }

.template-library-row:hover,
.template-library-row:has(details[open]) { background: var(--ui-subtle); }

.template-library-row > input { margin: 1rem 0 0 0.25rem; }
.template-library-row > .template-actions-trigger { margin-block-start: 0.35rem; }

.template-row-preview {
  flex: 1;
  min-width: 0;
}

.template-row-preview summary {
  display: grid;
  grid-template-columns: 0.55rem minmax(0, 1fr);
  align-items: center;
  gap: 0.25rem 0.7rem;
  min-height: 3rem;
  padding: 0.55rem 0.3rem;
  list-style: none;
  cursor: pointer;
}
.template-row-preview summary::-webkit-details-marker { display: none; }
.template-row-preview summary::before {
  content: "";
  width: 0.38rem;
  height: 0.38rem;
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
}
.template-row-preview[open] summary::before { transform: rotate(45deg); }
.template-row-title { overflow-wrap: anywhere; font-weight: 600; }
.template-row-metadata {
  grid-column: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.65rem;
  font-size: 0.75rem;
}
.template-row-clinic { color: var(--muted); }
.template-row-tag {
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tag-color) 13%, var(--surface));
  color: var(--tag-color);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.template-row-reading {
  margin: 0.2rem 0 0.5rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
}
.template-row-reading .plain-message {
  max-width: 76ch;
  margin: 0;
  color: var(--ui-body);
  line-height: 1.65;
}

.template-icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}
.template-icon-button svg { width: 1rem; height: 1rem; }

.template-row-actions {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 10.5rem;
  padding: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 24px #0003;
}

.template-row-actions button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0.35rem;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.template-row-actions button:hover,
.template-row-actions button:focus-visible,
.community-library-card:hover {
  background: var(--ui-subtle);
}

.template-dialog {
  width: min(44rem, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.35rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  color: var(--text);
  background: var(--surface);
}

.template-dialog::backdrop {
  background: #0008;
}

.template-dialog h4 {
  margin: 0 0 1rem;
}

.community-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 0.75rem;
}

.community-library-card {
  display: grid;
  justify-items: start;
  gap: 0.35rem;
  padding: 1rem;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  font: inherit;
  cursor: pointer;
}

.community-library-card small {
  color: var(--muted);
}

.community-library-heading {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.community-library-heading h4 {
  margin: 0;
}
