:root {
  --ink: #152d3b;
  --muted: #647681;
  --line: #dce5e8;
  --paper: #f5f8f8;
  --teal: #008d8a;
  --magenta: #9a2f80;
}

.template-submenu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}
.template-submenu a {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}
.template-submenu a:hover,
.template-submenu a.active {
  border-color: var(--teal);
  background: #eaf8f7;
  color: var(--teal);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    15px/1.5 Inter,
    Segoe UI,
    Arial,
    sans-serif;
}
header {
  height: 76px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5vw;
}
.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
}
.brand span {
  font-weight: 400;
  color: var(--teal);
}
nav {
  display: flex;
  gap: 24px;
  align-items: center;
}
nav a,
nav button {
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}
nav form {
  margin: 0;
}
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 54px 24px;
  min-height: calc(100vh - 140px);
}
footer {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
}
.pagehead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
h1 {
  font-size: 36px;
  line-height: 1.1;
  margin: 8px 0;
}
.button,
button {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 16px;
  text-decoration: none;
}
.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.cards article,
.cards a,
.panel,
.tablewrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
}
.cards a {
  color: inherit;
  text-decoration: none;
}
.cards a:hover {
  border-color: var(--teal);
  box-shadow: 0 8px 24px #1231;
}

.actions {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: nowrap;
}
.actions form { display: inline-flex; margin: 0; }
.actions .button, .actions button { white-space: nowrap; padding: .55rem .8rem; }
.compact-table th, .compact-table td { padding: .75rem 1rem; }
.searchbar { display: flex; gap: .65rem; margin: 0 0 1rem; max-width: 620px; }
.searchbar input { flex: 1; }
.checklist { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: .65rem; }
.checkitem { display: flex; align-items: center; gap: .55rem; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; }
.cards span {
  color: var(--muted);
}
.cards strong {
  display: block;
  font-size: 40px;
  margin-top: 8px;
}
.login {
  max-width: 480px;
  margin: 7vh auto;
  background: #fff;
  border-top: 4px solid var(--magenta);
  padding: 42px;
  border-radius: 10px;
  box-shadow: 0 16px 50px #1232;
}
.login form,
label {
  display: grid;
  gap: 7px;
  margin-top: 18px;
}
input,
select,
textarea {
  width: 100%;
  border: 1px solid #b9c8cd;
  border-radius: 6px;
  padding: 11px;
  font: inherit;
  background: #fff;
}
.formgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.wide {
  grid-column: 1/-1;
}
.tablewrap {
  padding: 0;
  overflow: auto;
}
.ticket-list {
  min-width: 980px;
}
.ticket-list td {
  vertical-align: top;
}
.ticket-list .ticket-subject {
  max-width: none;
  overflow-wrap: normal;
}
.ticket-list .sender-cell {
  white-space: nowrap;
}
.ticket-list .sender-cell span {
  color: var(--muted);
  font-size: 13px;
}
.ticket-list small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}
.pagination form,
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pagination label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.pagination select {
  width: auto;
  padding: 7px 28px 7px 9px;
}
.pagination button,
.pagination .button {
  padding: 7px 10px;
  font-size: 13px;
}
.pagination .disabled {
  pointer-events: none;
  opacity: 0.45;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  text-align: left;
  padding: 15px;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}
.pill {
  border-radius: 20px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}
.critical {
  background: #fee2e2;
  color: #991b1b;
}
.high {
  background: #ffedd5;
  color: #9a3412;
}
.medium {
  background: #fef3c7;
  color: #92400e;
}
.low {
  background: #dbeafe;
  color: #1e40af;
}
.ticketgrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
}
.metadata dl {
  margin: 0;
}
.metadata dt {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 14px;
}
.metadata dd {
  margin: 3px 0;
}
.compact-metadata {
  align-self: start;
  position: sticky;
  top: 18px;
  font-size: 12px;
  padding: 16px;
}
.compact-metadata dt { font-size: 10px; margin-top: 10px; }
.compact-metadata dd { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.compact-metadata .pill { font-size: 10px; padding: 3px 7px; }
.metadata-divider { border-top: 1px solid var(--line); margin-top: 14px !important; height: 0; }
.event-delete { margin-top: 12px; display: flex; justify-content: flex-end; }
.event-delete .compact { padding: 6px 9px; font-size: 11px; }
.danger { color: #991b1b; border-color: #fecaca; background: #fff5f5; }
.event {
  background: #fff;
  border-left: 3px solid var(--teal);
  padding: 18px;
  margin-bottom: 12px;
}
.event > div:first-child {
  display: flex;
  justify-content: space-between;
}
.event > div:first-child > span {
  color: var(--muted);
  font-size: 12px;
}
.event .email-envelope {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
  gap: 4px;
  margin: 10px 0 14px;
  padding: 10px 12px;
  background: #f4f8f9;
  border-left: 3px solid var(--teal);
}
.event .email-envelope span { font-size: 13px; }
@media (max-width: 760px) {
  nav a {
    display: none;
  }
  .cards,
  .formgrid,
  .ticketgrid {
    grid-template-columns: 1fr;
  }
  .wide {
    grid-column: auto;
  }
  h1 {
    font-size: 29px;
  }
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }
  .pagination form,
  .pager {
    justify-content: space-between;
  }
}

.reply-form {
  display: grid;
  gap: 12px;
}
.editor-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px 7px 0 0;
}
.editor-toolbar button {
  min-width: 40px;
  padding: 7px 10px;
  background: #fff;
  cursor: pointer;
}
.editor-toolbar select {
  width: auto;
  padding: 7px;
}
.color-tool {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-weight: 800;
}
.color-tool input {
  width: 24px;
  height: 24px;
  padding: 1px;
  border: 0;
}
.highlight-tool {
  background: #fff9c4;
}
.rich-editor {
  min-height: 150px;
  padding: 14px;
  margin-top: -13px;
  background: #fff;
  border: 1px solid #b9c8cd;
  border-radius: 0 0 7px 7px;
  outline: none;
  overflow-wrap: anywhere;
}
.rich-editor:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px #008d8a22;
}
.rich-content {
  overflow-wrap: anywhere;
}
.rich-content img,
.rich-editor img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.recipient-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
}
.recipient-fields label {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 0;
}
.recipient-fields label input { margin: 0; }
.recipient-fields[hidden] {
  display: none;
}
.recipient-fields legend {
  padding: 0 7px;
  font-weight: 800;
}
.recipient-fields small {
  grid-column: auto;
  color: var(--muted);
}
.recipient-fields.disabled {
  opacity: 0.45;
}
.reply-contact-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  margin-top: 4px;
}
.reply-contact-panel[hidden] {
  display: none;
}
.reply-contact-panel h3 {
  margin: 0;
  font-size: 1rem;
}
.recipient-picker {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 16px;
  background: #f8fbfc;
}
.recipient-picker legend {
  padding: 0 7px;
  font-weight: 800;
}
.recipient-picker textarea {
  min-height: 52px;
}
.recipient-picker small {
  color: var(--muted);
}
.recipient-picker h3 {
  margin: 6px 0 0;
  font-size: 1rem;
}
.recipient-contact-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
  padding-right: 4px;
}
.recipient-empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}
.recipient-empty[hidden] {
  display: none;
}
.recipient-contact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.recipient-contact span:first-child {
  display: grid;
  min-width: 0;
}
.recipient-contact small {
  word-break: break-word;
}
.recipient-contact span:last-child {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.recipient-contact[hidden] {
  display: none;
}
.ticket-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.ticket-tabs button { background: #fff; }
.ticket-tabs button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.ticket-tab-panel[hidden] { display: none; }
@media (max-width: 760px) {
  .recipient-fields label { grid-template-columns: 1fr; gap: 5px; }
}
.internal-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #d9a7cc;
  border-radius: 8px;
  background: #fff8fc;
  cursor: pointer;
}
.internal-toggle > span:first-child {
  display: grid;
  gap: 2px;
}
.internal-toggle small {
  color: var(--muted);
}
.internal-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-track {
  position: relative;
  flex: 0 0 48px;
  width: 48px;
  height: 26px;
  background: #a8b6bc;
  border-radius: 20px;
  transition: 0.2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: 0.2s;
}
.internal-toggle input:checked + .switch-track {
  background: var(--magenta);
}
.internal-toggle input:checked + .switch-track::after {
  transform: translateX(22px);
}
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.attachments .button {
  background: var(--paper);
  font-size: 13px;
}
.attachment-list {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 6px;
}
.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.attachment-item span { overflow-wrap: anywhere; }
.attachment-item .compact { padding: 5px 8px; font-size: 11px; }
.current-clock {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sla-countdown {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
}
.sla-countdown.safe { color: #16734a; }
.sla-countdown.breached { color: #b42318; }
.sla-countdown.complete { color: var(--muted); }
.metadata-divider { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 5px; }
.sla-level { margin-bottom: 16px; }
.sla-editor input[type="number"] { width: 92px; }
.sla-editor select { min-width: 135px; margin-left: 6px; }
.sla-editor input,
.sla-editor select,
.sla-editor button { padding: 8px; font-size: 13px; }
.sla-save-bottom { margin-top: 14px; }
.refresh-button { white-space: nowrap; }
.closed-reply-form { display: none; }
.closed-ticket-notice {
  border-color: #e7b5b0;
  background: #fff7f6;
}
.email-log-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 650px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.audit-table {
  min-width: 980px;
}
.audit-metadata {
  max-width: 360px;
  max-height: 120px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--muted);
}
.audit-filters label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--muted);
}
.audit-filters input[type="date"] {
  width: auto;
}
@media (max-width: 760px) {
  .recipient-fields {
    grid-template-columns: 1fr;
  }
  .recipient-fields small {
    grid-column: auto;
  }
}

/* Responsive containers keep wide controls and tables inside their own scroll areas. */
header { height:auto; min-height:76px; flex-wrap:wrap; gap:14px; padding-top:14px; padding-bottom:14px; }
header nav { flex-wrap:wrap; max-width:100%; }
main { min-width:0; overflow-wrap:anywhere; }
.panel, .tablewrap, .formgrid > *, .admin-grid > *, .cards > *, .pagehead > * { min-width:0; max-width:100%; }
.tablewrap { width:100%; overflow-x:auto; }
input, select, textarea { min-width:0; max-width:100%; }
.formgrid { grid-template-columns:repeat(2,minmax(0,1fr)); }
@media(max-width:1250px) { header nav { gap:8px; } }
@media(max-width:760px) {
  header { padding:14px 16px; }
  header nav { gap:6px; width:100%; }
  header nav a, header nav button { padding:7px 9px; }
  main { padding:28px 14px; }
  h1 { font-size:28px; }
  .formgrid { grid-template-columns:minmax(0,1fr); }
  .pagehead, .pagination, .searchbar { flex-wrap:wrap; }
  .brand { max-width:100%; }
  .brand img { max-width:32vw; }
  .template-submenu, .checklist { grid-template-columns:repeat(auto-fit,minmax(min(210px,100%),1fr)); }
}

/* Address book stays out of the reply workspace until requested. */
.address-book-open { margin-top: 10px; }
.address-book-dialog { width: min(680px, calc(100vw - 32px)); max-height: 80vh; box-sizing: border-box; border: 1px solid #bccbd3; border-radius: 12px; padding: 20px; color: #152d3b; background: #fff; box-shadow: 0 12px 48px #0004; }
.address-book-dialog::backdrop { background: #152d3b80; }
.address-book-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.address-book-header h2 { margin: 0 0 12px; font-size: 21px; }
.address-book-dialog .recipient-contact-list { max-height: 45vh; overflow-y: auto; margin-top: 12px; }
.address-book-dialog .recipient-contact { gap: 12px; }
.address-book-dialog .recipient-contact[hidden] { display: none; }
.address-book-dialog .recipient-contact > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.address-book-feedback { min-height: 1.5em; font-size: 14px; }
@media (max-width: 600px) { .address-book-dialog { padding: 14px; } .address-book-dialog .recipient-contact { flex-wrap: wrap; } }

.color-tool button { border: 0; background: transparent; padding: 0 2px; min-width: 20px; font-weight: 800; }
.address-book-open { width: fit-content; justify-self: start; }
.address-book-dialog label { display: grid; grid-template-columns: 1fr; gap: 6px; }

/* Keep each ticket readable on one line; narrow screens scroll the table. */
.ticket-list th,
.ticket-list td {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  padding: 12px 14px;
}
.ticket-list .pill { display: inline-block; }
main:has(.ticket-list) { max-width: 1680px; }

/* Wide application pages; readable forms and message bodies keep natural wrapping. */
main { max-width: 1680px; }
main table th, main table td { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
main table .pill { display: inline-block; }
.managed-table { table-layout: fixed; min-width: 0; max-width: none; }
.managed-table th, .managed-table td { overflow: hidden; text-overflow: ellipsis; max-width: none; }
.managed-table th { position: relative; padding-right: 20px; }
.managed-table [hidden] { display: none !important; }
.column-resizer { position: absolute; right: 0; top: 0; height: 100%; width: 9px; cursor: col-resize; touch-action: none; border-right: 2px solid #bccbd3; }
.column-resizer:hover, .column-resizer:focus-visible { background: #008d8a33; outline: 2px solid var(--teal); outline-offset: -2px; }
.table-controls { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.table-controls small { color: var(--muted); }
.column-dialog { width: min(480px, calc(100vw - 32px)); max-height: 80vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; padding: 22px; color: var(--ink); }
.column-dialog::backdrop { background: #152d3b80; }
.column-dialog h2 { margin-top: 0; }
.column-choices { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.column-choices label { display: flex; align-items: center; gap: 8px; white-space: normal; overflow-wrap: anywhere; }
.column-choices input { width: auto; margin: 0; }
.column-dialog > button { margin: 6px 8px 0 0; }
@media(max-width:480px) { .column-choices { grid-template-columns: 1fr; } }

/* Keep the signed-in identity and portal together with the logout action. */
.account-menu { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; max-width: 260px; }
.account-identity { text-align: right; overflow-wrap: anywhere; }
.account-identity strong { display: block; font-size: 13px; line-height: 1.3; }
.account-identity small { font-size: 12px; line-height: 1.3; color: var(--muted); }
.account-menu form button { padding: 5px 0; }
@media(max-width:760px) { .account-menu { align-items: flex-start; max-width: 100%; } .account-identity { text-align: left; } }
