:root {
  --bg: #1a1917;
  --bg-side: #141413;
  --bg-elev: #232220;
  --line: rgba(255, 255, 255, 0.08);
  --txt: #f4f0ea;
  --mut: #b4aea5;
  --accent: #d97757;
  --accent-2: #c96442;
  --user-bg: #2a2926;
  --danger: #e07a7a;
  --radius: 22px;
  --max: 740px;
  --side: 268px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  letter-spacing: -0.011em;
}

.hidden,
[hidden] {
  display: none !important;
}

button {
  font: inherit;
}

/* Login — Claude-quiet */
#gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100dvh;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  background: var(--bg);
}

#login {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

#login img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin-bottom: 18px;
}

#login h1 {
  margin: 0 0 6px;
  font-size: 1.7rem;
  font-weight: 560;
  letter-spacing: -0.03em;
}

#login .sub {
  margin: 0 0 28px;
  color: var(--mut);
  font-size: 0.95rem;
}

#login label {
  font-size: 0.78rem;
  color: var(--mut);
  margin: 0 0 6px;
}

#login input {
  height: 44px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--txt);
  border-radius: 10px;
  padding: 0 12px;
  margin-bottom: 14px;
  outline: none;
}

#login input:focus {
  border-color: var(--accent);
}

#login-go {
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #1a120f;
  font-weight: 650;
  cursor: pointer;
  margin-top: 6px;
}

#login-go:disabled {
  opacity: 0.5;
}

#login-error {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

/* Shell */
#app {
  height: 100dvh;
  height: 100svh;
  display: flex;
  padding-top: var(--safe-t);
  background: var(--bg);
}

#sidebar {
  width: var(--side);
  flex: 0 0 var(--side);
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-top {
  padding: 14px 12px 8px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand-row img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.btn-new {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--txt);
  cursor: pointer;
}

.btn-new:hover {
  background: var(--bg-elev);
}

.side-label {
  padding: 14px 18px 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mut);
}

.side-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
  overflow: auto;
}

.side-list.chats {
  flex: 1;
  min-height: 0;
}

.side-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--txt);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 0.88rem;
}

.side-item span {
  color: var(--mut);
  font-size: 0.72rem;
}

.side-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.side-item.on {
  background: var(--bg-elev);
}

.side-bottom {
  padding: 10px 12px calc(12px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--line);
}

.ghost {
  border: 0;
  background: transparent;
  color: var(--mut);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.ghost:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--txt);
}

#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title strong {
  font-size: 0.95rem;
}

#tenant-pill {
  color: var(--mut);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#menu {
  border: 0;
  background: transparent;
  color: var(--txt);
  padding: 8px;
  cursor: pointer;
}

#log-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

#empty h2 {
  margin: 0;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-weight: 450;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.03em;
}

#empty p {
  margin: 12px 0 0;
  color: var(--mut);
  font-size: 0.95rem;
}

#empty.has-msgs {
  display: none;
}

#log {
  width: min(var(--max), 100%);
  margin: 0 auto;
  padding: 28px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.row.me {
  justify-content: flex-end;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #1a120f;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  font-weight: 750;
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  margin-top: 2px;
}

.bubble {
  max-width: 100%;
  min-width: 0;
}

.bubble .who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--mut);
  margin-bottom: 6px;
  font-weight: 600;
}

.speak {
  border: 0;
  background: transparent;
  color: var(--mut);
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 26px;
}

.speak:hover,
.speak.playing {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
}

.speak.busy {
  opacity: 0.45;
}

.voice-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--mut);
  font-size: 0.82rem;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.voice-toggle input {
  accent-color: var(--accent);
}

.voice-toggle:hover {
  color: var(--txt);
  background: rgba(255, 255, 255, 0.04);
}

.bubble .body {
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 0.98rem;
  word-break: break-word;
  color: var(--txt);
}

.row.bot .bubble .body {
  min-height: 1.4em;
}

.row.bot .bubble .body.is-pending {
  color: var(--mut);
}

.row.me .bubble .body {
  background: var(--user-bg);
  border-radius: 18px 18px 6px 18px;
  padding: 12px 16px;
}

.row.bot .bubble {
  flex: 1;
}

.row.sys {
  justify-content: center;
}

.row.sys .body {
  font-size: 0.75rem;
  color: var(--mut);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}

#send {
  width: min(var(--max), 100%);
  margin: 0 auto;
  padding: 8px 16px calc(14px + var(--safe-b));
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 8px 8px 8px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

#q {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--txt);
  font: inherit;
  line-height: 1.45;
  max-height: 160px;
  outline: none;
  padding: 8px 0;
}

#go {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--txt);
  color: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 36px;
}

#go:disabled {
  opacity: 0.28;
  cursor: default;
}

.hint {
  margin: 8px 0 0;
  text-align: center;
  color: var(--mut);
  font-size: 0.72rem;
}

#usage-line {
  font-variant-numeric: tabular-nums;
}

#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}

@media (max-width: 860px) {
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  #app.nav-open #sidebar {
    transform: none;
  }

  .topbar {
    display: flex;
  }
}
