:root {
  --bg: #e7e1d4;
  --panel: #f9f5ec;
  --panel-2: #f3efe6;
  --ink: #1c1a16;
  --muted: #6d665b;
  --accent: #1d7a6a;
  --accent-soft: #cfe6df;
  --field: #fdfbf6;
  --border: #ded6c6;
  --bubble: #fbfaf6;
  --bubble-me: #e3f1ec;
  --shadow: 0 16px 30px rgba(18, 16, 10, 0.12);
  --sidebar-width: 480px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", "IBM Plex Sans", "Trebuchet MS", sans-serif;
  background: radial-gradient(1200px 700px at 10% 10%, #f5efe4 0%, #e2e7df 55%, #d4e0dc 100%);
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(200px 200px at 80% 20%, rgba(29, 122, 106, 0.12), transparent 60%),
    radial-gradient(300px 300px at 15% 80%, rgba(205, 170, 90, 0.14), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 20px;
  box-shadow: var(--shadow);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: "Fraunces", "Bitter", "Georgia", serif;
  font-size: 1.1rem;
}

.brand__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px var(--accent-soft);
}

.status {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--panel-2);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) 8px 1fr;
  gap: 18px;
  animation: liftIn 420ms ease both;
}

.resize-handle {
  width: 8px;
  border: none;
  background: transparent;
  cursor: col-resize;
  position: relative;
}

.resize-handle::before {
  content: "";
  position: absolute;
  inset: 6px 2px;
  border-radius: 999px;
  background: rgba(29, 122, 106, 0.2);
  transition: background 0.15s ease;
}

.resize-handle:hover::before,
.resize-handle:focus-visible::before {
  background: rgba(29, 122, 106, 0.45);
}

.resize-handle:focus-visible {
  outline: 2px solid rgba(29, 122, 106, 0.45);
  outline-offset: 2px;
}

.app[aria-hidden="true"] {
  filter: blur(2px);
  pointer-events: none;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar__header h1 {
  font-family: "Fraunces", "Bitter", "Georgia", serif;
  font-size: 1.4rem;
  margin: 0;
}

.sidebar__count {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.sidebar__search input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--field);
  font-size: 0.9rem;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar__status {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 0 2px;
  min-height: 18px;
}

.conversation {
  padding: 12px 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  animation: riseIn 300ms ease both;
  animation-delay: var(--delay, 0ms);
}

.conversation:hover {
  transform: translateY(-1px);
  border-color: rgba(29, 122, 106, 0.4);
  box-shadow: 0 8px 18px rgba(30, 26, 18, 0.12);
}

.conversation:focus-visible {
  outline: 2px solid rgba(29, 122, 106, 0.45);
  outline-offset: 2px;
}

.conversation--active {
  border-color: var(--accent);
  box-shadow: 0 10px 22px rgba(29, 122, 106, 0.18);
}

.conversation__sender {
  font-weight: 600;
  font-size: 0.98rem;
  word-break: break-word;
  text-align: right;
}

.conversation__subject {
  font-weight: 500;
  font-size: 0.88rem;
  margin-top: 4px;
  word-break: break-word;
}

.conversation--unread .conversation__sender {
  font-weight: 700;
}

.conversation__preview {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.conversation__meta {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.thread {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 0;
  position: relative;
  box-shadow: var(--shadow);
}

.thread__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
}

.thread__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.thread__subject {
  font-weight: 700;
  font-size: 1.1rem;
}

.thread__meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.thread__messages {
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 6px;
  user-select: text;
}

.thread__status {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 6px 0 10px;
}

.message {
  max-width: 70%;
  padding: 12px 14px;
  background: var(--bubble);
  border: 1px solid var(--border);
  border-radius: 16px;
  align-self: flex-start;
  user-select: text;
}

.message--me {
  align-self: flex-end;
  background: var(--bubble-me);
  border-color: rgba(29, 122, 106, 0.4);
}

.message__meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
  user-select: text;
}

.message__body {
  white-space: pre-wrap;
  line-height: 1.4;
  user-select: text;
  cursor: text;
}

.primary {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 10px 20px rgba(29, 122, 106, 0.25);
}

.primary:hover {
  transform: translateY(-1px);
}

.ghost {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.ghost:hover {
  border-color: rgba(29, 122, 106, 0.4);
}

.auth {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(28, 26, 22, 0.35);
  backdrop-filter: blur(6px);
  padding: 24px;
  z-index: 10;
}

.auth[hidden] {
  display: none;
}

.auth__card {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 24px;
  border: 1px solid var(--border);
  padding: 26px;
  box-shadow: 0 18px 40px rgba(13, 12, 10, 0.24);
  display: grid;
  gap: 16px;
  animation: popIn 320ms ease both;
}

.auth__brand {
  font-family: "Fraunces", "Bitter", "Georgia", serif;
  font-size: 1.4rem;
}

.auth__desc {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--field);
  font-size: 0.95rem;
  color: var(--ink);
}

.auth__error {
  background: #f2d8d8;
  color: #6d2b2b;
  border: 1px solid #e5b9b9;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

@keyframes liftIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .page {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .page {
    padding: 16px;
  }

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

  .sidebar {
    max-height: 40vh;
  }

  .resize-handle {
    display: none;
  }
}
