.hw-root {
  --hw-navy: #0e2740;
  --hw-gold: #d4b36a;
  --hw-cream: #f3f0ea;
  --hw-text: #1c2430;
  --hw-muted: #5d6570;
  --hw-line: #e7e1d6;
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}

.hw-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1400;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--hw-navy);
  color: #fff;
  box-shadow: 0 8px 20px rgba(14, 39, 64, 0.28);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.hw-fab:active {
  cursor: grabbing;
}

.hw-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--hw-gold);
  color: var(--hw-navy);
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
}

body.app-body .hw-fab {
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767px) {
  body.app-body .hw-fab {
    bottom: calc(var(--tab-h, 64px) + 12px + env(safe-area-inset-bottom, 0px));
  }
}

.hw-panel {
  position: fixed;
  right: 18px;
  bottom: 78px;
  z-index: 1400;
  width: min(400px, calc(100vw - 20px));
  height: min(580px, calc(100dvh - 96px));
  background: #fff;
  border: 1px solid var(--hw-line);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(14, 39, 64, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hw-root.is-page {
  position: relative;
  z-index: 1;
  margin: 0;
}

.hw-root.is-page .hw-fab,
.hw-root.is-page .hw-close,
.hw-root.is-page .hw-page-link {
  display: none;
}

.hw-root.is-page .hw-panel {
  position: static;
  width: 100%;
  height: calc(100dvh - var(--nav-h, 58px) - env(safe-area-inset-top, 0px) - 20px);
  min-height: 360px;
  right: auto;
  bottom: auto;
  box-shadow: 0 4px 12px rgba(14, 39, 64, 0.06);
}

@media (max-width: 767px) {
  .hw-root.is-page .hw-panel {
    height: calc(100dvh - var(--nav-h, 58px) - var(--tab-h, 64px) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 10px);
    border-radius: 12px;
  }
}

.hw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--hw-navy);
  color: #fff;
  flex-shrink: 0;
}

.hw-head strong {
  display: block;
  font-size: 0.88rem;
}

.hw-head span {
  display: block;
  font-size: 0.68rem;
  opacity: 0.75;
  font-weight: 600;
}

.hw-head-actions {
  display: flex;
  gap: 6px;
}

.hw-icon-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 8px;
  min-height: 26px;
  padding: 0 8px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

a.hw-icon-btn:hover {
  color: #fff;
  text-decoration: none;
}

.hw-close {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 7px;
}

.hw-stage {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.hw-root.is-page .hw-stage {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
}

.hw-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
  padding: 6px;
  background: #faf8f3;
  border-bottom: 1px solid var(--hw-line);
  max-height: 88px;
  flex-shrink: 0;
}

.hw-root.is-page .hw-list {
  max-height: none;
  border-bottom: 0;
  border-right: 1px solid var(--hw-line);
}

.hw-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

.hw-item:hover,
.hw-item.is-on {
  background: #fff;
}

.hw-item b {
  display: block;
  font-size: 0.75rem;
  color: var(--hw-navy);
}

.hw-item small {
  display: block;
  font-size: 0.65rem;
  color: var(--hw-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hw-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  background: linear-gradient(180deg, #fcfbf8 0%, #fff 48px);
}

.hw-thread-meta {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--hw-muted);
  font-weight: 700;
  padding: 6px 10px 4px;
}

.hw-chat {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 10px 10px;
  -webkit-overflow-scrolling: touch;
}

.hw-empty {
  margin: auto;
  font-size: 0.78rem;
  color: var(--hw-muted);
  font-weight: 600;
  text-align: center;
  max-width: 220px;
}

.hw-msg {
  max-width: 84%;
  padding: 7px 9px;
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.hw-msg.is-tenant {
  align-self: flex-end;
  background: var(--hw-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.hw-msg.is-staff {
  align-self: flex-start;
  background: var(--hw-cream);
  color: var(--hw-text);
  border-bottom-left-radius: 4px;
}

.hw-msg time {
  display: block;
  margin-top: 3px;
  font-size: 0.62rem;
  opacity: 0.7;
  font-weight: 600;
}

.hw-msg-thumb {
  display: block;
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  margin: 4px 0 2px;
  background: rgba(255, 255, 255, 0.2);
}

.hw-msg a {
  display: inline-block;
  margin-top: 2px;
  font-size: 0.7rem;
  font-weight: 700;
  color: inherit;
}

.hw-more {
  border: 0;
  background: transparent;
  color: var(--hw-gold);
  font-weight: 700;
  font-size: 0.7rem;
  padding: 0;
  cursor: pointer;
}

.hw-msg.is-staff .hw-more {
  color: #8b6914;
}

.hw-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--hw-line);
  background: #fff;
  padding: 8px 10px 10px;
}

.hw-phone-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.hw-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hw-muted);
  margin: 0;
}

.hw-label.hw-req:after {
  content: " *";
  color: #c0392b;
}

.hw-input {
  width: 100%;
  border: 1px solid var(--hw-line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  color: var(--hw-text);
  background: #fff;
}

.hw-text {
  resize: none;
  min-height: 44px;
  max-height: 88px;
  line-height: 1.35;
}

.hw-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 4px;
  padding: 4px;
  background: var(--hw-cream);
  border: 1px solid var(--hw-line);
  border-radius: 8px;
  width: fit-content;
  max-width: 100%;
}

.hw-preview-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  background: #fff;
  display: block;
}

.hw-preview-file {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--hw-navy);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}

.hw-preview-x {
  border: 0;
  background: transparent;
  color: var(--hw-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}

.hw-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.hw-chip {
  border: 1px solid var(--hw-line);
  background: var(--hw-cream);
  color: var(--hw-navy);
  border-radius: 99px;
  min-height: 26px;
  padding: 0 9px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.hw-file-chip {
  display: inline-flex;
  align-items: center;
}

.hw-send {
  border: 0;
  background: var(--hw-navy);
  color: #fff;
  border-radius: 99px;
  min-height: 26px;
  padding: 0 12px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  margin-left: auto;
}

.hw-status {
  margin: 0;
  font-size: 0.68rem;
  color: var(--hw-muted);
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.hw-status.is-err {
  color: #8a1f11;
}

.hw-status.is-ok {
  color: #1f5b2c;
}

.hw-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(14, 39, 64, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.hw-lightbox-card {
  background: #fff;
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  padding: 14px 16px;
}

.hw-lightbox-card p {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.9rem;
  color: var(--hw-text);
}

.hw-lightbox-card button {
  margin-top: 12px;
}

.app-main:has(.hw-root.is-page) {
  margin-top: 8px !important;
  padding-bottom: 8px;
}

@media (max-width: 700px) {
  .hw-root.is-page .hw-stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .hw-root.is-page .hw-list {
    max-height: 76px;
    border-right: 0;
    border-bottom: 1px solid var(--hw-line);
    flex-direction: row;
    gap: 4px;
  }

  .hw-root.is-page .hw-item {
    width: auto;
    min-width: 132px;
    flex-shrink: 0;
  }
}
