/* Wanetizen Chat — WhatsApp-inspired Live Chat
   Worker/API tidak diubah. Frontend only. */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: Arial, "Helvetica Neue", sans-serif;
  background: #d7dbd6;
  color: #111b21;
}

#app {
  width: 100%;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: #efeae2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* HEADER */
header {
  position: relative;
  flex: 0 0 auto;
  min-height: 88px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-end;
  gap: 5px;
  background: linear-gradient(135deg, #075e54, #128c7e);
  color: #fff;
  padding: 10px 8px 7px;
}

header h1 {
  position: absolute;
  top: 10px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 19px;
  line-height: 23px;
  font-weight: 700;
}

header p {
  margin-top: 2px;
  font-size: 11px;
  opacity: .82;
}

/* AUTH PANEL — generated by app.js */
#authPanel {
  width: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0;
  min-height: 31px;
}

#authPanel button,
#adminPanel button,
#notificationPanel button {
  border: 0;
  color: #fff;
  background: rgba(0, 0, 0, .18);
  border-radius: 18px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(5px);
}

#authPanel button:active,
#adminPanel button:active,
#notificationPanel button:active {
  transform: scale(.96);
}

/* HEADER CONTROLS */
#adminPanel,
#notificationPanel {
  position: static;
  margin: 0;
}

#adminPanel button,
#notificationPanel button {
  height: 31px;
  min-width: auto;
  padding: 0 12px;
}

/* MAIN */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* CHAT AREA */
#chatBox {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px 16px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;

  /* WhatsApp-like subtle wallpaper */
  background-color: #efeae2;
  background-image:
    radial-gradient(rgba(17, 27, 33, .035) 1px, transparent 1px),
    radial-gradient(rgba(17, 27, 33, .025) 1px, transparent 1px);
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
}

/* CHAT BUBBLE */
.chat-message {
  position: relative;
  width: fit-content;
  max-width: 82%;
  margin: 3px 0 8px;
  padding: 7px 9px 6px;
  background: #fff;
  border-radius: 8px 8px 8px 2px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .10);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-message.own-message {
  margin-left: auto;
  background: #d9fdd3;
  border-radius: 8px 8px 2px 8px;
}

.chat-message.admin-message {
  background: #fff;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* small WhatsApp-style tails */
.chat-message:not(.own-message)::after {
  content: "";
  position: absolute;
  left: -5px;
  bottom: 0;
  width: 9px;
  height: 9px;
  background: #fff;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.chat-message.own-message::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 0;
  width: 9px;
  height: 9px;
  background: #d9fdd3;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.chat-username {
  margin-bottom: 2px;
  font-size: 11px;
  line-height: 15px;
  font-weight: 700;
  color: #075e54;
}

.own-message .chat-username {
  color: #128c7e;
}

.chat-text {
  font-size: 14px;
  line-height: 19px;
  color: #111b21;
  white-space: pre-wrap;
}

.chat-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 2px;
  min-height: 12px;
}

.chat-time {
  font-size: 9px;
  line-height: 12px;
  color: #667781;
  text-align: right;
}

.message-check {
  font-size: 11px;
  line-height: 11px;
  letter-spacing: -3px;
  color: #53bdeb;
  margin-right: 2px;
}

.admin-badge {
  display: inline-block;
  margin-right: 3px;
  color: #128c7e;
  font-size: 10px;
}

.delete-message-button {
  margin-top: 5px;
  height: 25px !important;
  min-width: auto !important;
  padding: 0 8px !important;
  border-radius: 13px !important;
  background: #f1f2f2 !important;
  color: #d32f2f !important;
  font-size: 10px !important;
}

/* EMPTY */
.empty-chat {
  padding: 28px 10px;
  text-align: center;
  font-size: 13px;
  color: #667781;
}

/* NEW MESSAGE INDICATOR */
#newMessageIndicator {
  position: absolute !important;
  right: 12px !important;
  bottom: 12px !important;
  z-index: 20 !important;
  display: none;
  border: 0 !important;
  border-radius: 18px !important;
  padding: 8px 14px !important;
  height: auto !important;
  min-width: auto !important;
  background: #25d366 !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-size: 12px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.22);
}

/* INPUT AREA */
#chatForm {
  position: relative;
  flex: 0 0 auto;
  padding: 7px 8px;
  background: #f0f2f5;
  border-top: 1px solid #d1d7db;
  padding-bottom: calc(7px + env(safe-area-inset-bottom));
}

/* Hide the old standalone username field visually when logged in;
   it remains in the DOM and preserves the existing auth logic. */
#username {
  width: 100%;
  height: 32px;
  margin-bottom: 5px;
  border: 1px solid #d1d7db;
  border-radius: 16px;
  padding: 0 12px;
  font-size: 12px;
  outline: none;
  background: #fff;
  color: #111b21;
}

#username:focus,
#message:focus {
  border-color: #25d366;
  box-shadow: 0 0 0 1px rgba(37,211,102,.12);
}

.message-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 0;
}

#message {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 1px solid #d1d7db;
  border-radius: 21px;
  padding: 0 15px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: #111b21;
}

#message::placeholder,
#username::placeholder {
  color: #667781;
}

button {
  flex: 0 0 auto;
  height: 42px;
  min-width: 68px;
  border: none;
  border-radius: 21px;
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, opacity .2s ease;
}

button:active {
  transform: scale(.96);
}

button:disabled {
  opacity: .55;
  cursor: default;
}

/* SCROLLBAR */
#chatBox::-webkit-scrollbar {
  width: 4px;
}

#chatBox::-webkit-scrollbar-thumb {
  background: rgba(103,119,129,.45);
  border-radius: 10px;
}

#chatBox::-webkit-scrollbar-track {
  background: transparent;
}

/* AUTH MODAL */
#authModal {
  backdrop-filter: blur(4px);
}

#authModalBox {
  background: #fff !important;
  color: #111b21 !important;
  border-radius: 16px !important;
  box-shadow: 0 12px 45px rgba(0,0,0,.25) !important;
}

#authModalBox input {
  border-color: #d1d7db !important;
  background: #f0f2f5 !important;
  color: #111b21 !important;
}

#authModalSubmit {
  background: #25d366 !important;
  color: #fff !important;
}

/* MOBILE */
@media (max-width: 600px) {
  #app {
    max-width: 100%;
  }

  header {
    min-height: 86px;
    padding: 8px 4px 6px;
  }

  header h1 {
    font-size: 18px;
  }

  header p {
    font-size: 10px;
  }

  #authPanel {
    margin-top: 0;
  }

  #authPanel button,
  #adminPanel button,
  #notificationPanel button {
    font-size: 9px;
    padding: 0 7px;
    white-space: nowrap;
  }

  #adminPanel,
  #notificationPanel {
    position: static;
  }

  #chatBox {
    padding: 10px 7px 14px;
  }

  .chat-message {
    max-width: 88%;
    margin-bottom: 7px;
    padding: 6px 8px 5px;
  }

  .chat-username {
    font-size: 10px;
  }

  .chat-text {
    font-size: 14px;
    line-height: 19px;
  }

  .chat-time {
    font-size: 8px;
  }

  #chatForm {
    padding: 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }

  #username {
    height: 30px;
    margin-bottom: 4px;
  }

  #message,
  button {
    height: 40px;
  }

  #message {
    border-radius: 20px;
  }

  button {
    min-width: 58px;
    border-radius: 20px;
  }
}
