.tenant-sms-workspace {
  min-height: calc(100vh - 116px);
  color: #202124;
  background: #fff;
  border: 1px solid #dde3ea;
  border-radius: 16px;
  height: calc(100vh - 116px);
  overflow: auto;
}

.sms-workspace-toolbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
}

.sms-workspace-toolbar h2 { margin: 0; font: 700 18px/1.25 Manrope, sans-serif; }
.sms-workspace-toolbar p { margin: 2px 0 0; color: #6b7280; font-size: 12px; }
.sms-workspace-actions, .sms-thread-actions, .sms-filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sms-workspace-actions button, .sms-thread-actions button, .sms-filter-row button,
.sms-compose-actions button, .sms-admin-card button, .sms-note-form button {
  min-height: 36px;
  border: 0;
  border-radius: 18px;
  padding: 0 14px;
  background: #0b57d0;
  color: white;
  font-weight: 700;
  cursor: pointer;
}
.sms-workspace-actions button.secondary, .sms-thread-actions button.secondary,
.sms-filter-row button.secondary, .sms-admin-card button.secondary {
  background: #f1f3f4;
  color: #3c4043;
}

.sms-compliance-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  background: #fff8e1;
  border-bottom: 1px solid #f4d37d;
}
.sms-compliance-banner.is-ready { background: #ecfdf3; border-color: #a7e5bc; }
.sms-compliance-banner.is-attention { background: #fff8e8; border-color: #f0c36d; }
.sms-compliance-banner.is-error { background: #fef2f2; border-color: #fecaca; }
.sms-compliance-banner strong { display: block; font-size: 13px; }
.sms-compliance-banner span { color: #5f6368; font-size: 12px; }

.sms-filter-row {
  padding: 9px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  flex-wrap: nowrap;
}
.sms-filter-row > select { width: auto !important; flex: 0 1 190px; }
.sms-filter-row > .sms-filter-search { width: auto !important; min-width: 220px; }
.sms-filter-row select, .sms-filter-row input, .sms-admin-card input,
.sms-admin-card select, .sms-compose-shell select, .sms-compose-shell input,
.sms-note-form textarea {
  min-height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
  color: #202124;
  font: inherit;
}
.sms-filter-search { flex: 1 1 240px; }

.sms-inbox-grid {
  display: grid;
  grid-template-columns: minmax(300px, 38%) minmax(0, 1fr);
  min-height: 480px;
  height: clamp(480px, calc(100vh - 380px), 680px);
}
.sms-conversation-list { border-right: 1px solid #e5e7eb; overflow: auto; background: #fff; }
.sms-conversation-pagination { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 8px 10px; border-top: 1px solid #e5e7eb; background: #fff; font-size: 12px; }
.sms-conversation-row {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid #eef1f4;
  padding: 12px 14px;
  background: #fff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.sms-conversation-row:hover { box-shadow: inset 3px 0 #1a73e8; background: #f8fbff; }
.sms-conversation-row.is-selected { background: #eaf2ff !important; color: #202124 !important; box-shadow: inset 3px 0 #0b57d0; }
.sms-conversation-row.is-unread { background: #f2f6fc; }
.sms-conversation-avatar {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 50%; background: #dbeafe; color: #174ea6; font-weight: 800;
}
.sms-conversation-copy { min-width: 0; }
.sms-conversation-copy strong, .sms-conversation-copy span, .sms-conversation-copy small {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sms-conversation-copy strong { font-size: 14px; }
.sms-conversation-copy span { font-size: 12px; color: #4b5563; margin-top: 2px; }
.sms-conversation-copy small { font-size: 11px; color: #7a828d; margin-top: 4px; }
.sms-conversation-meta { text-align: right; }
.sms-conversation-meta time { display: block; color: #6b7280; font-size: 11px; }
.sms-unread-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-top: 7px; padding: 0 6px; border-radius: 10px; background: #0b57d0; color: white; font-size: 11px; font-weight: 800; }

.sms-thread-pane { min-width: 0; display: flex; flex-direction: column; background: #f8fafc; }
.sms-thread-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px; border-bottom: 1px solid #e5e7eb; background: #fff; }
.sms-thread-header h3 { margin: 0; font-size: 17px; }
.sms-thread-header p { margin: 4px 0 0; color: #6b7280; font-size: 12px; }
.sms-message-stream { flex: 1; min-height: 0; max-height: none; overflow: auto; padding: 20px; }
.sms-load-older { display: block; margin: 0 auto 14px; }
.sms-message { width: min(78%, 620px); margin: 0 0 14px; }
.sms-message.is-outbound { margin-left: auto; }
.sms-message-bubble { padding: 11px 14px; border-radius: 16px 16px 16px 4px; background: #fff; border: 1px solid #dfe3e8; box-shadow: 0 1px 2px rgb(30 41 59 / 7%); white-space: pre-wrap; overflow-wrap: anywhere; }
.sms-message.is-outbound .sms-message-bubble { border-color: #bfd4ff; border-radius: 16px 16px 4px 16px; background: #eaf2ff; }
.sms-message.is-failed .sms-message-bubble { border-color: #f4a7a7; background: #fff5f5; }
.sms-message-meta { display: flex; gap: 6px; align-items: center; justify-content: flex-start; margin: 4px 5px 0; color: #6b7280; font-size: 10px; }
.sms-message.is-outbound .sms-message-meta { justify-content: flex-end; }
.sms-delivery-failed { color: #b3261e; font-weight: 800; }
.sms-attachment-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sms-attachment-list a { display: inline-flex; padding: 6px 9px; border-radius: 8px; background: #fff; border: 1px solid #cbd5e1; color: #0b57d0; font-size: 11px; font-weight: 700; text-decoration: none; }
.sms-retry-button { border: 0; background: transparent; color: #0b57d0; text-decoration: underline; font-weight: 700; cursor: pointer; }

.sms-compose-shell { padding: 12px 16px 16px; background: #fff; border-top: 1px solid #e5e7eb; }
.sms-compose-shell textarea { width: 100%; min-height: 78px; resize: vertical; border: 1px solid #cbd5e1; border-radius: 12px; padding: 11px 12px; font: inherit; }
.sms-compose-shell > input[name="mediaUrls"] { width: 100%; margin-top: 8px; }
.sms-compose-head { display: grid; grid-template-columns: minmax(145px, 220px) minmax(170px, 1fr); gap: 8px; margin-bottom: 8px; }
.sms-compose-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; }
.sms-compose-actions small { color: #6b7280; }
.sms-compose-blocked { display: grid; gap: 3px; padding: 12px; border: 1px solid #f0c36d; border-radius: 10px; background: #fff8e8; }
.sms-compose-blocked span, .sms-note-readonly { color: #5f6368; font-size: 12px; }
.sms-compose-error { margin: 7px 0 0; color: #b3261e; font-size: 12px; }

.sms-empty, .sms-loading, .sms-service-error { display: grid; place-items: center; align-content: center; min-height: 320px; padding: 38px; text-align: center; color: #5f6368; }
.sms-empty strong, .sms-service-error strong { display: block; margin-bottom: 6px; color: #202124; font-size: 16px; }

.sms-admin-panel { padding: 16px; background: #f8fafc; border-top: 1px solid #e5e7eb; scroll-margin-top: 16px; }
.sms-admin-panel > summary, .sms-admin-card > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer; list-style: none;
}
.sms-admin-panel > summary::-webkit-details-marker, .sms-admin-card > summary::-webkit-details-marker { display: none; }
.sms-admin-panel > summary::after, .sms-admin-card > summary::after { content: "⌄"; color: #5f6368; font-weight: 800; }
.sms-admin-panel[open] > summary::after, .sms-admin-card[open] > summary::after { content: "⌃"; }
.sms-admin-panel > summary > span, .sms-admin-card > summary > span { display: grid; gap: 2px; }
.sms-admin-panel > summary small, .sms-admin-card > summary small { color: #6b7280; font-size: 11px; font-weight: 500; }
.sms-admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.sms-admin-card { min-width: 0; border: 1px solid #dfe3e8; border-radius: 12px; background: #fff; overflow: hidden; }
.sms-admin-card:first-child { grid-column: 1 / -1; }
.sms-admin-card > summary { min-height: 58px; padding: 11px 14px; }
.sms-admin-card[open] > summary { border-bottom: 1px solid #eef1f4; }
.sms-admin-card-body { padding: 14px; }
.sms-admin-card h3 { margin: 0 0 5px; font-size: 14px; }
.sms-admin-card p { margin: 0 0 10px; color: #6b7280; font-size: 12px; }
.sms-admin-card label { display: grid; gap: 4px; margin: 8px 0; color: #4b5563; font-size: 11px; font-weight: 700; }
.sms-admin-field > input, .sms-admin-field > select { width: 100%; }
.sms-access-list { max-height: 260px; overflow: auto; }
.sms-access-role-list { max-height: none; border: 1px solid #e5e7eb; border-radius: 10px 10px 0 0; background: #f8fafc; }
.sms-access-user-list { border: 1px solid #e5e7eb; border-top: 0; border-radius: 0 0 10px 10px; }
.sms-access-heading, .sms-access-user { display: grid; grid-template-columns: minmax(180px, 1fr) 92px minmax(230px, auto); gap: 10px; align-items: center; }
.sms-access-heading { padding: 6px 10px; color: #6b7280; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.sms-access-user { padding: 9px 10px; border-bottom: 1px solid #eef1f4; font-size: 11px; }
.sms-access-user:last-child { border-bottom: 0; }
.sms-access-user > span:first-child { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.sms-access-user small { display: block; margin-top: 2px; color: #6b7280; font-weight: 500; }
.sms-access-permissions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.sms-admin-card .sms-access-permission { display: inline-flex; align-items: center; gap: 4px; margin: 0; white-space: nowrap; }
.sms-access-feature-state { color: #5f6368; font-size: 11px; font-weight: 700; }
.sms-admin-save-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.sms-admin-save-row small { max-width: 56ch; color: #6b7280; }
.sms-admin-number-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid #eef1f4; }
.sms-admin-number-row span { display: grid; gap: 2px; }
.sms-admin-number-row small { color: #6b7280; }
.sms-access-empty { padding: 14px; }
.sms-note-section { padding: 10px 16px; border-top: 1px solid #e5e7eb; background: #fff; }
.sms-note { margin: 6px 0; padding: 8px 10px; border-radius: 8px; background: #fff8e1; font-size: 12px; }
.sms-note small { display: block; color: #6b7280; margin-top: 3px; }
.sms-note-form { display: flex; gap: 8px; margin-top: 8px; }
.sms-note-form textarea { flex: 1; min-height: 42px; resize: vertical; }
.sms-tag { display: inline-flex; width: auto !important; padding: 2px 7px; border-radius: 10px; background: #e8eaed; color: #4b5563; font-size: 10px; }
.sms-thread-header [data-sms-action="mobile-back"] { display: none; }

@media (max-width: 1050px) {
  .sms-inbox-grid { grid-template-columns: minmax(260px, 42%) minmax(0, 1fr); }
  .sms-admin-grid { grid-template-columns: 1fr; }
  .sms-admin-card:first-child { grid-column: auto; }
}

@media (max-width: 760px) {
  .tenant-sms-workspace { border: 0; border-radius: 0; min-height: calc(100vh - 100px); }
  .sms-inbox-grid { display: block; }
  .sms-filter-row { flex-wrap: wrap; }
  .sms-filter-row > select, .sms-filter-row > .sms-filter-search { width: 100% !important; flex: 1 1 100%; }
  .sms-conversation-list { border-right: 0; }
  .sms-thread-pane { display: none; position: fixed; inset: 0; z-index: 1200; }
  .tenant-sms-workspace.sms-mobile-thread-open .sms-thread-pane { display: flex; }
  .sms-thread-header [data-sms-action="mobile-back"] { display: inline-flex; }
  .sms-message-stream { max-height: none; }
  .sms-compose-head { grid-template-columns: 1fr; }
  .sms-workspace-toolbar, .sms-filter-row { padding-left: 12px; padding-right: 12px; }
  .sms-admin-panel { padding: 12px; }
  .sms-access-heading { display: none; }
  .sms-access-user { grid-template-columns: minmax(0, 1fr) auto; }
  .sms-access-user > .sms-access-permissions { grid-column: 1 / -1; justify-content: flex-start; padding-top: 4px; }
  .sms-admin-save-row { align-items: stretch; flex-direction: column; }
}

/* Daily messaging remains an inbox. Administration is an explicit drawer so
 * setup never lengthens or displaces the shared conversation workspace. */
.sms-admin-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1500;
  display: none;
  width: min(760px, 92vw);
  height: 100dvh;
  padding: 0;
  overflow: auto;
  border: 0;
  border-left: 1px solid #dfe3e8;
  background: #f8fafc;
  box-shadow: -12px 0 36px rgb(15 23 42 / 18%);
}
.sms-admin-panel.is-open { display: block; }
body:has(.sms-admin-panel.is-open) .tenant-workspace-sidebar,
body:has(.sms-admin-panel.is-open) .tenant-workspace-toolbar,
body:has(.sms-admin-panel.is-open) .sms-inbox-grid,
body:has(.sms-admin-panel.is-open) .tenant-mobile-nav { pointer-events: none; user-select: none; }
.tenant-sms-workspace:has(> .sms-admin-panel.is-open) > :not(.sms-admin-panel) { pointer-events: none; user-select: none; }
.sms-admin-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  min-height: 68px;
  padding: 12px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #dfe3e8;
  background: rgba(255,255,255,.98);
}
.sms-admin-head > span { display: grid; gap: 2px; }
.sms-admin-head small { color: #6b7280; font-size: 11px; font-weight: 500; }
.sms-admin-panel .sms-admin-grid { grid-template-columns: 1fr; margin: 0; padding: 14px; }
.sms-admin-panel .sms-admin-card:first-child { grid-column: auto; }
.sms-access-preset { width: 100%; min-width: 148px; }
.sms-access-advanced { display: none; }
.sms-access-user.is-disabled { background: #f3f4f6; color: #6b7280; }
.sms-attachment-tools { margin-top: 8px; }
.sms-attachment-tools > summary {
  display: inline-flex;
  min-height: 36px;
  padding: 0 12px;
  align-items: center;
  border-radius: 18px;
  background: #f1f3f4;
  color: #3c4043;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  list-style: none;
}
.sms-attachment-tools label { display: grid; gap: 4px; margin-top: 8px; color: #5f6368; font-size: 11px; }
.sms-attachment-tools input { width: 100%; }
.sms-attachment-picker { display: inline-grid; width: fit-content; gap: 2px; margin-top: 8px; cursor: pointer; color: #3c4043; font-size: 12px; font-weight: 700; }
.sms-attachment-picker > span { display: inline-flex; min-height: 36px; padding: 0 12px; align-items: center; border-radius: 18px; background: #f1f3f4; }
.sms-attachment-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.sms-attachment-picker small { color: #6b7280; font-size: 10px; font-weight: 500; }
.sms-compose-uploads { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sms-compose-upload { display: inline-flex; min-height: 40px; max-width: min(100%, 320px); padding: 6px 8px 6px 12px; align-items: center; gap: 10px; border: 1px solid #dadce0; border-radius: 10px; background: #fff; }
.sms-compose-upload > span { display: grid; min-width: 0; }
.sms-compose-upload strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.sms-compose-upload small { color: #6b7280; font-size: 10px; }
.sms-compose-upload button { min-width: 28px; min-height: 28px; padding: 0; border-radius: 50%; }
.sms-compose-upload.is-uploading { color: #1a73e8; font-size: 12px; }

@media (max-width: 760px) {
  .sms-workspace-toolbar { min-height: 54px; }
  .sms-workspace-toolbar p, .sms-ready-strip { display: none; }
  .sms-workspace-actions button[data-sms-action="refresh"] { display: none; }
  .sms-filter-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .sms-filter-row > .sms-filter-search { grid-column: 1 / -1; min-width: 0; }
  .sms-filter-row > select { width: 100% !important; min-width: 0; }
  .sms-filter-row > select[data-sms-filter="number"] { grid-column: 1 / -1; }
  .sms-thread-pane {
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff;
  }
  .sms-thread-header {
    position: sticky;
    top: 0;
    z-index: 4;
    display: grid;
    padding: 8px 10px;
  }
  .sms-thread-header > div:first-child { display: grid; grid-template-columns: 44px minmax(0,1fr); align-items: center; }
  .sms-thread-header h3, .sms-thread-header p { grid-column: 2; }
  .sms-thread-header [data-sms-action="mobile-back"] { grid-row: 1 / 3; min-width: 44px; min-height: 44px; padding: 0; justify-content: center; }
  .sms-thread-actions { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .sms-thread-actions input[data-sms-tags], .sms-thread-actions [data-sms-action="save-tags"] { display: none; }
  .sms-message-stream { padding: 14px 12px; }
  .sms-message { width: min(88%, 620px); }
  .sms-message-meta { flex-wrap: wrap; font-size: 11px; }
  .sms-note-section { display: none; }
  .sms-compose-shell {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgb(15 23 42 / 8%);
  }
  .sms-compose-head { display: none; }
  .sms-compose-shell.is-new-compose .sms-compose-head { display: grid; }
  .sms-compose-shell textarea { min-height: 48px; max-height: 112px; resize: none; }
  .sms-compose-actions small { display: none; }
  .sms-admin-panel { width: 100vw; }
  .sms-access-user { grid-template-columns: minmax(0, 1fr); }
  .sms-access-user > span { grid-column: 1; }
}
