:root {
  --paper: #f4f1ea;
  --paper-deep: #ebe4d7;
  --ink: #111111;
  --navy: #18304b;
  --navy-deep: #0f2236;
  --green: #1e5b4f;
  --red: #8b1f24;
  --line: rgba(24, 48, 75, 0.16);
  --white: #fffdfa;
  --shadow: 0 24px 90px rgba(15, 34, 54, 0.14);
  --font: "Aptos", "Segoe UI Variable", "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(24, 48, 75, 0.06), transparent 24%),
    radial-gradient(circle at 85% 12%, rgba(30, 91, 79, 0.07), transparent 18%),
    linear-gradient(180deg, #f9f6ef 0%, var(--paper) 52%, var(--paper-deep) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(to right, rgba(199, 192, 180, 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(199, 192, 180, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  opacity: 0.4;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(24, 48, 75, 0.68);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  position: relative;
  width: min(100%, 560px);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 253, 250, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-card h1 {
  margin: 0 0 14px;
  color: var(--navy);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.03;
}

.login-copy,
.login-note,
.sidebar-copy,
.workspace-subtitle {
  color: rgba(24, 48, 75, 0.72);
  line-height: 1.55;
}

.flash {
  margin: 18px 0;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 0.95rem;
}

.flash-error {
  background: rgba(139, 31, 36, 0.08);
  color: var(--red);
  border: 1px solid rgba(139, 31, 36, 0.14);
}

.login-form,
.composer {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 8px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(24, 48, 75, 0.18);
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(30, 91, 79, 0.12);
}

button {
  border: 0;
  border-radius: 16px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: var(--white);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  padding: 28px;
  border-right: 1px solid rgba(24, 48, 75, 0.09);
  background: rgba(249, 246, 239, 0.72);
  backdrop-filter: blur(18px);
}

.sidebar-top h1,
.workspace-header h2,
.empty-card h3 {
  margin: 0;
  color: var(--navy);
}

.search-box {
  display: block;
  margin-top: 18px;
}

.new-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin-top: 14px;
  align-items: end;
}

.new-chat-input {
  display: grid;
  gap: 8px;
}

.new-chat-input span {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--navy);
}

.sidebar-feedback {
  min-height: 20px;
  margin-top: 10px;
}

.conversation-list {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  padding-right: 4px;
}

.conversation-item {
  padding: 16px;
  border: 1px solid rgba(24, 48, 75, 0.09);
  border-radius: 20px;
  background: rgba(255, 253, 250, 0.82);
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.conversation-item:hover,
.conversation-item.is-active {
  border-color: rgba(30, 91, 79, 0.34);
  transform: translateY(-1px);
  background: rgba(255, 253, 250, 0.96);
}

.conversation-top,
.workspace-header,
.workspace-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.conversation-name {
  font-weight: 700;
  color: var(--navy);
}

.conversation-meta,
.message-meta,
.conversation-preview,
.composer-feedback,
.message-quote {
  color: rgba(24, 48, 75, 0.68);
}

.conversation-preview {
  margin-top: 8px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.unread-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(30, 91, 79, 0.12);
  color: var(--green);
  font-weight: 700;
  font-size: 0.85rem;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: 28px;
  gap: 18px;
}

.message-list {
  overflow: auto;
  padding-right: 6px;
  min-height: 0;
}

.message-stack {
  display: grid;
  gap: 14px;
}

.message-row {
  display: flex;
}

.message-row.outbound {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(78ch, 82%);
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid rgba(24, 48, 75, 0.08);
  box-shadow: 0 12px 32px rgba(15, 34, 54, 0.08);
  background: rgba(255, 253, 250, 0.9);
}

.message-row.outbound .message-bubble {
  background: linear-gradient(135deg, rgba(24, 48, 75, 0.98), rgba(15, 34, 54, 0.94));
  color: var(--white);
}

.message-row.outbound .message-meta,
.message-row.outbound .message-quote {
  color: rgba(255, 255, 255, 0.72);
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.5;
}

.message-quote {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed rgba(24, 48, 75, 0.18);
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.message-row.outbound .message-quote {
  border-top-color: rgba(255, 255, 255, 0.18);
}

.message-meta {
  margin-top: 10px;
  font-size: 0.82rem;
}

.empty-state {
  display: grid;
  place-items: center;
}

.empty-card {
  width: min(100%, 520px);
  padding: 30px;
  border-radius: 28px;
  background: rgba(255, 253, 250, 0.88);
  border: 1px solid rgba(24, 48, 75, 0.08);
  box-shadow: var(--shadow);
}

.composer {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.composer textarea {
  min-height: 110px;
  resize: vertical;
}

.composer-feedback {
  min-height: 24px;
  font-size: 0.92rem;
}

.composer-feedback.is-error {
  color: var(--red);
}

.logout-link {
  color: var(--navy);
  text-decoration: none;
  font-weight: 700;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(24, 48, 75, 0.09);
  }

  .conversation-list {
    max-height: 280px;
  }

  .workspace {
    min-height: calc(100vh - 360px);
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .new-chat-form {
    grid-template-columns: 1fr;
  }
}
