#adx-ai-chat {
  --adx-ink: #171a14;
  --adx-muted: #697064;
  --adx-line: #dfe3d9;
  --adx-paper: #fbfcf8;
  --adx-soft: #f1f3ed;
  --adx-accent: #d4fa49;
  color: var(--adx-ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#adx-ai-chat *, #adx-ai-chat *::before, #adx-ai-chat *::after { box-sizing: border-box; }
#adx-ai-chat [hidden] { display: none !important; }

.adx-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9998;
  display: flex;
  height: 58px;
  align-items: center;
  gap: 11px;
  overflow: hidden;
  padding: 0 19px 0 8px;
  border: 1px solid #3a4034;
  border-radius: 18px;
  background: var(--adx-ink);
  color: #fff;
  box-shadow: 0 12px 34px #11140f40;
  font: inherit;
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.adx-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px #11140f40; }
.adx-fab:active { transform: translateY(0); }
.adx-fab-icon { display: grid; width: 40px; height: 40px; flex: 0 0 auto; place-items: center; border-radius: 12px; background: var(--adx-accent); color: var(--adx-ink); font-size: 12px; font-weight: 900; letter-spacing: -.3px; }
.adx-fab-status { width: 7px; height: 7px; flex: 0 0 auto; margin-left: 2px; border-radius: 50%; background: var(--adx-accent); box-shadow: 0 0 0 3px #d4fa4920; }
.adx-fab::after { content: ""; position: absolute; bottom: 0; left: 0; width: 42px; height: 2px; border-radius: 2px; background: var(--adx-accent); transform: translateX(-48px); animation: adx-signal 3.6s cubic-bezier(.4,0,.2,1) infinite; }
@keyframes adx-signal { 0%,34% { transform: translateX(-48px); opacity: 0; } 42% { opacity: 1; } 76% { transform: translateX(210px); opacity: 1; } 84%,100% { transform: translateX(210px); opacity: 0; } }

.adx-panel {
  position: fixed;
  right: 22px;
  bottom: 84px;
  z-index: 9999;
  display: flex;
  width: min(420px, calc(100vw - 28px));
  height: min(650px, calc(100dvh - 110px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--adx-line);
  border-radius: 24px;
  background: var(--adx-paper);
  box-shadow: 0 28px 80px #10130e2e, 0 8px 24px #10130e1a;
}

.adx-panel header {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px 12px 16px;
  background: var(--adx-ink);
  color: #fff;
}

.adx-heading { display: flex; min-width: 0; align-items: center; gap: 11px; }
.adx-back { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; padding: 0; border: 0; border-radius: 11px; background: #ffffff10; color: #fff; font: 24px/1 system-ui,sans-serif; cursor: pointer; }
.adx-back:hover { background: #ffffff1c; }
.adx-heading > div { min-width: 0; }
.adx-heading b { display: block; font-size: 15px; line-height: 1.25; }
.adx-heading span:not(.adx-avatar) { display: flex; align-items: center; gap: 6px; color: #cbd0c5; font-size: 12px; }
.adx-heading i { width: 7px; height: 7px; border-radius: 50%; background: var(--adx-accent); box-shadow: 0 0 0 3px #d4fa4920; }

.adx-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--adx-accent);
  color: var(--adx-ink);
  font-weight: 850;
}

.adx-close {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font: 400 27px/1 system-ui, sans-serif;
  cursor: pointer;
  transition: background .16s ease;
}

.adx-close:hover { background: #ffffff12; }

.adx-gate, .adx-modes {
  flex: 1;
  overflow: auto;
  background: var(--adx-soft);
}

.adx-gate { display: grid; place-items: center; padding: 28px; }
.adx-gate-card { width: min(100%,340px); padding: 24px; border: 1px solid var(--adx-line); border-radius: 18px; background: #fff; box-shadow: 0 10px 30px #11140f0a; }
.adx-gate-card h2, .adx-mode-intro h2 { margin: 5px 0 8px; font-size: 22px; line-height: 1.2; }
.adx-gate-card > p:not(.adx-gate-status) { margin: 0 0 18px; color: var(--adx-muted); font-size: 13px; }
.adx-gate-card altcha-widget { display: block; width: 100%; --altcha-max-width: 100%; }
.adx-gate-status { min-height: 20px; margin: 12px 0 0; color: var(--adx-muted); font-size: 13px; }

.adx-modes { padding: 26px 22px; }
.adx-mode-intro { margin-bottom: 18px; }
.adx-mode-card { display: grid; width: 100%; grid-template-columns: 44px minmax(0,1fr) 24px; align-items: center; gap: 12px; margin-top: 12px; padding: 16px; border: 1px solid var(--adx-line); border-radius: 16px; background: #fff; color: var(--adx-ink); text-align: left; cursor: pointer; transition: border-color .16s ease,transform .16s ease,box-shadow .16s ease; }
.adx-mode-card:hover { transform: translateY(-2px); border-color: #a8b09f; box-shadow: 0 9px 22px #11140f0c; }
.adx-mode-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 13px; background: var(--adx-ink); color: var(--adx-accent); font-size: 12px; font-weight: 800; }
.adx-mode-card b, .adx-mode-card small { display: block; }
.adx-mode-card b { font-size: 16px; line-height: 1.25; }
.adx-mode-card small { margin-top: 4px; color: var(--adx-muted); font-size: 12px; }
.adx-mode-arrow { color: #7b8377; font-size: 22px; }
.adx-serial {
  display: grid;
  flex: 1;
  overflow: auto;
  place-items: center;
  padding: 28px;
  background: var(--adx-soft);
}

.adx-serial-card {
  display: grid;
  width: min(100%, 330px);
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--adx-line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 30px #11140f0a;
}

.adx-serial-kicker { color: var(--adx-muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.adx-serial label { font-size: 20px; font-weight: 780; line-height: 1.2; }
.adx-serial small { color: var(--adx-muted); font-size: 13px; }

.adx-serial input:not([type=file]), .adx-form textarea {
  width: 100%;
  border: 1px solid #cdd2c7;
  outline: none;
  background: #fff;
  color: var(--adx-ink);
  font: inherit;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.adx-serial input:not([type=file]) { height: 46px; border-radius: 12px; padding: 0 13px; }
.adx-serial input:not([type=file]):focus, .adx-form textarea:focus { border-color: #777e70; box-shadow: 0 0 0 3px #171a1414; }

.serial-file-button, .serial-save {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 12px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.serial-file-button { border: 1px solid var(--adx-line); background: #fff; color: var(--adx-ink); }
.serial-file-button img { width: 18px; height: 18px; }
.serial-save { border: 1px solid var(--adx-ink); background: var(--adx-ink); color: var(--adx-accent); }
.serial-status { min-height: 20px; margin: 0; color: var(--adx-muted); font-size: 13px; }

.adx-chat-meta { padding: 8px 15px; border-bottom: 1px solid var(--adx-line); background: #fff; color: var(--adx-muted); font-size: 11px; text-align: center; }

.adx-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 18px 16px 22px;
  background: var(--adx-soft);
  overscroll-behavior: contain;
  scrollbar-color: #bcc2b6 transparent;
  scrollbar-width: thin;
}

.adx-message {
  width: fit-content;
  max-width: 84%;
  padding: 10px 13px;
  border: 1px solid var(--adx-line);
  border-radius: 15px 15px 15px 5px;
  background: #fff;
  box-shadow: 0 2px 8px #11140f08;
  overflow-wrap: anywhere;
}

.adx-message.user {
  align-self: flex-end;
  border-color: var(--adx-ink);
  border-radius: 15px 15px 5px 15px;
  background: var(--adx-ink);
  color: #fff;
}

.adx-message.typing { color: var(--adx-muted); font-style: italic; }
.adx-message a { color: #3d5900; font-weight: 700; text-underline-offset: 2px; }
.adx-message p { margin: 0; }
.adx-message p + p, .adx-message p + ul, .adx-message p + ol, .adx-message ul + p, .adx-message ol + p { margin-top: 9px; }
.adx-message ul, .adx-message ol { margin: 7px 0 0; padding-left: 20px; }
.adx-message li + li { margin-top: 4px; }
.adx-message h4 { margin: 0 0 7px; font-size: 15px; line-height: 1.3; }
.adx-message code { padding: 1px 5px; border-radius: 5px; background: #e8ebe3; font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }
.adx-message.user a { color: var(--adx-accent); }
.adx-message.user code { background: #ffffff18; }

.adx-form {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: end;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--adx-line);
  background: #fff;
}
.adx-form.is-chooser { grid-template-columns: minmax(0,1fr) 42px; }
.adx-form.is-chooser .chat-file-button { display: none; }
.adx-form.is-limit-reached { grid-template-columns: minmax(0,1fr); }
.adx-form.is-limit-reached .chat-file-button, .adx-form.is-limit-reached textarea, .adx-form.is-limit-reached .chat-send-button { display: none; }
.adx-limit-notice { display: grid; grid-column: 1 / -1; gap: 9px; margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--adx-soft); color: var(--adx-muted); font-size: 13px; text-align: center; }
.adx-limit-notice a { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; justify-self: center; padding: 0 16px; border-radius: 11px; background: var(--adx-ink); color: var(--adx-accent); font-weight: 750; text-decoration: none; }
.adx-limit-notice a:hover { background: #24281f; }

.adx-form textarea {
  min-width: 0;
  min-height: 42px;
  max-height: 124px;
  resize: none;
  overflow-y: auto;
  border-color: transparent;
  border-radius: 14px;
  background: var(--adx-soft);
  padding: 10px 12px;
  line-height: 1.45;
}

.adx-form button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border-radius: 13px;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.adx-form button:active { transform: scale(.96); }
.chat-file-button { border: 1px solid var(--adx-line); background: #fff; color: var(--adx-ink); }
.chat-file-button:hover { background: var(--adx-soft); border-color: #c7ccc2; }
.chat-send-button { border: 1px solid var(--adx-ink); background: var(--adx-ink); color: var(--adx-accent); }
.chat-send-button:hover { background: #24281f; }
.adx-form button img { width: 20px; height: 20px; }
.chat-send-button img { filter: brightness(0) saturate(100%) invert(90%) sepia(99%) saturate(686%) hue-rotate(25deg) brightness(105%); }

.chat-file-status {
  display: none;
  grid-column: 1 / -1;
  width: fit-content;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--adx-soft);
  color: var(--adx-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-status:not(:empty) { display: block; }

#adx-ai-chat button:focus-visible, #adx-ai-chat input:focus-visible, #adx-ai-chat textarea:focus-visible {
  outline: 3px solid #a6c530;
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .adx-fab { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); height: 54px; padding-right: 16px; border-radius: 16px; font-size: 15px; }
  .adx-fab-icon { width: 38px; height: 38px; border-radius: 11px; }
  .adx-panel {
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .adx-panel header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .adx-gate { padding: 20px; }
  .adx-modes { padding: 22px 16px; }
  .adx-serial { padding: 20px; }
  .adx-serial-card { padding: 20px; }
  .adx-messages { padding: 16px 12px 18px; }
  .adx-message { max-width: 88%; }
  .adx-form { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) { .adx-fab::after { animation: none; transform: none; left: 8px; width: calc(100% - 16px); opacity: .65; } }

@media (prefers-reduced-motion: reduce) {
  .adx-fab, .adx-form button { transition: none; animation: none; }
}
