/* ECHO — premium minimal dark glass UI
   System font stack only; CSP-safe; responsive and accessible. */

:root {
  --bg-0: #07110f;
  --bg-1: #0b1715;
  --bg-2: #0f201d;
  --panel: rgba(255,255,255,0.08);
  --panel-strong: rgba(255,255,255,0.11);
  --panel-soft: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.12);
  --border-strong: rgba(255,255,255,0.18);
  --text: rgba(245,250,248,0.96);
  --muted: rgba(210,225,221,0.72);
  --muted-2: rgba(210,225,221,0.56);
  --accent: #0F8A5F;
  --accent-2: #2E9E8F;
  --cyan: #67e8f9;
  --danger: #ff7b90;
  --success: #7ef0c4;
  --shadow-lg: 0 24px 80px rgba(0,0,0,0.38), 0 10px 30px rgba(0,0,0,0.28);
  --shadow-md: 0 12px 36px rgba(0,0,0,0.28);
  --shadow-sm: 0 6px 18px rgba(0,0,0,0.18);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --radius-pill: 999px;
  --blur: 18px;
  --maxw: 920px;
  --authw: 430px;
  --topbar-h: 72px;
  --composer-h: 84px;
  --focus: 0 0 0 1px rgba(103,232,249,0.55), 0 0 0 4px rgba(46,158,143,0.18), 0 10px 30px rgba(46,158,143,0.16);
  --user-grad: linear-gradient(135deg, rgba(15,138,95,0.98), rgba(46,158,143,0.96) 62%, rgba(103,232,249,0.82));
  --glass-grad: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.06));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 12% 10%, rgba(46,158,143,0.15), transparent 60%),
    radial-gradient(760px 420px at 88% 12%, rgba(103,232,249,0.10), transparent 58%),
    radial-gradient(620px 380px at 50% 100%, rgba(15,138,95,0.14), transparent 65%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1) 40%, var(--bg-0));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(42% 24% at 24% 8%, rgba(126,240,196,0.10), transparent 70%),
    radial-gradient(34% 18% at 82% 16%, rgba(103,232,249,0.08), transparent 72%);
  filter: blur(36px);
  opacity: 0.9;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 90%);
  opacity: 0.16;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }
img, svg { display: block; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.echo-shell,
.auth-shell {
  position: relative;
  min-height: 100vh;
}

.auth-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card,
.glass-card {
  position: relative;
  width: 100%;
  background: var(--glass-grad);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(var(--blur)) saturate(135%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(135%);
  box-shadow: var(--shadow-lg);
}

.auth-card {
  max-width: var(--authw);
  padding: 28px;
}

.auth-card::before,
.glass-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), transparent 22%, transparent 78%, rgba(255,255,255,0.04));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #b6fff0, var(--cyan) 18%, var(--accent-2) 46%, var(--accent) 78%, rgba(15,138,95,0.2));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.14), 0 0 22px rgba(46,158,143,0.34), 0 0 42px rgba(103,232,249,0.12);
}

.brand-word {
  font-size: 0.9rem;
}

.auth-head {
  margin-bottom: 22px;
}

.auth-title {
  margin: 16px 0 8px;
  font-size: clamp(1.8rem, 3.2vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.auth-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}

.input,
#message {
  width: 100%;
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(7,17,15,0.44);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.input::placeholder,
#message::placeholder {
  color: rgba(215,230,225,0.42);
}

.input:hover,
#message:hover {
  border-color: var(--border-strong);
  background: rgba(7,17,15,0.52);
}

.input:focus,
#message:focus,
button:focus-visible,
a:focus-visible,
input[type="checkbox"]:focus-visible + .switch-ui {
  box-shadow: var(--focus);
  border-color: rgba(103,232,249,0.38);
}

.input:focus,
#message:focus {
  background: rgba(7,17,15,0.62);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.hint {
  color: var(--muted-2);
  font-size: 0.85rem;
}

.error-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,123,144,0.22);
  background: rgba(255,123,144,0.10);
  color: #ffd5dd;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 13px 16px;
  color: white;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease, opacity 180ms ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--user-grad);
  box-shadow: 0 10px 28px rgba(15,138,95,0.28), inset 0 1px 0 rgba(255,255,255,0.18);
}

.btn-primary:hover {
  filter: brightness(1.04);
  box-shadow: 0 14px 32px rgba(15,138,95,0.34), inset 0 1px 0 rgba(255,255,255,0.20);
}

.auth-footer {
  margin-top: 16px;
  color: var(--muted-2);
  font-size: 0.88rem;
}

.app-root {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 16px 16px 0;
}

.topbar {
  height: var(--topbar-h);
  max-width: calc(var(--maxw) + 120px);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}

.role-chip {
  padding: 7px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: capitalize;
}

.signout-link {
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.signout-link:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
}

.app-main {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 24px;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 14px;
  min-height: calc(100vh - 88px);
}

.transcript-card {
  min-height: 0;
  overflow: hidden;
}

#transcript {
  height: 100%;
  min-height: 48vh;
  max-height: calc(100vh - 236px);
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.16) transparent;
}

#transcript::-webkit-scrollbar { width: 10px; }
#transcript::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#transcript::-webkit-scrollbar-track { background: transparent; }

.msg {
  display: flex;
  width: 100%;
}

.msg.echo { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }

.bubble {
  position: relative;
  max-width: min(78%, 700px);
  padding: 14px 16px;
  border-radius: 20px;
  line-height: 1.5;
  font-size: 0.98rem;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.echo .bubble {
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.06));
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 10px;
}

.msg.user .bubble {
  background: var(--user-grad);
  color: white;
  border: 1px solid rgba(255,255,255,0.10);
  border-top-right-radius: 10px;
  box-shadow: 0 14px 30px rgba(15,138,95,0.26), inset 0 1px 0 rgba(255,255,255,0.18);
}

.bubble.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 78px;
}

.bubble.typing::before,
.bubble.typing::after,
.bubble.typing span {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(180deg, #d7fffa, var(--cyan));
  opacity: 0.85;
  animation: echoDots 1.2s infinite ease-in-out;
  box-shadow: 0 0 16px rgba(103,232,249,0.22);
}

.bubble.typing span { animation-delay: 0.16s; }
.bubble.typing::after { animation-delay: 0.32s; }

@keyframes echoDots {
  0%, 80%, 100% { transform: translateY(0) scale(0.9); opacity: 0.45; }
  40% { transform: translateY(-3px) scale(1); opacity: 1; }
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  z-index: 9;
}

#composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.08));
  border: 1px solid var(--border);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow-md);
}

#mic,
#send {
  appearance: none;
  border: 1px solid var(--border);
  outline: none;
}

#mic {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.06));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

#mic:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

#mic.recording {
  background: radial-gradient(circle at 50% 36%, rgba(255,255,255,0.16), transparent 42%), linear-gradient(135deg, rgba(15,138,95,0.96), rgba(46,158,143,0.96), rgba(103,232,249,0.86));
  border-color: rgba(103,232,249,0.30);
  box-shadow: 0 0 0 0 rgba(46,158,143,0.36), 0 0 28px rgba(46,158,143,0.28), inset 0 1px 0 rgba(255,255,255,0.18);
  animation: micPulse 1.7s infinite ease-out;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(46,158,143,0.36), 0 0 28px rgba(46,158,143,0.24), inset 0 1px 0 rgba(255,255,255,0.18); }
  70% { box-shadow: 0 0 0 14px rgba(46,158,143,0), 0 0 34px rgba(46,158,143,0.30), inset 0 1px 0 rgba(255,255,255,0.18); }
  100% { box-shadow: 0 0 0 0 rgba(46,158,143,0), 0 0 22px rgba(46,158,143,0.20), inset 0 1px 0 rgba(255,255,255,0.18); }
}

.mic-glyph {
  font-size: 1.15rem;
  line-height: 1;
}

#message {
  min-width: 0;
  border-radius: 18px;
  padding: 15px 16px;
  background: rgba(5,12,11,0.42);
}

#send {
  height: 52px;
  padding: 0 18px;
  border-radius: 16px;
  color: white;
  font-weight: 700;
  background: var(--user-grad);
  box-shadow: 0 10px 26px rgba(15,138,95,0.24), inset 0 1px 0 rgba(255,255,255,0.16);
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}

#send:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 6px 0;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(221,232,228,0.88));
  box-shadow: 0 3px 10px rgba(0,0,0,0.28);
  transition: transform 180ms ease;
}

.switch input[type="checkbox"]:checked + .switch-ui {
  background: linear-gradient(135deg, rgba(15,138,95,0.78), rgba(46,158,143,0.72));
  border-color: rgba(103,232,249,0.24);
  box-shadow: 0 0 16px rgba(46,158,143,0.18), inset 0 1px 0 rgba(255,255,255,0.10);
}

.switch input[type="checkbox"]:checked + .switch-ui::after {
  transform: translateX(20px);
}

.switch-label {
  font-size: 0.92rem;
}

#status {
  min-height: 1.3em;
  color: var(--muted-2);
  font-size: 0.9rem;
  text-align: right;
}

[data-role="manager"] .role-chip,
[data-role="admin"] .role-chip {
  color: rgba(240,251,247,0.92);
  border-color: rgba(103,232,249,0.20);
}

@media (max-width: 720px) {
  .topbar-wrap { padding: 12px 12px 0; }
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    padding: 12px 14px;
    align-items: flex-start;
    flex-direction: column;
  }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .app-main {
    padding: 14px 12px 20px;
    min-height: calc(100vh - 94px);
  }
  #transcript {
    padding: 16px;
    max-height: calc(100vh - 270px);
  }
  .bubble { max-width: 88%; }
  .controls-row {
    flex-direction: column;
    align-items: flex-start;
  }
  #status { text-align: left; }
}

@media (max-width: 480px) {
  .auth-card { padding: 22px 18px; border-radius: 24px; }
  .auth-title { font-size: 1.7rem; }
  .brand-word { font-size: 0.84rem; }
  .user-name { max-width: 120px; }
  #composer {
    grid-template-columns: 48px 1fr;
    grid-template-areas:
      "mic message"
      "send send";
  }
  #mic { grid-area: mic; width: 48px; height: 48px; }
  #message { grid-area: message; }
  #send {
    grid-area: send;
    width: 100%;
    height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
