/* Ayra — presença de luz sobre o vazio.
   Gelo (#6FE3FF) = o que é seu. Halo (#FFE9B8) = o que é dela. */
@property --s { syntax: "<length>"; inherits: true; initial-value: 96px; }

:root {
  --void: #050814;
  --deep: #1b2352;
  --ink: #e6ecf7;
  --muted: #8b97b3;
  --ion: #6fe3ff;
  --halo: #ffe9b8;
  --glass: rgba(150, 180, 255, .06);
  --edge: rgba(150, 190, 255, .16);
  --danger: #ff8a8a;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Unbounded", "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--void); color: var(--ink);
  font: 300 16px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ion); outline-offset: 3px; }

.aurora {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60vmax 40vmax at 12% 108%, rgba(27, 35, 82, .95), transparent 70%),
    radial-gradient(45vmax 32vmax at 92% -8%, rgba(111, 227, 255, .10), transparent 70%),
    radial-gradient(30vmax 22vmax at 50% 42%, rgba(255, 233, 184, .05), transparent 70%);
}

/* ---------- Presença (a esfera) ---------- */
.presence { --s: 96px; position: relative; width: var(--s); height: var(--s); flex: none; transition: --s .6s cubic-bezier(.2, .7, .2, 1); }
.presence.xl { --s: 132px; margin: 0 auto; }
.presence .core {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fffaf0 0, var(--halo) 20%, #93b8ff 56%, var(--deep) 100%);
  box-shadow: 0 0 calc(var(--s) * .55) calc(var(--s) * .05) rgba(111, 227, 255, .28),
              0 0 calc(var(--s) * 1.3) rgba(255, 233, 184, .10);
  animation: breathe 7s ease-in-out infinite;
}
.presence .ring {
  position: absolute; inset: -16%; border-radius: 50%; opacity: 0; transition: opacity .4s;
  background: conic-gradient(from 0deg, transparent 0 62%, rgba(111, 227, 255, .95) 88%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
  animation: spin 1.5s linear infinite;
}
.presence::before, .presence::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--ion); opacity: 0; pointer-events: none;
}
@keyframes breathe { 50% { transform: scale(1.05); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ripple { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(2.1); opacity: 0; } }
@keyframes speak { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }

body[data-state="listening"] .presence::before { animation: ripple 2.4s ease-out infinite; }
body[data-state="listening"] .presence::after  { animation: ripple 2.4s ease-out 1.2s infinite; }
body[data-state="thinking"] .presence .ring { opacity: 1; }
body[data-state="speaking"] .presence .core {
  animation: speak 1.15s ease-in-out infinite;
  box-shadow: 0 0 calc(var(--s) * .6) calc(var(--s) * .08) rgba(255, 233, 184, .42),
              0 0 calc(var(--s) * 1.4) rgba(111, 227, 255, .16);
}

/* ---------- Acesso ---------- */
.auth { position: relative; z-index: 1; height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.auth-card h1 { font: 500 2.2rem/1 var(--display); letter-spacing: .06em; margin: 34px 0 10px; }
.tagline { color: var(--muted); margin: 0 0 30px; }
#auth-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
#auth-form input:not([type=checkbox]) {
  width: 100%; padding: 14px 16px; border-radius: 14px; color: var(--ink); font: inherit;
  background: var(--glass); border: 1px solid var(--edge);
}
#auth-form input::placeholder, #input::placeholder { color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .84rem; color: var(--muted); }
.check input { margin-top: 4px; accent-color: var(--ion); flex: none; }
.primary {
  padding: 14px; border: 0; border-radius: 999px; font-weight: 500;
  background: var(--ion); color: #04101a; transition: transform .15s, box-shadow .2s;
}
.primary:hover { box-shadow: 0 0 28px rgba(111, 227, 255, .4); }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .5; cursor: wait; }
.error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: .88rem; text-align: center; }
.link { background: none; border: 0; color: var(--muted); padding: 6px 0; text-align: left; font-size: .86rem; }
.link:hover { color: var(--ink); }
.link.danger:hover { color: var(--danger); }
.auth-card > .link { display: block; margin: 8px auto 0; text-align: center; }

/* ---------- Chat ---------- */
.chat { position: relative; z-index: 1; height: 100%; }
.pane { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.pane header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; color: var(--muted); font-size: .9rem; }
.stage { display: grid; place-items: center; padding: 8px 0 14px; }
.pane:has(#messages .msg:nth-child(2)) .presence { --s: 44px; }

.icon-btn {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  transition: color .2s, background .2s, border-color .2s;
}
.icon-btn:hover { color: var(--ink); background: var(--glass); }
.icon-btn svg, .send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { color: var(--ion); border-color: var(--ion); background: rgba(111, 227, 255, .1); }
.icon-btn.quiet { border: 0; }

#messages {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 26px;
  padding: 8px max(20px, calc(50% - 350px)) 24px;
  scrollbar-width: thin; scrollbar-color: var(--edge) transparent;
}
.msg { max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant {
  max-width: 62ch; padding-left: 18px; font-size: 1.08rem; line-height: 1.75; color: #dbe5fb;
  border-left: 1px solid rgba(255, 233, 184, .55);
}
.msg.user {
  align-self: flex-end; max-width: 80%; padding: 10px 16px; border-radius: 18px 18px 4px 18px;
  background: rgba(111, 227, 255, .09); border: 1px solid rgba(111, 227, 255, .22); color: var(--ink);
}
.msg.error { color: var(--danger); border-left-color: var(--danger); }

.voice-status { text-align: center; color: var(--halo); font-size: .82rem; min-height: 1.2em; margin: 0 0 6px; }
#composer {
  width: min(720px, calc(100% - 28px)); margin: 0 auto; display: flex; align-items: flex-end; gap: 4px;
  padding: 6px 6px 6px 8px; border-radius: 28px; background: var(--glass); border: 1px solid var(--edge);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  transition: border-color .2s, box-shadow .2s;
}
#composer:focus-within { border-color: rgba(111, 227, 255, .5); box-shadow: 0 0 34px rgba(111, 227, 255, .10); }
#input {
  flex: 1; resize: none; max-height: 160px; padding: 10px 6px; border: 0; background: transparent;
  color: var(--ink); font: inherit; outline: none;
}
.send {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--ion); color: #04101a; transition: transform .15s, box-shadow .2s;
}
.send:hover { box-shadow: 0 0 22px rgba(111, 227, 255, .45); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .35; cursor: wait; box-shadow: none; }

.foot { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); text-align: center; }
.pause-wrap { display: block; color: var(--muted); font-size: .76rem; margin-bottom: 4px; }
.pause-wrap select { background: var(--glass); color: var(--ink); border: 1px solid var(--edge); border-radius: 8px; padding: 2px 6px; font: inherit; }
.disclaimer { color: var(--muted); font-size: .74rem; margin: 0 auto; max-width: 62ch; opacity: .8; }

/* ---------- Gaveta de histórico ---------- */
#sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 5; width: min(320px, 86vw);
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(8, 12, 30, .92); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-right: 1px solid var(--edge);
  transform: translateX(-102%); transition: transform .35s cubic-bezier(.2, .7, .2, 1);
}
#sidebar.open { transform: none; box-shadow: 0 0 80px rgba(0, 0, 0, .7); }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 16px; }
.brand { font: 500 1.1rem var(--display); letter-spacing: .06em; }
.ghost { background: transparent; border: 1px solid var(--edge); border-radius: 999px; padding: 6px 14px; font-size: .84rem; color: var(--ink); }
.ghost:hover { border-color: var(--ion); }
#conv-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
#conv-list li { display: flex; align-items: center; border-radius: 12px; }
#conv-list li.active { background: var(--glass); }
#conv-list li:hover { background: var(--glass); }
#conv-list button.open { flex: 1; text-align: left; background: none; border: 0; padding: 10px 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
#conv-list button.del { background: none; border: 0; color: var(--muted); padding: 8px 10px; opacity: 0; transition: opacity .2s; }
#conv-list li:hover button.del, #conv-list button.del:focus-visible { opacity: 1; }
.side-foot { padding: 14px 18px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--edge); display: flex; flex-direction: column; align-items: flex-start; color: var(--muted); font-size: .84rem; }
#user-name { color: var(--ink); margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
}

/* Tela vazia: só a saudação, centralizada, logo abaixo da esfera */
.pane:not(:has(#messages .msg:nth-child(2))) .presence { --s: 116px; }
#messages .msg.assistant:only-child {
  align-self: center; text-align: center; max-width: 30ch; padding-left: 0; border-left: 0;
  font-size: 1.4rem; line-height: 1.55; font-weight: 300; color: var(--ink); margin-top: 6px;
}
.side-opt { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 6px 0; font-size: .86rem; }
.side-opt select { background: var(--glass); color: var(--ink); border: 1px solid var(--edge); border-radius: 8px; padding: 3px 8px; font: inherit; }

/* ---------- Modo trabalho ---------- */
.work-entry { margin: 0 16px 10px; padding: 11px 14px; border-radius: 14px; border: 1px solid rgba(255, 233, 184, .4); background: rgba(255, 233, 184, .07); color: var(--halo); text-align: left; }
.work-entry:hover { background: rgba(255, 233, 184, .13); }
.workroom { position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; background: var(--void); overflow-y: auto; }
.workroom::before { content: ""; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(50vmax 34vmax at 50% 8%, rgba(255, 233, 184, .06), transparent 70%), radial-gradient(60vmax 40vmax at 10% 110%, rgba(27, 35, 82, .9), transparent 70%); }
.workroom > * { position: relative; }
.wr-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex-wrap: wrap; }
.wr-head select { flex: 1; min-width: 160px; }
.workroom select, .workroom input:not([type=checkbox]), .workroom textarea, #wr-editor input, #wr-editor textarea {
  background: var(--glass); color: var(--ink); border: 1px solid var(--edge); border-radius: 12px; padding: 10px 12px; font: inherit;
}
.wr-main { width: min(720px, 100%); margin: 0 auto; padding: 8px 18px 40px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.wr-main .presence { margin: 4px auto 0; }
.wr-stages { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip { background: var(--glass); border: 1px solid var(--edge); border-radius: 999px; padding: 8px 16px; font-size: .9rem; color: var(--ink); }
.chip:hover { border-color: var(--ion); }
.chip.on { background: rgba(255, 233, 184, .14); border-color: rgba(255, 233, 184, .55); color: var(--halo); }
.wr-focus { text-align: center; color: var(--muted); margin: 0; min-height: 1.5em; }
#wr-text { width: 100%; resize: vertical; line-height: 1.7; font-size: 1.05rem; }
.wr-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.wr-row .primary { padding: 10px 22px; }
.wr-quick { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.wr-live { display: flex; gap: 8px; align-items: center; }
.wr-live input { flex: 1; min-width: 0; }
.wr-auto { color: var(--muted); font-size: .84rem; display: flex; gap: 8px; align-items: center; justify-content: center; }
.workroom .ghost, #wr-editor .ghost { padding: 9px 16px; }
.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }
#wr-editor { width: min(560px, calc(100% - 28px)); max-height: 90vh; padding: 20px; border: 1px solid var(--edge); border-radius: 20px; background: #0a0f24; color: var(--ink); }
#wr-editor::backdrop { background: rgba(0, 0, 0, .65); }
#wr-editor h2 { font: 500 1.05rem var(--display); letter-spacing: .05em; margin: 0 0 14px; }
#wr-form { display: flex; flex-direction: column; gap: 12px; }
#wr-form label { display: flex; flex-direction: column; gap: 6px; font-size: .86rem; color: var(--muted); }
.wr-presets { display: flex; gap: 8px; flex-wrap: wrap; }
#wf-stages { display: flex; flex-direction: column; gap: 10px; }
.wf-stage { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 10px; border: 1px solid var(--edge); border-radius: 14px; }
.wf-stage textarea { grid-column: 1 / -1; grid-row: 2; }

/* ---------- A esfera é o botão de falar ---------- */
.orb-btn { display: block; padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.orb-btn:focus-visible { outline: 2px solid var(--ion); outline-offset: 8px; }
.orb-btn .mic { position: absolute; inset: 0; margin: auto; width: 34%; height: 34%; fill: none; stroke: #0b1230; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .72; transition: opacity .2s, transform .2s; pointer-events: none; }
.orb-btn:hover .mic { opacity: 1; transform: scale(1.08); }
.orb-btn:active { transform: scale(.97); }
.orb-btn.on .core { box-shadow: 0 0 calc(var(--s) * .7) calc(var(--s) * .12) rgba(111, 227, 255, .5), 0 0 calc(var(--s) * 1.4) rgba(255, 233, 184, .14); }
.orb-btn.on .mic { stroke: #04212e; opacity: 1; }
.stage { flex-direction: column; gap: 10px; }
.orb-hint { color: var(--muted); font-size: .85rem; transition: opacity .3s; }
.pane:has(#messages .msg:nth-child(2)) .orb-hint { display: none; }
.pane:has(#messages .msg:nth-child(2)) .orb-btn .mic { display: none; }
.pane:has(#messages .msg:nth-child(2)) .orb-btn.on .mic { display: block; }

/* ---------- Administrador: o que diferencia ---------- */
.badge { margin-left: auto; padding: 3px 12px; border: 1px solid rgba(255, 233, 184, .55); border-radius: 999px; background: rgba(255, 233, 184, .1); color: var(--halo); font-size: .78rem; }
body.is-admin .pane header { border-bottom: 1px solid rgba(255, 233, 184, .22); }
.wr-title { color: var(--halo); font: 500 .95rem var(--display); letter-spacing: .05em; }
.workroom .wr-head { border-bottom: 1px solid rgba(255, 233, 184, .3); background: rgba(255, 233, 184, .04); }

/* Compacta a tela vazia para a saudação sempre caber */
.pane:not(:has(#messages .msg:nth-child(2))) .presence:not(.xl) { --s: 92px; }
.stage { padding: 4px 0 6px; gap: 6px; }
#messages .msg.assistant:only-child { font-size: 1.25rem; margin-top: 0; }
body:not(.voice-on) .pause-wrap { display: none; }
.foot { padding-top: 4px; }
@media (max-height: 640px) { .disclaimer { display: none; } .orb-hint { display: none; } }

/* ---------- Convites, memória e preferências ---------- */
.invites { width: min(720px, calc(100% - 28px)); margin: 0 auto 8px; display: flex; flex-direction: column; gap: 8px; }
.pane:has(#messages .msg:nth-child(2)) .invites { display: none; }
.invite { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border: 1px solid rgba(255, 233, 184, .35); border-radius: 18px; background: rgba(255, 233, 184, .06); }
.invite p { margin: 0; flex: 1 1 260px; color: var(--ink); }
.sheet { width: min(560px, calc(100% - 28px)); max-height: 88vh; padding: 0; border: 1px solid var(--edge); border-radius: 20px; background: #0a0f24; color: var(--ink); }
.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet-body { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { font: 500 1.02rem var(--display); letter-spacing: .05em; margin: 8px 0 0; }
.muted { color: var(--muted); font-size: .88rem; margin: 0; }
#mem-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
#mem-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 8px 12px; border: 1px solid var(--edge); border-radius: 12px; font-size: .92rem; }
#mem-list small { color: var(--muted); white-space: nowrap; }
.toggle { display: flex; gap: 12px; align-items: flex-start; font-size: .9rem; color: var(--muted); }
.toggle input { margin-top: 5px; accent-color: var(--ion); flex: none; width: 18px; height: 18px; }
.toggle b { display: block; color: var(--ink); font-weight: 500; }

/* Modo trabalho: rótulos e contagem */
.wr-label { color: var(--muted); font-size: .86rem; margin: 6px 0 -6px; }
#wr-said { width: 100%; resize: vertical; line-height: 1.6; }
.wr-count { text-align: center; }
#wr-editor label { display: flex; flex-direction: column; gap: 6px; font-size: .86rem; color: var(--muted); }
#wr-editor input[type=date] { color-scheme: dark; }
