/* C.H.I.T.T.I. — Cognitive Heuristic Interface Trained for Task Integration */

.chitti-fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 90;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  padding: 0;
  cursor: pointer;
  /* Follows Admin UI palette (--primary / --brand-2) */
  background: linear-gradient(
    145deg,
    hsl(var(--primary)),
    color-mix(in oklab, hsl(var(--primary)) 70%, white) 48%,
    hsl(var(--brand-2, var(--primary)))
  );
  box-shadow:
    0 10px 28px hsl(var(--primary) / .28),
    0 0 0 1px hsl(0 0% 100% / .18) inset;
  display: grid;
  place-items: center;
  transition: transform .15s ease, box-shadow .15s ease, background .2s;
}
.chitti-fab:hover { transform: translateY(-2px) scale(1.03); }
.chitti-fab:active { transform: translateY(0) scale(0.98); }
.chitti-fab[data-state="listening"] {
  animation: chittiPulse 1.4s ease-in-out infinite;
  box-shadow:
    0 10px 28px hsl(var(--primary) / .4),
    0 0 0 3px hsl(var(--primary) / .22);
}
.chitti-fab[data-state="speaking"] {
  box-shadow:
    0 10px 28px hsl(var(--primary) / .45),
    0 0 0 3px hsl(var(--brand-2, var(--primary)) / .3);
}
.chitti-fab img,
.chitti-fab svg {
  width: 34px;
  height: 34px;
  display: block;
  pointer-events: none;
}
.chitti-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #fff;
  color: #0c4a6e;
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px hsl(220 30% 10% / .2);
}
@keyframes chittiPulse {
  0%, 100% { box-shadow: 0 10px 28px hsl(215 70% 30% / .28), 0 0 0 0 hsl(199 89% 48% / .45); }
  50% { box-shadow: 0 10px 28px hsl(215 70% 30% / .28), 0 0 0 10px hsl(199 89% 48% / 0); }
}

.chitti-panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + 64px + env(safe-area-inset-bottom));
  z-index: 91;
  width: min(360px, calc(100vw - 28px));
  border-radius: 18px;
  border: 1px solid hsl(var(--border, 214 32% 91%));
  background: hsl(var(--card, 0 0% 100%));
  color: hsl(var(--foreground, 222 47% 11%));
  box-shadow: 0 18px 50px hsl(220 30% 10% / .18);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chittiIn .18s ease-out;
}
.chitti-panel[hidden] { display: none !important; }
@keyframes chittiIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: none; }
}

.chitti-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 10px;
  background:
    linear-gradient(135deg, hsl(239 84% 67% / .12), hsl(199 89% 48% / .08)),
    hsl(var(--muted, 210 40% 96%) / .55);
  border-bottom: 1px solid hsl(var(--border, 214 32% 91%));
}
.chitti-panel-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 4px 12px hsl(215 70% 30% / .18);
}
.chitti-panel-mark img { width: 100%; height: 100%; display: block; }
.chitti-panel-copy { min-width: 0; flex: 1; }
.chitti-panel-kicker {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground, 215 16% 47%));
}
.chitti-panel-title {
  margin: 1px 0 0;
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.chitti-panel-sub {
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.35;
  color: hsl(var(--muted-foreground, 215 16% 47%));
}
.chitti-panel-close {
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground, 215 16% 47%));
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.chitti-panel-close:hover { background: hsl(var(--muted, 210 40% 96%)); color: inherit; }

.chitti-bubble {
  margin: 12px;
  padding: 11px 12px;
  border-radius: 14px;
  background: hsl(var(--muted, 210 40% 96%) / .7);
  border: 1px solid hsl(var(--border, 214 32% 91%));
  font-size: 13.5px;
  line-height: 1.45;
  min-height: 52px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}
.chitti-bubble[data-tone="ok"] {
  border-color: hsl(142 50% 45% / .35);
  background: hsl(142 40% 94%);
}
.chitti-bubble[data-tone="err"] {
  border-color: hsl(0 70% 55% / .3);
  background: hsl(0 80% 96%);
}
.chitti-bubble[data-tone="listen"] {
  border-color: hsl(239 84% 67% / .35);
  background: hsl(239 90% 96%);
}

.chitti-meta {
  margin: -4px 12px 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: hsl(var(--muted-foreground, 215 16% 47%));
}

.chitti-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 12px;
}
.chitti-actions .btn-sm,
.chitti-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid hsl(var(--border, 214 32% 91%));
  background: hsl(var(--card, 0 0% 100%));
  color: inherit;
  cursor: pointer;
}
.chitti-actions .chitti-primary {
  border-color: transparent;
  background: hsl(var(--primary, 221 83% 53%));
  color: #fff;
}
.chitti-actions button:disabled { opacity: .55; cursor: not-allowed; }

.chitti-compose {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  align-items: center;
}
.chitti-file { display: none; }
.chitti-compose input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid hsl(var(--border, 214 32% 91%));
  background: hsl(var(--card, 0 0% 100%));
  color: inherit;
  outline: none;
}
.chitti-compose input[type="text"]:focus {
  border-color: hsl(var(--primary, 221 83% 53%) / .55);
  box-shadow: 0 0 0 3px hsl(var(--primary, 221 83% 53%) / .12);
}
.chitti-compose button {
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid hsl(var(--border, 214 32% 91%));
  background: hsl(var(--card, 0 0% 100%));
  color: inherit;
  cursor: pointer;
  flex-shrink: 0;
}
.chitti-compose #chitti-send {
  background: hsl(var(--primary, 221 83% 53%));
  color: #fff;
  border-color: transparent;
}
[data-theme="dark"] .chitti-compose input[type="text"] {
  background: hsl(217 25% 14%);
  border-color: hsl(217 20% 24%);
}

.chitti-hints {
  padding: 0 12px 12px;
  font-size: 11px;
  color: hsl(var(--muted-foreground, 215 16% 47%));
  line-height: 1.4;
}

[data-theme="dark"] .chitti-panel {
  background: hsl(222 47% 8%);
  border-color: hsl(217 20% 22%);
  color: hsl(210 40% 98%);
}
[data-theme="dark"] .chitti-bubble {
  background: hsl(217 25% 14%);
  border-color: hsl(217 20% 24%);
}
[data-theme="dark"] .chitti-bubble[data-tone="ok"] { background: hsl(142 30% 14%); }
[data-theme="dark"] .chitti-bubble[data-tone="err"] { background: hsl(0 40% 16%); }
[data-theme="dark"] .chitti-bubble[data-tone="listen"] { background: hsl(199 40% 14%); }

@media (max-width: 520px) {
  .chitti-fab { width: 52px; height: 52px; border-radius: 16px; }
  .chitti-panel { bottom: calc(14px + 60px + env(safe-area-inset-bottom)); }
}
