:root {
  color-scheme: dark light;
  --bg: #080a0e;
  --bg-2: #10151c;
  --panel: rgba(21, 27, 36, 0.72);
  --panel-strong: rgba(28, 36, 47, 0.9);
  --stroke: rgba(255, 255, 255, 0.13);
  --text: #f7f8fb;
  --muted: #a7b1bf;
  --blue: #72d8ff;
  --gold: #f4cc73;
  --green: #79e6b1;
  --pink: #ff7a9f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --bg-2: #ffffff;
    --panel: rgba(255, 255, 255, 0.72);
    --panel-strong: rgba(255, 255, 255, 0.92);
    --stroke: rgba(32, 42, 56, 0.13);
    --text: #121821;
    --muted: #607083;
    --shadow: 0 20px 54px rgba(50, 70, 95, 0.16);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 8%, rgba(114, 216, 255, 0.16), transparent 28%),
    radial-gradient(circle at 76% 20%, rgba(244, 204, 115, 0.12), transparent 30%),
    linear-gradient(140deg, var(--bg), var(--bg-2));
}

button, input, textarea, select { font: inherit; }
button, select {
  border: 1px solid var(--stroke);
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 0.72rem 0.95rem;
}
button { cursor: pointer; transition: transform .16s ease, border-color .16s ease, background .16s ease; }
button:hover { transform: translateY(-1px); border-color: rgba(114, 216, 255, .38); }
.primary { background: linear-gradient(135deg, rgba(114,216,255,.28), rgba(244,204,115,.18)); border-color: rgba(114,216,255,.36); }
.danger { background: rgba(255, 122, 159, .15); border-color: rgba(255, 122, 159, .34); }
.danger-soft { color: var(--pink); }
.wide { width: 100%; margin-top: 1rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.sidebar, .login-card, .chat-card, .status-panel, .admin-panel, .notice {
  border: 1px solid var(--stroke);
  background: var(--panel);
  backdrop-filter: blur(28px) saturate(150%);
  box-shadow: var(--shadow);
}

.sidebar {
  border-radius: 30px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 32px);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px; }
.brand strong { display: block; letter-spacing: .08em; }
.brand span { color: var(--muted); font-size: .86rem; }
.mark {
  width: 46px;
  height: 46px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,.92), transparent 13%),
    conic-gradient(from 220deg, var(--blue), var(--gold), var(--green), var(--blue));
  box-shadow: 0 0 42px rgba(114,216,255,.24);
}

.mode-stack {
  display: grid;
  gap: 8px;
  padding: 6px;
  border-radius: 24px;
  background: rgba(255,255,255,.055);
}
.mode { text-align: left; border-radius: 18px; }
.mode.active { background: var(--panel-strong); border-color: rgba(114,216,255,.36); }

.side-section { display: grid; gap: 10px; min-height: 0; }
.side-section.compact { margin-top: auto; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
}
.thread-list { display: grid; gap: 8px; overflow: auto; }
.thread {
  width: 100%;
  border-radius: 18px;
  text-align: left;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread.active { color: var(--text); background: rgba(114,216,255,.12); border-color: rgba(114,216,255,.25); }
.select-label { display: grid; gap: 8px; color: var(--muted); font-size: .9rem; }
.language-select, .chip-select { width: 100%; outline: none; }

.login-card {
  width: min(460px, 100%);
  place-self: center;
  padding: 30px;
  border-radius: 34px;
}
.login-orb { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(from 80deg, var(--blue), var(--gold), var(--green), var(--blue)); box-shadow: 0 0 70px rgba(114,216,255,.2); }
.login-orb span { width: 62%; height: 62%; border-radius: 50%; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.26); }
.login-card h1 { margin: 18px 0 8px; font-size: clamp(2.6rem, 8vw, 4.7rem); letter-spacing: 0; }
.login-card p { color: var(--muted); line-height: 1.5; }
label { display: grid; gap: 7px; margin-top: 14px; color: var(--muted); }
input, textarea {
  width: 100%;
  color: var(--text);
  background: rgba(255,255,255,.07);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: .95rem 1rem;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: rgba(114,216,255,.46); box-shadow: 0 0 0 4px rgba(114,216,255,.11); }

.workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.topbar h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 3.1rem); letter-spacing: 0; }
.eyebrow { color: var(--blue); text-transform: uppercase; font-size: .72rem; letter-spacing: .13em; margin: 0 0 4px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.chat-card {
  min-height: 0;
  border-radius: 34px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.chat-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--stroke);
}
.orb {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 38% 32%, rgba(255,255,255,.88), transparent 10%),
    conic-gradient(from 120deg, rgba(114,216,255,.2), rgba(244,204,115,.54), rgba(121,230,177,.22), rgba(114,216,255,.2));
  box-shadow: inset 0 0 32px rgba(255,255,255,.12), 0 0 52px rgba(114,216,255,.18);
}
.orb span { width: 60%; height: 60%; border-radius: 50%; border: 1px solid rgba(255,255,255,.24); background: rgba(255,255,255,.1); }
.orb.listening { animation: pulse 1.15s infinite; box-shadow: 0 0 74px rgba(121,230,177,.32); }
.orb.thinking { animation: rotate 4.8s linear infinite; }
.orb.speaking { animation: pulse .72s infinite; box-shadow: 0 0 82px rgba(244,204,115,.34); }
@keyframes pulse { 50% { transform: scale(1.035); } }
@keyframes rotate { to { transform: rotate(360deg); } }
#providerState { margin: 4px 0 0; color: var(--muted); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip, .chip-select { min-height: 38px; }
.chip-select { width: auto; max-width: 170px; }

.live-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(255,255,255,.04);
}
#partialTranscript { margin: 2px 0 0; color: var(--muted); }
.wave { display: flex; align-items: center; gap: 4px; height: 30px; }
.wave i { width: 4px; height: 12px; border-radius: 8px; background: var(--blue); animation: wave 1s infinite ease-in-out; }
.wave i:nth-child(2) { animation-delay: .1s; }
.wave i:nth-child(3) { animation-delay: .2s; }
.wave i:nth-child(4) { animation-delay: .3s; }
.wave i:nth-child(5) { animation-delay: .4s; }
@keyframes wave { 50% { height: 27px; background: var(--gold); } }

.messages {
  padding: 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.empty-state {
  margin: auto;
  color: var(--muted);
  padding: 24px;
  border: 1px dashed var(--stroke);
  border-radius: 24px;
}
.message {
  max-width: min(78ch, 88%);
  padding: 13px 15px;
  border: 1px solid var(--stroke);
  border-radius: 26px;
  line-height: 1.52;
  white-space: pre-wrap;
}
.message.user {
  align-self: flex-end;
  color: #ffffff;
  background: linear-gradient(135deg, rgba(33, 137, 190, .58), rgba(55, 89, 130, .58));
  border-bottom-right-radius: 10px;
}
.message.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,.06);
  border-bottom-left-radius: 10px;
}
.message-meta { color: var(--muted); font-size: .76rem; margin-bottom: 5px; }
.message.user .message-meta { color: rgba(255,255,255,.72); }

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--stroke);
  background: rgba(0,0,0,.12);
}
textarea { resize: none; min-height: 50px; max-height: 170px; }
.send { min-width: 86px; background: var(--text); color: var(--bg); }

.right-rail { display: grid; align-content: start; gap: 16px; min-width: 0; }
.status-panel, .admin-panel, .notice { border-radius: 28px; padding: 16px; }
dl { display: grid; gap: 9px; margin-bottom: 0; }
dl div { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,.08); }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.admin-output {
  max-height: 260px;
  overflow: auto;
  color: var(--muted);
  background: rgba(0,0,0,.18);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 12px;
  white-space: pre-wrap;
}
.notice { color: var(--muted); line-height: 1.45; background: rgba(121,230,177,.08); border-color: rgba(121,230,177,.22); }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .workspace { grid-template-columns: 1fr; }
  .right-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; gap: 10px; }
  .sidebar, .chat-card, .status-panel, .admin-panel, .notice, .login-card { border-radius: 24px; }
  .topbar, .chat-header { align-items: flex-start; }
  .chat-header { grid-template-columns: auto 1fr; }
  .chip-row { grid-column: 1 / -1; justify-content: flex-start; }
  .right-rail { grid-template-columns: 1fr; }
  .message { max-width: 96%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
