:root {
  --ink: #232220;
  --ink-soft: #55504a;
  --paper: #faf7f2;
  --paper-card: #ffffff;
  --paper-alt: #efe8de;
  --line: #ddd3c3;
  --brand: #9c8f80;
  --brand-dark: #776a5a;
  --accent: #2c2926;
  --danger: #b34a3f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
.hidden { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 12px; font-size: 0.8rem; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px;
  max-width: 380px;
  width: 100%;
}
.login-card h1 { font-size: 1.3rem; margin: 0 0 8px; }
.login-sub { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 24px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-row label { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.form-row input, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: var(--paper-card);
}
.form-row input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-error { color: var(--danger); font-size: 0.85rem; margin: 12px 0 0; min-height: 1em; }

/* App shell */
.app { display: flex; flex-direction: column; height: 100vh; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}
.app-title { font-weight: 700; }
.app-body { flex: 1; display: flex; overflow: hidden; }

/* Thread list */
.thread-list {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  background: var(--paper-alt);
}
.thread-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
}
.thread-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.thread-item:hover { background: rgba(0,0,0,0.03); }
.thread-item.active { background: var(--paper-card); border-left: 3px solid var(--brand); }
.thread-item-top { display: flex; align-items: center; justify-content: space-between; }
.thread-item-name { font-weight: 700; font-size: 0.9rem; }
.unread-badge {
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 1px 7px;
  font-weight: 700;
}
.thread-item-subject { font-size: 0.84rem; color: var(--ink); margin-top: 2px; }
.thread-item-preview { font-size: 0.8rem; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item-time { font-size: 0.72rem; color: var(--ink-soft); margin-top: 6px; }
.empty-state { padding: 24px 16px; color: var(--ink-soft); font-size: 0.88rem; }

/* Thread view */
.thread-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.thread-view-header { padding: 18px 28px; border-bottom: 1px solid var(--line); background: #fff; }
.thread-view-header h2 { margin: 0 0 4px; font-size: 1.1rem; }
.thread-view-header p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }

.messages { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.message {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.message.inbound { background: var(--paper-card); align-self: flex-start; }
.message.outbound { background: var(--brand); color: #fff; align-self: flex-end; border-color: var(--brand); }
.message-meta { font-size: 0.72rem; opacity: 0.75; margin-bottom: 6px; }
.message-body { font-size: 0.92rem; white-space: pre-wrap; }

.reply-form {
  border-top: 1px solid var(--line);
  padding: 16px 28px 22px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reply-form textarea { resize: vertical; }
.reply-actions { display: flex; align-items: center; gap: 14px; }
.reply-note { font-size: 0.82rem; color: var(--ink-soft); }
