:root {
  --radius: 12px;
  --background: #fbfaf3;
  --foreground: #1f2937;
  --card: #ffffff;
  --muted: #f3f1e8;
  --muted-foreground: #697386;
  --primary: #17243a;
  --primary-foreground: #fffaf0;
  --accent: #f2bd2f;
  --border: #e6e0cf;
  --green: #12a150;
  --red: #c2410c;
  --blue: #2563eb;
  font-family: Barlow, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--background) 92%, white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
  font-weight: 650;
}

.brand span,
.userline,
.muted {
  color: var(--muted-foreground);
  font-size: 12px;
}

.token-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 18px 45px -28px rgba(23, 36, 58, 0.35);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-card textarea {
  min-height: 110px;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr) minmax(320px, 380px);
  min-height: calc(100vh - 64px);
}

.pane {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--card);
}

.pane.context {
  border-right: 0;
  background: var(--background);
}

.pane-header {
  min-height: 70px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pane-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.workspace-label,
.workspace-select {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 650;
}

.workspace-select {
  width: 100%;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 9px;
  color: var(--foreground);
}

.toolbar,
.filters,
.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filters {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.btn,
.icon-btn,
.pill {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.icon-btn {
  width: 34px;
  padding: 0;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.pill {
  min-height: 30px;
  font-size: 12px;
}

.pill.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.search {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--foreground);
}

.textarea {
  resize: vertical;
  min-height: 42px;
  max-height: 160px;
}

.conversation-list {
  overflow: auto;
  height: calc(100vh - 64px - 128px);
}

.conversation-row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 12px;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  text-align: left;
}

.conversation-row.active {
  background: color-mix(in srgb, var(--accent) 20%, white);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.row-main {
  min-width: 0;
}

.row-top,
.chat-header-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.name,
.preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.name {
  font-weight: 650;
}

.preview {
  color: var(--muted-foreground);
  font-size: 13px;
  margin-top: 3px;
}

.badge {
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
  padding: 3px 8px;
  font-size: 11px;
  white-space: nowrap;
}

.badge.green {
  background: color-mix(in srgb, var(--green) 14%, white);
  color: #087238;
}

.badge.red {
  background: color-mix(in srgb, var(--red) 12%, white);
  color: var(--red);
}

.badge.blue {
  background: color-mix(in srgb, var(--blue) 12%, white);
  color: var(--blue);
}

.unread {
  background: var(--accent);
  color: #392700;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.chat {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #f8f6ee;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
}

.bubble-wrap {
  display: flex;
}

.bubble-wrap.outbound,
.bubble-wrap.outgoing {
  justify-content: flex-end;
}

.bubble {
  max-width: min(72%, 680px);
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  box-shadow: 0 5px 18px -18px rgba(23, 36, 58, 0.35);
}

.outbound .bubble,
.outgoing .bubble {
  background: #e5ffd8;
}

.bubble .quote {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  color: var(--muted-foreground);
  font-size: 12px;
  margin-bottom: 6px;
}

.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-meta {
  margin-top: 5px;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  color: var(--muted-foreground);
  font-size: 11px;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--card);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.quoted-compose {
  border-left: 3px solid var(--accent);
  background: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.context-scroll {
  height: calc(100vh - 64px - 70px);
  overflow: auto;
  padding: 16px;
}

.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  font-size: 13px;
  margin: 7px 0;
}

.kv span:first-child {
  color: var(--muted-foreground);
}

.media-box {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: color-mix(in srgb, var(--muted) 55%, white);
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted-foreground);
  padding: 24px;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .pane.context {
    display: none;
  }

  .conversation-list {
    height: 280px;
  }

  .chat {
    min-height: calc(100vh - 64px - 280px);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.32);
}

.modal {
  width: min(420px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.forward-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  max-height: 440px;
  overflow: auto;
}

.forward-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 8px;
  text-align: left;
}

.forward-row:hover {
  border-color: var(--border);
  background: var(--muted);
}
