/* Emma AI — the assistant of Vepra AI: the launcher and the window on every page of the site and the app.
   Own tokens (the brand colour is not approved yet), both colour schemes keyed like app.css/site.css on
   html[data-theme], reduced motion honoured, no inline styles (CSP). */

:root {
  --emma-bg: #173f5f; /* launcher; white icon 10.4:1 */
  --emma-on-bg: #ffffff;
  --emma-surface: #ffffff;
  --emma-surface-2: #f2f5f8;
  --emma-ink: #17212b; /* 15.4:1 on white */
  --emma-muted: #566270; /* 6.4:1 on white */
  --emma-line: #d9e0e7;
  --emma-accent: #0f766e; /* 5.9:1 on white */
  --emma-on-accent: #ffffff;
  --emma-me: #173f5f; /* the person's bubble */
  --emma-on-me: #ffffff;
  --emma-bad: #b3261e; /* 6.4:1 on white */
  --emma-notice-bg: #e6f4f1;
  --emma-notice-ink: #0b4f4a; /* 8.6:1 on the notice background */
  --emma-shadow: 0 18px 48px -20px rgba(23, 63, 95, 0.35), 0 4px 14px -8px rgba(23, 63, 95, 0.25);
  --emma-focus: #0f766e;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme='dark'] {
    --emma-bg: #173f5f;
    --emma-on-bg: #ffffff;
    --emma-surface: #141d30;
    --emma-surface-2: #1b263b;
    --emma-ink: #eef3fb; /* 15.2:1 on the surface */
    --emma-muted: #a7b3c4; /* 8.7:1 */
    --emma-line: #2a3750;
    --emma-accent: #5eead4; /* 11.1:1 */
    --emma-on-accent: #0b1220;
    --emma-me: #1f4a73; /* white 8:1 */
    --emma-on-me: #ffffff;
    --emma-bad: #f28b85; /* 6.5:1 */
    --emma-notice-bg: #12312d;
    --emma-notice-ink: #a7f3e6;
    --emma-shadow: 0 18px 48px -20px rgba(0, 0, 0, 0.7), 0 4px 14px -8px rgba(0, 0, 0, 0.6);
    --emma-focus: #5eead4;
  }
}
:root[data-theme='dark'] {
  --emma-bg: #173f5f;
  --emma-on-bg: #ffffff;
  --emma-surface: #141d30;
  --emma-surface-2: #1b263b;
  --emma-ink: #eef3fb;
  --emma-muted: #a7b3c4;
  --emma-line: #2a3750;
  --emma-accent: #5eead4;
  --emma-on-accent: #0b1220;
  --emma-me: #1f4a73;
  --emma-on-me: #ffffff;
  --emma-bad: #f28b85;
  --emma-notice-bg: #12312d;
  --emma-notice-ink: #a7f3e6;
  --emma-shadow: 0 18px 48px -20px rgba(0, 0, 0, 0.7), 0 4px 14px -8px rgba(0, 0, 0, 0.6);
  --emma-focus: #5eead4;
}

/* ---------- launcher ---------- */
.emma-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: var(--emma-bg);
  color: var(--emma-on-bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--emma-shadow);
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.emma-launcher:hover {
  transform: translateY(-1px);
}
.emma-launcher:focus-visible {
  outline: 3px solid var(--emma-focus);
  outline-offset: 3px;
}
.emma-launcher .icon {
  width: 26px;
  height: 26px;
}

/* ---------- window ---------- */
.emma-window {
  position: fixed;
  right: 24px;
  bottom: 92px;
  width: 380px;
  max-width: calc(100vw - 48px);
  max-height: min(600px, calc(100vh - 96px - var(--emma-top, 0px)));
  max-height: min(600px, calc(100dvh - 96px - var(--emma-top, 0px)));
  display: flex;
  flex-direction: column;
  background: var(--emma-surface);
  color: var(--emma-ink);
  border: 1px solid var(--emma-line);
  border-radius: 20px;
  box-shadow: var(--emma-shadow);
  z-index: 41;
  overflow: hidden;
  font-family: var(--font-body, 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, sans-serif);
  font-size: 15px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px);
  visibility: hidden;
  transition: opacity 180ms ease, transform 180ms ease, visibility 0s linear 180ms;
}
.emma-window.open {
  opacity: 1;
  transform: none;
  visibility: visible;
  transition: opacity 180ms ease, transform 180ms ease, visibility 0s;
}
.emma-window a {
  color: var(--emma-accent);
}
.emma-window :focus-visible {
  outline: 2px solid var(--emma-focus);
  outline-offset: 2px;
}

.emma-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 8px 10px 16px;
  border-bottom: 1px solid var(--emma-line);
}
.emma-head-text {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 4px;
}
.emma-title {
  margin: 0;
  font-family: var(--font-display, 'Manrope', 'Segoe UI', system-ui, sans-serif);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--emma-ink);
}
.emma-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--emma-muted);
}
.emma-status {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--emma-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.emma-status:empty {
  display: none;
}
.emma-status::before {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emma-muted);
}
.emma-status.ready::before {
  background: var(--emma-accent);
}
.emma-status.error::before {
  background: var(--emma-bad);
}
.emma-head-tools {
  display: flex;
  gap: 2px;
  flex: none;
}
.emma-iconbtn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--emma-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.emma-iconbtn:hover {
  background: var(--emma-surface-2);
}
.emma-iconbtn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- log ---------- */
.emma-log {
  flex: 1 1 auto;
  min-height: 140px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.emma-msg {
  max-width: 92%;
}
.emma-msg.me {
  align-self: flex-end;
  padding: 8px 12px;
  border-radius: 16px 16px 4px 16px;
  background: var(--emma-me);
  color: var(--emma-on-me);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.emma-msg.emma {
  align-self: flex-start;
  padding: 10px 12px;
  border-radius: 16px 16px 16px 4px;
  background: var(--emma-surface-2);
  display: grid;
  gap: 8px;
}
.emma-msg p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.emma-details {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  display: grid;
  gap: 2px;
}
.emma-muted {
  font-size: 13px;
  color: var(--emma-muted);
}
.emma-cites {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--emma-muted);
  display: grid;
  gap: 2px;
}
.emma-notice {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--emma-notice-bg);
  color: var(--emma-notice-ink);
}
.emma-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.emma-chip {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border: 1px solid var(--emma-accent);
  border-radius: 14px;
  background: var(--emma-surface);
  color: var(--emma-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.emma-chip:hover {
  background: var(--emma-notice-bg);
}
.emma-chip:disabled {
  opacity: 0.55;
  cursor: default;
}
.emma-chip.k-back,
.emma-chip.k-change,
.emma-chip.k-new {
  border-color: var(--emma-line);
  color: var(--emma-ink);
  font-weight: 500;
}
.emma-change {
  flex: 1 1 100%;
  display: flex;
  gap: 6px;
  margin-top: 2px;
}
.emma-change .emma-input {
  flex: 1 1 auto;
}
.emma-thinking {
  font-size: 13px;
  color: var(--emma-muted);
}
.emma-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--emma-bad);
}
.emma-retry {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid currentColor;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.emma-note {
  font-size: 13px;
  color: var(--emma-muted);
  text-align: center;
}

/* ---------- composer ---------- */
.emma-foot {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--emma-line);
  display: grid;
  gap: 6px;
}
.emma-usage {
  margin: 0;
  font-size: 12px;
  color: var(--emma-muted);
}
.emma-usage:empty {
  display: none;
}
.emma-form {
  display: flex;
  gap: 8px;
}
.emma-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--emma-line);
  border-radius: 14px;
  background: var(--emma-surface);
  color: var(--emma-ink);
  font: inherit;
  font-size: 16px; /* phones do not zoom into a 16px field */
}
.emma-input::placeholder {
  color: var(--emma-muted);
}
.emma-input:disabled {
  opacity: 0.6;
}
.emma-send {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--emma-accent);
  color: var(--emma-on-accent);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.emma-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .emma-launcher {
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--emma-nav, 0px) + var(--emma-lift, 0px));
  }
  .emma-window {
    inset: auto 0 0 0;
    width: auto;
    max-width: none;
    height: calc(100vh - var(--emma-kb, 0px));
    height: calc(100dvh - var(--emma-kb, 0px));
    max-height: calc(100vh - var(--emma-kb, 0px));
    max-height: calc(100dvh - var(--emma-kb, 0px));
    border-radius: 20px 20px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
}

/* ---------- right-to-left, reduced motion, print ---------- */
[dir='rtl'] .emma-launcher {
  right: auto;
  left: 24px;
}
[dir='rtl'] .emma-window {
  right: auto;
  left: 24px;
}
@media (max-width: 760px) {
  [dir='rtl'] .emma-launcher {
    left: calc(16px + env(safe-area-inset-left, 0px));
  }
  [dir='rtl'] .emma-window {
    left: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .emma-launcher,
  .emma-window,
  .emma-window.open {
    transition: none;
  }
}
@media print {
  .emma-launcher,
  .emma-window {
    display: none;
  }
}
