:root {
  --bg: #ffffff;
  --side: #f9f9f9;
  --hover: #ececec;
  --active: #e3e3e3;
  --text: #0d0d0d;
  --muted: #6b6b6b;
  --line: #e5e5e5;
  --bubble: #f4f4f4;
  --code: #f7f7f7;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --busy: #10a37f;
  --radius: 26px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --side: #171717;
    --hover: #2a2a2a;
    --active: #303030;
    --text: #ececec;
    --muted: #9b9b9b;
    --line: #3a3a3a;
    --bubble: #303030;
    --code: #2a2a2a;
    --accent: #ececec;
    --accent-text: #0d0d0d;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

.hidden {
  display: none !important;
}

/* ---------- sign in ---------- */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.login h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 12px;
}

.login input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
}

.login input:focus {
  border-color: var(--muted);
}

.login button {
  height: 52px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

.login button:disabled {
  opacity: 0.6;
}

.login .error {
  color: #d03b3b;
  font-size: 14px;
  min-height: 1.5em;
  margin: 0;
}

/* ---------- layout ---------- */

.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  flex: none;
  background: var(--side);
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 8px;
}

.side-label {
  font-size: 13px;
  color: var(--muted);
  padding: 16px 10px 6px;
}

.chats {
  flex: 1;
  overflow-y: auto;
}

.chat-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
}

.chat-link:hover {
  background: var(--hover);
}

.chat-link.current {
  background: var(--active);
}

.chat-link .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-link.unread .name {
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot.busy {
  background: var(--busy);
  animation: pulse 1.4s ease-in-out infinite;
}

.dot.unread {
  background: #3b82f6;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.side-foot {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.side-foot button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
}

.side-foot button:hover {
  background: var(--hover);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
}

.icon-btn:hover {
  background: var(--hover);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

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

.top {
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}

.top h1 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  padding: 0 6px;
}

.top .menu {
  display: none;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thread {
  max-width: 48rem;
  margin: 0 auto;
  padding: 8px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 30vh;
  font-size: 15px;
}

/* ---------- messages ---------- */

.msg-user {
  align-self: flex-end;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.bubble {
  background: var(--bubble);
  border-radius: 18px;
  padding: 10px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-user .state {
  font-size: 12px;
  color: var(--muted);
}

.files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg);
}

.file-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb {
  max-width: 220px;
  max-height: 220px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 12px;
  display: block;
  object-fit: cover;
}

.reply {
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.reply > :first-child {
  margin-top: 0;
}

.reply > :last-child {
  margin-bottom: 0;
}

.reply p,
.reply ul,
.reply ol,
.reply pre,
.reply table,
.reply blockquote {
  margin: 0 0 12px;
}

.reply h1,
.reply h2,
.reply h3,
.reply h4 {
  font-size: 1.05em;
  font-weight: 600;
  margin: 18px 0 8px;
}

.reply ul,
.reply ol {
  padding-left: 1.4em;
}

.reply li {
  margin: 3px 0;
}

.reply a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reply code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code);
  border-radius: 4px;
  padding: 1px 4px;
}

.reply pre {
  background: var(--code);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
}

.reply pre code {
  background: none;
  padding: 0;
}

.reply table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  font-size: 0.93em;
}

.reply th,
.reply td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}

.reply blockquote {
  border-left: 3px solid var(--line);
  padding-left: 12px;
  color: var(--muted);
}

.mail {
  font-size: 14px;
  color: var(--muted);
}

.mail summary {
  cursor: pointer;
  list-style: none;
}

.mail summary::-webkit-details-marker {
  display: none;
}

.mail summary::before {
  content: "\203A";
  display: inline-block;
  width: 1em;
  transition: transform 0.15s;
}

.mail[open] summary::before {
  transform: rotate(90deg);
}

.mail .reply {
  margin-top: 8px;
  padding-left: 1em;
  color: var(--text);
  font-size: 15px;
}

/* ---------- questions ---------- */

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card .recap {
  color: var(--muted);
  font-size: 15px;
  margin: 0;
}

.card .q {
  font-weight: 600;
  margin: 0;
}

.card .intro {
  margin: 0;
  font-size: 15px;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.choice {
  display: flex;
  gap: 10px;
  align-items: baseline;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
}

.choice:hover:not(:disabled) {
  background: var(--hover);
}

.choice.picked {
  border-color: var(--text);
  background: var(--hover);
}

.choice:disabled {
  cursor: default;
  opacity: 0.6;
}

.choice .n {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card .send-answers {
  align-self: flex-end;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 7px 16px;
  font-size: 14px;
}

.card .send-answers:disabled {
  opacity: 0.4;
  cursor: default;
}

.card .note {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.working {
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- composer ---------- */

.composer-wrap {
  flex: none;
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
}

.composer {
  max-width: 48rem;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 8px 10px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.composer.drag {
  border-color: var(--muted);
}

.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 4px 0;
}

.pending-file {
  position: relative;
}

.pending-file .file-chip {
  padding-right: 26px;
}

.pending-file img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.pending-file .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

.pending-file.loading {
  opacity: 0.5;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  max-height: 40vh;
  min-height: 24px;
  padding: 6px 4px;
  line-height: 1.5;
}

.send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  flex: none;
}

.send:disabled {
  opacity: 0.3;
  cursor: default;
}

.send svg {
  width: 18px;
  height: 18px;
}

.status-note {
  max-width: 48rem;
  margin: 6px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.scrim {
  display: none;
}

/* ---------- phone ---------- */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .layout.open .sidebar {
    transform: none;
  }

  .layout.open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 10;
  }

  .top .menu {
    display: inline-grid;
  }

  .thread {
    padding: 8px 14px 20px;
  }

  .msg-user {
    max-width: 88%;
  }

  .composer-wrap {
    padding: 0 10px calc(8px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    font-size: 16px;
  }
}

@media (min-width: 769px) {
  .side-head .close {
    display: none;
  }
}

/* ---------- weekly usage ---------- */

.usage {
  padding: 8px 10px 10px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.usage-label {
  color: var(--text);
  font-size: 13px;
}

.usage-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--muted);
}

.usage-warning {
  color: #b45309;
}
