/* GChat — WhatsApp-inspired layout */

:root {
  --wa-teal: #075e54;
  --wa-teal-dark: #054d44;
  --wa-accent: #25d366;
  --wa-accent-tap: #20bd5a;
  --wa-chat-bg: #e5ddd5;
  --wa-pattern-tint: rgba(0, 0, 0, 0.03);
  --wa-bubble-out: #dcf8c6;
  --wa-bubble-in: #fff;
  --wa-text: #111b21;
  --wa-meta: rgba(17, 27, 33, 0.45);
  --wa-composer-bg: #f0f2f5;
  --wa-input-bg: #fff;
  --radius-bubble-out: 12px 12px 0 12px;
  --radius-bubble-in: 12px 12px 12px 0;
  --shadow-header: 0 1px 3px rgba(11, 20, 26, 0.22);
  --shadow-bubble-in: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--wa-chat-bg);
  color: var(--wa-text);
  font-size: 15px;
  line-height: 1.4;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}

/* —— Header —— */
.wa-header {
  flex-shrink: 0;
  background: var(--wa-teal);
  color: #fff;
  padding: calc(0.5rem + var(--safe-top)) 0.5rem 0.65rem 0.85rem;
  box-shadow: var(--shadow-header);
  z-index: 20;
}

.wa-header-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  max-width: 1000px;
  margin: 0 auto;
}

.wa-header-title-block {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.wa-app-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.25;
}

.wa-status {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.88;
  margin-top: 0.2rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-header-actions-row {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  gap: 0.15rem;
}

.wa-header-call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.45rem;
  height: 2.45rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.wa-header-call-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.wa-header-call-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
}

.wa-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.wa-icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.wa-icon-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* —— Chat area —— */
#chat-container {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

#messages {
  flex: 1 1 0%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 0.5rem 0.65rem calc(0.35rem + var(--safe-bottom));
  min-height: 0;
  background-color: var(--wa-chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23000' fill-opacity='0.035'%3E%3Ccircle cx='8' cy='8' r='1'/%3E%3Ccircle cx='38' cy='38' r='1'/%3E%3Ccircle cx='22' cy='52' r='1'/%3E%3Ccircle cx='52' cy='14' r='1'/%3E%3C/g%3E%3C/svg%3E");
}

.wa-chat-empty-hint {
  margin: 2rem auto 1rem;
  max-width: 16rem;
  padding: 1rem 1.15rem;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--wa-meta);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

#messages:has(.message) .wa-chat-empty-hint {
  display: none;
}

.wa-load-older-row {
  display: flex;
  justify-content: center;
  padding: 0.35rem 0 0.45rem;
}

.wa-load-older-row[hidden] {
  display: none !important;
}

.wa-load-older-btn {
  font-size: 0.82rem;
  font-weight: 500;
  color: #027eb5;
  background: rgba(255, 255, 255, 0.85);
  border: none;
  padding: 0.45rem 1rem;
  border-radius: 1.25rem;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.wa-load-older-btn:hover:not(:disabled) {
  background: #fff;
}

.wa-load-older-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* —— Message rows —— */
.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.35rem;
  max-width: 100%;
}

.message.sent {
  align-items: flex-end;
}

.message.received {
  align-items: flex-start;
}

.msg-sender {
  font-size: 0.72rem;
  font-weight: 600;
  color: #128c7e;
  margin: 0 0 0.12rem 0.35rem;
  max-width: 85%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bubble {
  max-width: min(85%, 26rem);
  padding: 0.45rem 0.55rem 0.35rem;
  position: relative;
  border-radius: var(--radius-bubble-in);
  box-shadow: var(--shadow-bubble-in);
}

.message.sent .bubble {
  background: var(--wa-bubble-out);
  border-radius: var(--radius-bubble-out);
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.1);
}

.message.received .bubble {
  background: var(--wa-bubble-in);
}

.bubble-text {
  word-break: break-word;
  white-space: pre-wrap;
  padding-right: 0.25rem;
  font-size: 0.942rem;
  line-height: 1.42;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0.12rem;
  padding-left: 0.35rem;
  min-height: 1rem;
}

.bubble-time {
  font-size: 0.65rem;
  color: var(--wa-meta);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}

.bubble-img {
  display: block;
  max-width: 100%;
  max-height: min(280px, 50vh);
  border-radius: 0.45rem;
  margin-bottom: 0.15rem;
  vertical-align: middle;
}

.bubble-caption {
  margin-top: 0.35rem;
  word-break: break-word;
  font-size: 0.942rem;
}

.settings-notify-block {
  padding: 0.65rem 0;
  margin: 0.25rem 0 0.35rem;
  border-top: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

.settings-notify-status {
  font-size: 0.78rem;
  color: #667781;
  margin: 0;
  line-height: 1.4;
}

.settings-notify-action {
  align-self: flex-start;
  font-size: 0.85rem;
  font-weight: 500;
  color: #027eb5;
  background: transparent;
  border: 1px solid #b8d4e8;
  border-radius: 0.45rem;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.settings-notify-action:hover {
  background: rgba(2, 126, 181, 0.06);
}

.bubble-video {
  display: block;
  width: 100%;
  max-width: min(100%, 320px);
  max-height: min(240px, 45vh);
  border-radius: 0.45rem;
  background: #000;
}

.bubble-audio {
  display: block;
  width: 100%;
  min-width: 200px;
  max-width: 280px;
  height: 2.25rem;
}

/* —— Composer dock (Telegram / WhatsApp style) —— */
#composer-wrap {
  flex-shrink: 0;
  position: relative;
  background: var(--wa-composer-bg);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding-bottom: 0;
}

.wa-composer-panel {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  padding: 0.45rem 0.55rem calc(0.5rem + var(--safe-bottom));
  max-width: 1000px;
  margin: 0 auto;
}

.wa-composer-tools {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.08rem;
  padding-bottom: 0.15rem;
}

.wa-composer-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  border: none;
  border-radius: 0.45rem;
  background: transparent;
  color: #54656f;
  cursor: pointer;
  flex-shrink: 0;
}

.wa-composer-tool:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.06);
}

.wa-composer-tool:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.wa-composer-tool.wa-recording {
  color: #e53935;
  background: rgba(229, 57, 53, 0.12);
  animation: wa-pulse-rec 1.2s ease-in-out infinite;
}

@keyframes wa-pulse-rec {
  50% {
    opacity: 0.85;
  }
}

.wa-input-shell-grow {
  flex: 1;
  min-width: 0;
}

.wa-input-shell-grow #message-input {
  min-height: 2.5rem;
}

.wa-input-shell {
  flex: 1;
  min-width: 0;
  background: var(--wa-input-bg);
  border-radius: 1.5rem;
  padding: 0.35rem 0.95rem;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.04);
}

#message-input {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-size: 0.98rem;
  font-family: inherit;
  line-height: 1.45;
  resize: none;
  min-height: 2.35rem;
  max-height: 7.5rem;
  overflow-y: auto;
}

#message-input:focus {
  outline: none;
}

#message-input::placeholder {
  color: #8696a0;
}

.wa-send-btn {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background: var(--wa-accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: background 0.15s ease, transform 0.1s ease;
}

.wa-send-btn:hover:not(:disabled) {
  background: var(--wa-accent-tap);
}

.wa-send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.wa-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.wa-send-btn:focus-visible {
  outline: 2px solid var(--wa-accent);
  outline-offset: 2px;
}

/* —— Emoji panel —— */
.wa-emoji-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0.5rem;
  right: 0.5rem;
  margin-bottom: 0.2rem;
  background: #fff;
  border-radius: 0.65rem;
  padding: 0.5rem;
  box-shadow: 0 -4px 24px rgba(11, 20, 26, 0.15);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.wa-emoji-panel.open {
  display: block;
}

#emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.35rem, 1fr));
  gap: 0.2rem;
}

.emoji-cell {
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 0.35rem;
}

.emoji-cell:hover {
  background: #f0f2f5;
}

/* —— Modal —— */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 20, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

#config-panel.modal-dismissed {
  display: none !important;
}

.modal-content {
  background: #fff;
  padding: 1.35rem 1.25rem 1.5rem;
  border-radius: 0.65rem;
  max-width: 420px;
  width: 100%;
  max-height: min(90dvh, 38rem);
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(11, 20, 26, 0.25);
}

#config-panel .modal-content {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

#config-panel .modal-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--wa-text);
}

#config-panel .config-hint {
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0;
  text-align: left;
  color: #3b4a54;
}

#config-panel .config-hint code {
  font-size: 0.78rem;
  word-break: break-all;
}

#config-panel .field-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
  align-self: flex-start;
  color: #54656f;
}

#config-panel .pat-explainer {
  font-size: 0.78rem;
  line-height: 1.45;
  margin: 0;
  text-align: left;
  color: #667781;
}

#config-panel .token-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: flex-start;
}

#config-panel .btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: #027eb5;
  cursor: pointer;
  text-decoration: underline;
}

#config-panel .btn-link:hover {
  color: #015a82;
}

.optional-badge {
  font-size: 0.75rem;
  font-weight: normal;
  opacity: 0.75;
}

#config-panel .pat-details {
  font-size: 0.85rem;
  text-align: left;
  width: 100%;
}

#config-panel .pat-details summary {
  cursor: pointer;
  color: #027eb5;
  list-style-position: outside;
}

#config-panel .pat-details .pat-explainer {
  margin-top: 0.5rem;
}

#config-panel .pat-details .token-actions {
  margin-top: 0.35rem;
}

#config-panel #repo-input,
input[type='password'] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  margin: 0.2rem 0 0.4rem;
  border: 1px solid #d1d7db;
  border-radius: 0.45rem;
  font-size: 1rem;
}

#config-panel #btn-save-config {
  margin-top: 0.35rem;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--wa-accent);
  border: none;
  border-radius: 0.45rem;
  cursor: pointer;
  width: 100%;
}

#config-panel #btn-save-config:hover {
  background: var(--wa-accent-tap);
}

@media (prefers-color-scheme: dark) {
  :root {
    --wa-teal: #1f2c33;
    --wa-teal-dark: #111b21;
    --wa-chat-bg: #0b141a;
    --wa-bubble-out: #005c4b;
    --wa-bubble-in: #1f2c34;
    --wa-text: #e9edef;
    --wa-meta: rgba(233, 237, 239, 0.55);
    --wa-composer-bg: #1f2c33;
    --wa-input-bg: #2a3942;
    --shadow-bubble-in: 0 1px 0.5px rgba(0, 0, 0, 0.35);
  }

  body {
    background: var(--wa-chat-bg);
    color: var(--wa-text);
  }

  #messages {
    background-color: var(--wa-chat-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23fff' fill-opacity='0.04'%3E%3Ccircle cx='8' cy='8' r='1'/%3E%3Ccircle cx='38' cy='38' r='1'/%3E%3Ccircle cx='22' cy='52' r='1'/%3E%3Ccircle cx='52' cy='14' r='1'/%3E%3C/g%3E%3C/svg%3E");
  }

  .wa-chat-empty-hint {
    background: rgba(31, 44, 52, 0.92);
    color: var(--wa-meta);
  }

  .wa-load-older-btn {
    background: rgba(42, 57, 66, 0.95);
    color: #53bdeb;
  }

  .wa-load-older-btn:hover:not(:disabled) {
    background: rgba(53, 68, 77, 0.98);
  }

  .msg-sender {
    color: #00a884;
  }

  .wa-composer-tool {
    color: #aebac1;
  }

  .wa-composer-tool:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
  }

  .wa-header-call-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
  }

  .wa-header-call-btn:hover {
    background: rgba(255, 255, 255, 0.2);
  }

  .settings-notify-block {
    border-top-color: #3d4f5c;
  }

  .settings-notify-status {
    color: #8696a0;
  }

  .wa-input-shell {
    border-color: rgba(255, 255, 255, 0.08);
  }

  #message-input::placeholder {
    color: #8696a0;
  }

  .wa-emoji-panel {
    background: #2a3942;
    border-color: rgba(255, 255, 255, 0.08);
  }

  .emoji-cell:hover {
    background: #3d4f5c;
  }

  .modal-content {
    background: #2a3942;
    color: var(--wa-text);
  }

  #config-panel .modal-content h3 {
    color: var(--wa-text);
  }

  #config-panel .config-hint {
    color: #b7c1c7;
  }

  #config-panel .pat-explainer {
    color: #8696a0;
  }

  #config-panel #repo-input,
  input[type='password'] {
    background: #1f2c33;
    border-color: #3d4f5c;
    color: var(--wa-text);
  }

  #config-panel .field-label {
    color: #aebac1;
  }
}

@media (max-width: 380px) {
  .bubble {
    max-width: 92%;
  }
}
