:root {
  --bg: #efe8d8;
  --surface: #f7f1e4;
  --surface-2: #fffaf0;
  --ink: #152033;
  --ink-soft: #3d4a5c;
  --muted: #6b7380;
  --faint: #8b929c;
  --line: #d4cbb6;
  --navy: #1b3a57;
  --navy-deep: #12283d;
  --steel: #2f5d7a;
  --now: #1f6b57;
  --now-bg: #dceee6;
  --soon: #9a5b2a;
  --soon-bg: #f3e4d2;
  --danger: #9a3b32;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(21, 32, 51, 0.04), 0 8px 24px -16px rgba(21, 32, 51, 0.18);
  --sidebar: 17.5rem;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-font-smoothing: antialiased; }
body {
  font-family: Manrope, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 50% -120px, color-mix(in oklab, var(--navy) 8%, transparent), transparent 70%),
    repeating-linear-gradient(180deg, transparent 0, transparent 27px, color-mix(in oklab, var(--ink) 4%, transparent) 28px),
    var(--bg);
  background-attachment: fixed;
}
button { font: inherit; cursor: pointer; }
a { color: var(--steel); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
textarea, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

.app {
  height: 100dvh;
  height: 100svh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  padding: 1rem 0.85rem 0.85rem;
  padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.15rem 0.25rem 0.95rem;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--navy);
  color: var(--surface-2);
  display: grid;
  place-items: center;
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.brand-copy { min-width: 0; }
.kicker {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--steel);
  margin: 0;
}
.brand h1 {
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-top: 0.1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: 12px;
  border: 0;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}
.btn-navy { background: var(--navy); color: var(--surface-2); }
.btn-line { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 0; }
.btn-danger { background: #9a3b32; color: #fffaf0; }
.btn-new {
  width: 100%;
  margin-bottom: 0.85rem;
}

.history {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 0.15rem;
}
.section {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.85rem 0.35rem 0.4rem;
}
.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 12px;
  min-height: 40px;
  padding: 0.15rem;
}
.chat-item button.pick {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item.on {
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.chat-item .more {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  flex-shrink: 0;
}
.chat-item:hover .more,
.chat-item:focus-within .more,
.chat-item.menu-open .more { opacity: 1; }
.menu {
  position: absolute;
  right: 0.2rem;
  top: calc(100% - 0.2rem);
  z-index: 6;
  min-width: 10.5rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
}
.menu button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  padding: 0 0.7rem;
  font-weight: 500;
  color: var(--ink);
}
.menu button:hover { background: var(--surface); }
.menu button.danger { color: var(--danger); }

.user-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.75rem;
  padding: 0.7rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--navy) 12%, transparent);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.user-card b { display: block; font-size: 0.88rem; line-height: 1.25; }
.user-card span { display: block; margin-top: 0.15rem; font-size: 0.75rem; color: var(--muted); line-height: 1.3; }

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  display: none;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.85rem 0.55rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top, 0px));
}
.iconbtn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  flex-shrink: 0;
}
.topbar .title {
  font-family: Unbounded, Manrope, sans-serif;
  font-weight: 500;
  font-size: 1rem;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem 1rem;
}
.empty .mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--navy-deep);
  color: var(--surface-2);
  display: grid;
  place-items: center;
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.empty h2 {
  font-family: Unbounded, Manrope, sans-serif;
  font-size: clamp(1.35rem, 4vw, 2rem);
  font-weight: 500;
  margin: 1rem 0 0.35rem;
}
.empty p { margin: 0; color: var(--ink-soft); font-size: 1.02rem; }
.quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  width: min(36rem, 100%);
  margin-top: 1.4rem;
}
.quick button {
  min-height: 52px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.7rem 0.9rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--navy);
}

.thread {
  width: min(46rem, 100%);
  margin: 0 auto;
  padding: 1.25rem 1.1rem 0.5rem;
  display: grid;
  gap: 1.15rem;
}
.msg-user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: min(38rem, 92%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 18px 18px 8px 18px;
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow);
  font-size: 0.98rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg-ai { max-width: min(42rem, 100%); }
.msg-ai .body {
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.65;
}
.msg-ai .body p { margin: 0 0 0.8rem; }
.msg-ai .body p:last-child { margin-bottom: 0; }
.msg-ai h3 {
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 1.02rem;
  font-weight: 500;
  margin: 1rem 0 0.45rem;
}
.msg-ai ul, .msg-ai ol { margin: 0 0 0.85rem; padding-left: 1.15rem; }
.msg-ai li { margin: 0.2rem 0; }
.msg-ai table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.35rem 0 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.msg-ai th, .msg-ai td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
}
.msg-ai th { background: var(--surface); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.pre {
  margin: 0.2rem 0 0.9rem;
  padding: 0.85rem 0.95rem;
  border-radius: 14px;
  background: var(--navy-deep);
  color: #f4efe4;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.5;
}
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.sources a, .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
}
.sources a { color: var(--steel); background: color-mix(in oklab, var(--navy) 8%, transparent); }
.think-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--now);
  background: var(--now-bg);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}
.msg-ai.is-pending .body { min-height: 1.4em; }
.gen-cursor {
  display: inline-block;
  width: 0.55rem;
  height: 1em;
  margin-left: 0.15rem;
  background: var(--navy);
  vertical-align: text-bottom;
  animation: gen-blink 1s steps(1) infinite;
}
@keyframes gen-blink {
  50% { opacity: 0; }
}
.msg-ai.is-error .body { color: var(--danger); }
.attach-in-msg {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.dock {
  width: min(46rem, 100%);
  margin: 0 auto;
  padding: 0.55rem 1.1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}
.composer {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 0.75rem 0.8rem 0.65rem;
}
.composer textarea {
  width: 100%;
  border: 0;
  resize: none;
  background: transparent;
  min-height: 52px;
  max-height: 180px;
  padding: 0.15rem 0.35rem 0.45rem;
  outline: none;
  line-height: 1.45;
}
.composer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.icon-round {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.think {
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 0 0.85rem;
  font-weight: 600;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.think.on {
  border-color: var(--navy);
  background: color-mix(in oklab, var(--navy) 8%, transparent);
  color: var(--navy);
}
.think .short { display: none; }
.send {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 99px;
  background: var(--navy);
  color: var(--surface-2);
  display: grid;
  place-items: center;
}
.send:disabled { opacity: 0.35; }

.previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.55rem;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.35rem 0.4rem 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 500;
}
.file-chip b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.file-chip .x {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18, 40, 61, 0.45);
  z-index: 20;
}
.modal-bg {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(18, 40, 61, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}
.modal {
  width: 100%;
  max-width: 26rem;
  background: var(--surface-2);
  border-radius: 22px;
  padding: 1.2rem 1.15rem 1.3rem;
  box-shadow: 0 24px 48px -18px rgba(18, 40, 61, 0.5);
}
.modal h2 {
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 1.15rem;
  font-weight: 500;
  margin: 0.2rem 0 0.75rem;
}
.modal input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 0 0.85rem;
}
.modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.9rem; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; }
.close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}

@media (min-width: 540px) {
  .modal-bg { align-items: center; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(19.5rem, 88vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: 16px 0 40px -24px rgba(18, 40, 61, 0.45); }
  .scrim.show { display: block; }
  .chat-item .more { opacity: 1; }
}

@media (max-width: 430px) {
  .quick { grid-template-columns: 1fr; }
  .dock, .thread { padding-left: 0.8rem; padding-right: 0.8rem; }
  .think { font-size: 0.78rem; padding: 0 0.7rem; }
  .empty h2 { font-size: 1.35rem; }
}

@media (max-width: 320px) {
  .brand h1 { font-size: 0.92rem; }
  .composer { padding: 0.6rem 0.6rem 0.55rem; border-radius: 18px; }
  .think .full { display: none; }
  .think .short { display: inline; }
  .send, .iconbtn, .icon-round { width: 40px; height: 40px; }
}

.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}
.auth-card {
  width: min(26rem, 100%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.35rem 1.25rem 1.4rem;
}
.display-title {
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 1.35rem;
  font-weight: 500;
  margin: .35rem 0 .75rem;
}
.auth-form { display: grid; gap: .45rem; }
.auth-form label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.auth-form input[type="text"],
.auth-form input[type="password"] {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 0 .85rem;
}
.remember { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--ink); }
.auth-err { color: var(--danger); font-weight: 600; font-size: .9rem; }
.invite-who { margin: 0 0 1rem; }
.invite-who b { display: block; }
.invite-who span { color: var(--muted); font-size: .9rem; }
.side-nav { display: grid; gap: .25rem; margin: 0 0 .75rem; }
.side-nav a {
  min-height: 40px;
  border-radius: 12px;
  padding: .45rem .7rem;
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: .9rem;
}
.side-nav a.on, .side-nav a:hover { background: var(--surface-2); color: var(--ink); }
.user-card { justify-content: space-between; }
.user-card .who { min-width: 0; flex: 1; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .55rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .85rem;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.users-table th, .users-table td {
  text-align: left;
  padding: .65rem .7rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.users-table th {
  font-size: .7rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
}
.users-stage { padding: 1.1rem; overflow: auto; }
.invite-box {
  margin-top: .7rem;
  padding: .75rem;
  border-radius: 12px;
  background: var(--now-bg);
  color: var(--now);
  word-break: break-all;
  font-size: .85rem;
}
@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .users-table { display: block; overflow-x: auto; }
}
