.ai-settings-trigger {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: var(--gold-soft);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-50%);
  transition: 180ms ease;
}

.ai-settings-trigger:hover,
.ai-settings-trigger:focus-visible {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}

.ai-settings-trigger svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-brand {
  position: relative;
}

.side-brand > div:nth-of-type(2) {
  padding-right: 34px;
}

.ai-floating-button {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 72;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 54px;
  height: 54px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 999px;
  color: #fff;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.3), transparent 28%),
    linear-gradient(135deg, var(--pine) 0%, var(--pine-soft) 58%, #7a654a 100%);
  box-shadow: 0 16px 38px rgba(14, 42, 36, 0.3);
  overflow: hidden;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.ai-floating-button::before {
  content: "";
  position: absolute;
  inset: -50%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 255, 255, 0.22), transparent 32%);
  animation: ai-breathe-rotate 5.5s linear infinite;
  pointer-events: none;
}

.ai-floating-button:hover,
.ai-floating-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 20px 44px rgba(14, 42, 36, 0.36);
  outline: none;
}

.ai-floating-button svg {
  position: relative;
  width: 23px;
  height: 23px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-floating-button span {
  position: relative;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: 200ms ease;
}

.ai-floating-button:hover span,
.ai-floating-button:focus-visible span {
  max-width: 90px;
  opacity: 1;
}

@keyframes ai-breathe-rotate {
  to {
    transform: rotate(360deg);
  }
}

.ai-chat-panel {
  --ai-bg: rgba(251, 248, 242, 0.98);
  --ai-surface: #fffdf8;
  --ai-surface-soft: #f2ece1;
  --ai-border: rgba(24, 35, 31, 0.12);
  --ai-text: #18231f;
  --ai-muted: #65716d;
  position: fixed;
  right: 24px;
  bottom: 94px;
  z-index: 74;
  display: flex;
  flex-direction: column;
  width: min(430px, calc(100vw - 40px));
  height: min(680px, calc(100vh - 128px));
  border: 1px solid rgba(24, 35, 31, 0.16);
  border-radius: 22px;
  color: var(--ai-text);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.52), transparent 28%),
    var(--ai-bg);
  box-shadow: 0 30px 90px rgba(14, 42, 36, 0.26);
  overflow: hidden;
  backdrop-filter: blur(20px);
  animation: ai-panel-in 180ms ease both;
}

@keyframes ai-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 16px;
  color: #f7f3ea;
  background:
    radial-gradient(circle at 15% 0, rgba(255, 255, 255, 0.16), transparent 34%),
    linear-gradient(135deg, var(--pine-deep), var(--pine-soft));
}

.ai-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 13px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.ai-avatar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-chat-title {
  min-width: 0;
  flex: 1;
}

.ai-chat-title strong {
  display: block;
  font-size: 14px;
  letter-spacing: 0.04em;
}

.ai-chat-title small {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 11px;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  color: inherit;
  background: transparent;
  transition: 160ms ease;
}

.ai-icon-button:hover,
.ai-icon-button:focus-visible {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.ai-icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--ai-border);
  color: var(--ai-muted);
  background: color-mix(in srgb, var(--ai-surface) 84%, transparent);
  font-size: 11px;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5c9170;
  box-shadow: 0 0 0 4px rgba(92, 145, 112, 0.13);
}

.ai-status-line[data-busy="true"] .ai-status-dot {
  background: var(--gold);
  animation: ai-status-pulse 1.1s ease-in-out infinite;
}

@keyframes ai-status-pulse {
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

.ai-message-scroll {
  flex: 1;
  padding: 18px 16px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.ai-welcome {
  padding: 3px 1px 12px;
}

.ai-welcome h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
}

.ai-welcome p {
  margin: 0;
  color: var(--ai-muted);
  line-height: 1.7;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 15px;
}

.ai-suggestion {
  padding: 7px 10px;
  border: 1px solid var(--ai-border);
  border-radius: 999px;
  color: var(--ai-text);
  background: var(--ai-surface);
  font-size: 11px;
}

.ai-suggestion:hover {
  border-color: color-mix(in srgb, var(--pine) 35%, transparent);
  background: var(--ai-surface-soft);
}

.ai-message {
  display: flex;
  margin-bottom: 15px;
}

.ai-message.user {
  justify-content: flex-end;
}

.ai-message-body {
  max-width: 88%;
  padding: 11px 13px;
  border: 1px solid var(--ai-border);
  border-radius: 5px 16px 16px;
  background: var(--ai-surface);
  box-shadow: 0 5px 18px rgba(24, 42, 36, 0.05);
  word-break: break-word;
}

.ai-message.user .ai-message-body {
  border-color: transparent;
  border-radius: 16px 5px 16px 16px;
  color: #f8f5ec;
  background: linear-gradient(135deg, var(--pine), var(--pine-soft));
}

.ai-message-role {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--ai-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ai-message.user .ai-message-role {
  color: rgba(255, 255, 255, 0.64);
}

.ai-message-content {
  font-size: 13px;
  line-height: 1.72;
}

.ai-message-content > :first-child {
  margin-top: 0;
}

.ai-message-content > :last-child {
  margin-bottom: 0;
}

.ai-message-content p,
.ai-message-content ul,
.ai-message-content ol,
.ai-message-content blockquote,
.ai-message-content pre,
.ai-message-content table {
  margin: 8px 0;
}

.ai-message-content h1,
.ai-message-content h2,
.ai-message-content h3 {
  margin: 12px 0 7px;
  font-family: var(--serif);
}

.ai-message-content h1 {
  font-size: 18px;
}

.ai-message-content h2 {
  font-size: 16px;
}

.ai-message-content h3 {
  font-size: 14px;
}

.ai-message-content code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--ai-surface-soft);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}

.ai-message-content pre {
  padding: 11px;
  border-radius: 10px;
  background: #14231f;
  color: #edf5ef;
  overflow-x: auto;
}

.ai-message-content pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.ai-message-content table {
  display: block;
  max-width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
}

.ai-message-content th,
.ai-message-content td {
  padding: 6px 8px;
  border: 1px solid var(--ai-border);
  white-space: nowrap;
  text-align: left;
}

.ai-message-content blockquote {
  padding-left: 10px;
  border-left: 2px solid var(--gold);
  color: var(--ai-muted);
}

.ai-message-content a {
  color: var(--pine-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-message-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--ai-muted);
  font-size: 10px;
}

.ai-message-tools button {
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font-size: inherit;
}

.ai-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--ai-border);
  color: var(--ai-muted);
  font-size: 10px;
}

.ai-composer {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--ai-border);
  background: color-mix(in srgb, var(--ai-surface) 92%, transparent);
}

.ai-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--ai-border);
  border-radius: 15px;
  background: var(--ai-surface);
}

.ai-composer-box:focus-within {
  border-color: color-mix(in srgb, var(--pine) 44%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 9%, transparent);
}

.ai-composer textarea {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 0;
  border: 0;
  color: var(--ai-text);
  background: transparent;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.ai-send-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 11px;
  color: #fff;
  background: var(--pine);
}

.ai-send-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-send-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-composer-hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--ai-muted);
  font-size: 9px;
}

.ai-history-drawer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  color: var(--ai-text);
  background: var(--ai-bg);
}

.ai-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ai-border);
}

.ai-history-list {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.ai-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  color: var(--ai-text);
  background: transparent;
  text-align: left;
}

.ai-history-item-main {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.ai-history-item:hover {
  background: var(--ai-surface-soft);
}

.ai-history-item span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-history-item small {
  color: var(--ai-muted);
  font-size: 9px;
}

.ai-config-layer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
}

.ai-config-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 29, 25, 0.48);
  backdrop-filter: blur(5px);
}

.ai-config-dialog {
  position: relative;
  width: min(620px, calc(100vw - 32px));
  max-height: min(780px, calc(100vh - 40px));
  border: 1px solid rgba(24, 35, 31, 0.15);
  border-radius: 20px;
  color: var(--ink);
  background: var(--paper-light);
  box-shadow: 0 30px 90px rgba(14, 42, 36, 0.28);
  overflow: auto;
}

.ai-config-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.ai-config-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 23px;
}

.ai-config-header p {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.ai-config-form {
  display: grid;
  gap: 13px;
  padding: 18px 22px 22px;
}

.ai-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ai-config-form label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.ai-config-form input,
.ai-config-form select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}

.ai-config-form input:focus,
.ai-config-form select:focus {
  border-color: var(--pine-soft);
  outline: 2px solid rgba(49, 88, 78, 0.13);
}

.ai-config-note {
  padding: 10px 12px;
  border: 1px solid rgba(180, 137, 79, 0.24);
  border-radius: 10px;
  color: #6f5737;
  background: rgba(234, 220, 196, 0.42);
  font-size: 11px;
  line-height: 1.6;
}

.ai-config-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.ai-config-actions button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
}

.ai-config-actions .primary {
  color: #fff;
  border-color: var(--pine);
  background: var(--pine);
}

.ai-config-actions .danger {
  color: var(--vermillion);
}

.ai-config-status {
  margin-left: auto;
  color: var(--ink-soft);
  font-size: 11px;
}

@media (prefers-color-scheme: dark) {
  .ai-chat-panel {
    --ai-bg: rgba(21, 29, 27, 0.98);
    --ai-surface: #202b28;
    --ai-surface-soft: #2b3733;
    --ai-border: rgba(231, 239, 234, 0.13);
    --ai-text: #edf2ef;
    --ai-muted: #a8b3ae;
    border-color: rgba(231, 239, 234, 0.14);
  }

  .ai-config-dialog {
    color: #eef3f0;
    border-color: rgba(231, 239, 234, 0.14);
    background: #18231f;
  }

  .ai-config-header,
  .ai-config-form label {
    color: #b8c2bd;
  }

  .ai-config-form input,
  .ai-config-form select,
  .ai-config-actions button {
    color: #eef3f0;
    background: #22302c;
  }
}

@media (max-width: 860px) {
  .ai-settings-trigger {
    top: 18px;
    right: 18px;
  }

  .ai-floating-button {
    right: 16px;
    bottom: 78px;
    width: 50px;
    min-width: 50px;
    height: 50px;
    padding: 0 13px;
  }

  .ai-floating-button:hover span,
  .ai-floating-button:focus-visible span {
    max-width: 0;
    opacity: 0;
  }

  .ai-chat-panel {
    right: 8px;
    bottom: 70px;
    width: calc(100vw - 16px);
    height: min(78vh, 720px);
    border-radius: 18px;
  }

  .ai-config-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .ai-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100dvh - 58px);
    border-radius: 18px 18px 0 0;
  }

  .ai-message-body {
    max-width: 94%;
  }

  .ai-config-layer {
    padding: 8px;
  }

  .ai-config-dialog {
    width: 100%;
    max-height: calc(100dvh - 16px);
    border-radius: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-floating-button::before,
  .ai-status-dot {
    animation: none;
  }

  .ai-chat-panel {
    animation: none;
  }
}
