/* ================= AI LAUNCHER ================= */

.ai-launcher {
  position: fixed;
  right: 25px;
  bottom: 25px;
  z-index: var(--z-sticky);

  width: 58px;
  height: 58px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--color-primary);
  color: var(--color-bg);

  border: none;
  border-radius: 50%;
  cursor: pointer;

  box-shadow: var(--shadow-md);
  transition: var(--transition);
  opacity: 0;
  transform: translateY(15px);
  visibility: hidden;
}

.ai-launcher.active{
  transition-duration: 0.8s;
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.ai-launcher:hover {
  transform: scale(1.02);
}

.ai-launcher svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ================= AI PANEL ================= */

.ai-panel {
  position: fixed;
  right: 25px;
  bottom: 95px;
  z-index: var(--z-modal);

  width: 380px;
  height: 550px;
  max-height: calc(100dvh - 120px);

  display: flex;
  flex-direction: column;

  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;

  box-shadow: var(--shadow-md);
  overflow: visible;
  transition: all 0.4s ease;
  visibility: visible;
  opacity: 1;
  transform: translateY(-4px);
}

.ai-panel[hidden],
.ai-confirm-overlay[hidden] {
  visibility: hidden;
  opacity: 0;
  transform: translateY(0px);
}

/* ================= HEADER ================= */

.ai-header {
  min-height: 68px;
  padding: 0 18px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  border-bottom: 1px solid var(--color-border);
}

.ai-header-info,
.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-avatar {
  width: 38px;
  height: 38px;

  display: grid;
  place-items: center;

  background: var(--color-surface-alt);
  color: var(--color-primary);
  border-radius: 12px;
}

.ai-avatar svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.ai-header h3 {
  margin: 0;
  color: var(--color-text);
  font-size: 0.85rem;
  font-weight: var(--font-semibold);
}

.ai-status {
  display: block;
  margin-top: 4px;

  color: var(--color-primary);
  font-size: 0.68rem;
}

.ai-status::before {
  content: "";
  display: inline-block;

  width: 6px;
  height: 6px;
  margin-inline-end: 5px;

  background: var(--color-primary);
  border-radius: 50%;
}

.ai-icon-btn {
  width: 32px;
  height: 32px;

  display: grid;
  place-items: center;

  background: transparent;
  color: var(--color-text-muted);

  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.ai-icon-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.ai-icon-btn svg {
  width: 19px;
  height: 19px;

  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ================= MENU ================= */

.ai-menu-wrapper {
  position: relative;
}

.ai-menu {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 5;

  width: 190px;
  padding: 6px;

  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;

  box-shadow: var(--shadow-md);
}

.ai-menu[hidden] {
  display: none;
}

.ai-menu button {
  width: 100%;
  padding: 10px;

  background: transparent;
  color: var(--color-text);

  border: none;
  border-radius: 7px;
  text-align: start;
  font-size: 0.78rem;
  cursor: pointer;
}

.ai-menu button:hover {
  background: var(--color-surface-alt);
}

.ai-menu button[data-action="clear"] {
  color: #d98282;
}

/* ================= CHAT AREA ================= */

.ai-chat {
  flex: 1;
  min-height: 0;
  padding: 18px;

  overflow-y: auto;
}

.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.ai-welcome-avatar {
  width: 54px;
  height: 54px;
  margin-bottom: 15px;

  display: grid;
  place-items: center;

  background: var(--color-surface-alt);
  color: var(--color-primary);

  border-radius: 18px;
  font-size: 30px;
}

.ai-welcome h4 {
  margin: 0;
  color: var(--color-text);
  font-size: 0.9rem;
}

.ai-welcome p {
  max-width: 290px;
  margin: 10px 0 20px;

  color: var(--color-text-muted);
  font-size: 0.76rem;
  line-height: 1.8;
}

/* ================= SUGGESTIONS ================= */

.ai-suggestions {
  width: 100%;
  display: grid;
  gap: 8px;
}

.ai-suggestion {
  width: 100%;
  padding: 11px 13px;

  background: var(--color-surface-alt);
  color: var(--color-text);

  border: 1px solid var(--color-border);
  border-radius: 10px;

  text-align: start;
  font-size: 0.74rem;
  line-height: 1.5;

  cursor: pointer;
  transition: var(--transition);
}

.ai-suggestion:hover {
  border-color: var(--color-primary);
  transform: translateX(2px);
}

/* ================= MESSAGES ================= */

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.ai-message {
  max-width: 88%;
  padding: 11px 13px;

  border-radius: 13px;

  font-size: 0.78rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.ai-message.user {
  align-self: flex-end;

  background: var(--color-primary);
  color: var(--color-bg);

  border-bottom-right-radius: 4px;
}

.ai-message.assistant {
  align-self: flex-start;

  background: var(--color-surface-alt);
  color: var(--color-text);

  border-bottom-left-radius: 4px;
}

.ai-message {
  font-family: "Vazirmatn", sans-serif;
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.ai-message > p {
  margin: 0;
  font-family: inherit;
  line-height: inherit;
  white-space: pre-wrap;
}

.ai-message h1,
.ai-message h2,
.ai-message h3 {
  margin: 0 0 8px;
  color: inherit;
  font-weight: var(--font-semibold);
  line-height: 1.5;
}

.ai-message h1 {
  font-size: 1rem;
}

.ai-message h2 {
  font-size: 0.92rem;
}

.ai-message h3 {
  font-size: 0.84rem;
}

.ai-message ul,
.ai-message ol {
  margin: 5px 0;
  padding-inline-start: 22px;
}

.ai-message li + li {
  margin-top: 3px;
}

.ai-message a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.ai-message.user a {
  color: inherit;
}

.ai-message strong {
  font-weight: var(--font-bold);
}

.ai-message code:not(pre code) {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--color-bg);
  direction: ltr;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.ai-message pre {
  max-width: 100%;
  margin: 8px 0 2px;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 9px;
  background: var(--color-bg);
  direction: ltr;
  text-align: left;
}

.ai-message pre code {
  display: block;
  color: var(--color-text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.72rem;
  line-height: 1.6;
  white-space: pre;
}

/* ================= INPUT ================= */

.ai-input-area {
  display: flex;
  align-items: center;
  gap: 8px;

  margin: 0 14px;
  padding: 7px 8px 7px 14px;

  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);

  background: var(--color-bg);
}

.ai-input-area:focus-within {
  border-color: var(--color-primary);
}

.ai-input-area input {
  flex: 1;
  min-width: 0;

  background: transparent;
  color: var(--color-text);

  border: none;
  outline: none;

  font: inherit;
  font-size: 0.78rem;
}

.ai-input-area input::placeholder {
  color: var(--color-text-muted);
}

.ai-input-area button {
  width: 36px;
  height: 36px;
  flex-shrink: 0;

  display: grid;
  place-items: center;

  background: var(--color-primary);
  color: var(--color-bg);

  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.ai-input-area button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-input-area button svg {
  width: 18px;
  height: 18px;

  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ================= DISCLAIMER ================= */

.ai-disclaimer {
  margin: 10px 12px 12px;

  color: var(--color-text-muted);
  text-align: center;
  font-size: 0.62rem;
}

/* ================= CONFIRM MODAL ================= */

.ai-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) + 1);

  display: grid;
  place-items: center;

  padding: 20px;
  background: rgb(0 0 0 / 55%);
}

.ai-confirm-box {
  width: 100%;
  max-width: 340px;
  padding: 24px;

  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
}

.ai-confirm-box h3 {
  margin: 0;
  color: var(--color-text);
  font-size: 1rem;
}

.ai-confirm-box p {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.7;
}

.ai-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.ai-confirm-actions button {
  padding: 9px 14px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
}

#ai-cancel-clear {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

#ai-confirm-clear {
  background: #a94d4d;
  color: white;
  border-color: #a94d4d;
}

/* ================= RESPONSIVE ================= */

