/* ILECO III — the CHAT BOX, copied from i-Assist (css/style.css): a round button (drag it anywhere), a box with the
   animated ILECO III header, tabs, rooms, direct messages, bubbles. Not loaded on the login page. */
.chatbtn {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #ffc928;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(20, 33, 61, 0.35);
}

.chatbtn[hidden],
.chatbox[hidden],
.chatnote[hidden],
.chatform[hidden],
.chatbadge[hidden] {
  display: none;
}

.chatbtn {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.chatbtn.mueve {
  cursor: grabbing;
  transform: scale(1.1);
  animation: none;
}

.chatbtn.asienta {
  transition:
    left 0.28s ease,
    top 0.28s ease;
}

.chatbtn.new {
  animation: cpulse 1.6s ease-in-out infinite;
}

@keyframes cpulse {
  0%,
  100% {
    box-shadow:
      0 6px 18px rgba(20, 33, 61, 0.35),
      0 0 0 0 rgba(255, 201, 40, 0.7);
  }
  50% {
    box-shadow:
      0 6px 18px rgba(20, 33, 61, 0.35),
      0 0 0 12px rgba(255, 201, 40, 0);
  }
}

.chatbadge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: #d62828;
  color: #fff;
  font:
    700 12px/18px system-ui,
    sans-serif;
  text-align: center;
  border: 2px solid #fff;
}

.chatbox {
  position: fixed;
  right: 14px;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  width: min(400px, calc(100vw - 28px));
  height: min(640px, calc(100vh - 100px));
  height: min(640px, calc(100dvh - 100px));
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: #fff8dc;
  border: 2px solid var(--navy);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(20, 33, 61, 0.45);
}

.chathead {
  position: relative;
  flex: 0 0 170px;
  background: linear-gradient(#150a36, #03071c);
}

.chat3d,
.chatgl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.chat3d,
.chatgl,
.chathead.dgl .chat3d {
  display: none;
}

.chatword {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffc21f;
  font:
    900 40px/1 'Segoe UI',
    Arial,
    sans-serif;
  letter-spacing: 3px;
  text-shadow: 0 0 14px rgba(255, 170, 40, 0.8);
}

.chathead.dgl .chatword,
.chathead.d3 .chatword {
  display: none;
}

.chathead.d3 .chat3d,
.chathead.dgl .chatgl {
  display: block;
}

.chatx {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: rgba(20, 33, 61, 0.88);
  color: #ffd23f;
  font-size: 16px;
  cursor: pointer;
}

.chatbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 10px;
  border-bottom: 1px solid #ecd98a;
  background: #fff3c4;
}

.chattabs {
  display: flex;
  gap: 6px;
  flex: 1;
}

.chattabs button {
  flex: 1;
  border: 1px solid var(--navy);
  background: #fff;
  color: var(--navy);
  border-radius: 18px;
  padding: 7px 6px;
  font:
    600 14px system-ui,
    sans-serif;
  cursor: pointer;
}

.chattabs button.on {
  background: var(--navy);
  color: #ffd23f;
}

.cdot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 4px;
  border-radius: 50%;
  background: #d62828;
}

.cback {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--navy);
  color: #ffd23f;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.cro {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--navy);
  color: #ffd23f;
}

.chatbody {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.cr {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 6px;
  padding: 9px 10px;
  text-align: left;
  border: 1px solid #f0e2a6;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.cr:hover {
  background: #fffbea;
}

.cav {
  flex: 0 0 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--navy);
  color: #ffd23f;
  display: flex;
  align-items: center;
  justify-content: center;
  font:
    700 14px system-ui,
    sans-serif;
}

.cav.g {
  background: #ffc928;
  color: var(--navy);
}

.cav {
  position: relative;
}

/* the green / grey dot: online or offline */
.cpres {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #9aa3b5;
}

.cpres.on {
  background: #27c24c;
  box-shadow: 0 0 6px rgba(39, 194, 76, 0.8);
}

.cverde {
  color: #1c8f39;
  font-weight: 600;
}

.cbt {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cbt b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cstat {
  color: var(--mut);
  font-size: 12px;
}

.cstat.on {
  color: #1c8f39;
  font-weight: 600;
}

.cedit {
  width: min(320px, 78vw);
}

.cedit textarea {
  min-height: 64px;
  padding: 8px 10px;
  border-radius: 12px;
}

.cerow {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.cedt {
  color: #1d4f91;
}

.ctx {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ctx b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  color: var(--navy);
}

.ctx small,
.cmeta small,
.cwala,
.cday {
  color: var(--mut);
}

.ctx small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.cmeta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.cmeta small {
  font-size: 11.5px;
}

.cbadge {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #d62828;
  color: #fff;
  font:
    700 12px/20px system-ui,
    sans-serif;
  font-style: normal;
  text-align: center;
}

.cnew,
.csearch {
  margin: 2px 0 8px;
}

.cwala {
  padding: 8px 4px;
  font-size: 13.5px;
}

.cday {
  margin: 10px 0 6px;
  text-align: center;
  font-size: 12px;
}

.cm {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 86%;
  margin: 0 0 8px;
}

.cm.me {
  align-items: flex-end;
  margin-left: auto;
}

.cwho {
  margin: 0 0 2px 4px;
  color: var(--mut);
  font-size: 12px;
}

.cb {
  padding: 8px 12px;
  border: 1px solid #f0e2a6;
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.cm.me .cb {
  background: #ffd84d;
  border-color: #e8bf2a;
  border-radius: 14px 14px 4px 14px;
}

.cwhen {
  margin: 2px 4px 0;
  color: #7a8094;
  font-size: 11.5px;
}

.cdel {
  padding: 0;
  border: 0;
  background: none;
  color: #a02020;
  font-size: 11.5px;
  text-decoration: underline;
  cursor: pointer;
}

.chatnote {
  padding: 6px 12px;
  background: var(--bad);
  color: #7a1f1f;
  font-size: 13px;
}

.chatform {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #ecd98a;
  background: #fff3c4;
}

.chatform textarea {
  flex: 1;
  min-height: 42px;
  max-height: 110px;
  padding: 10px 12px;
  border-radius: 18px;
  resize: none;
}

.chatform .btn {
  height: 42px;
  padding: 0 18px;
}

@media (max-width: 600px) {
  .chatbox {
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
  }

  .chathead {
    flex-basis: 150px;
  }

  .chatbox {
    max-height: none;
  }

  body.chatopen {
    overflow: hidden;
  }
}

@media print {
  #chat {
    display: none;
  }
}

/* the visible area is short (the keyboard is open): a thin title bar instead of the animation */
.chatbox.corto .chathead {
  flex: 0 0 54px;
}

.chatbox.corto .chatgl,
.chatbox.corto .chat3d {
  display: none;
}

.chatbox.corto .chathead .chatword {
  display: flex;
  font-size: 24px;
  justify-content: flex-start;
  padding-left: 16px;
}

.chatbox.corto .chatbar {
  min-height: 44px;
  padding: 4px 10px;
}

@media (prefers-reduced-motion: reduce) {
  .chatbtn.new {
    animation: none;
  }
}

/* ===== Traffic (the monitor of the Admin, laid out like Wireshark) ===== */
/* this system: the buttons inside the box, the dialog, and the position next to the field crew's "Log a complaint" button */
.chatbox .btn {
  background: var(--navy);
  color: var(--y, #ffc72c);
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.chatbox .btn.sm {
  padding: 6px 12px;
  font-size: 13px;
}
.chatbox .btn.alt {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--navy);
}
.field-page .chatbtn:not([style*='left']) {
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}
.chat-dlg {
  width: min(360px, 92vw);
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(20, 33, 61, 0.4);
}
.chat-dlg::backdrop {
  background: rgba(20, 33, 61, 0.5);
}
.chat-dlg form {
  padding: 20px;
}
.chat-dlg p {
  margin: 0 0 14px;
  font-weight: 600;
  color: var(--navy);
}
.chat-dlg .row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
/* while the chat is open the small switches at the bottom-left are hidden (they would lie over the box) */
body.chatopen .galamiton {
  display: none;
}

/* the header of the open box is a handle (PC / tablet) */
@media (min-width: 601px) {
  .chathead {
    cursor: grab;
    touch-action: none;
  }
  .chathead.mueve {
    cursor: grabbing;
  }
}
