:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f23;
  --muted: #69707a;
  --border: #dfe2e6;
  --accent: #128c4a;
  --accent-text: #ffffff;
  --ok-bg: #e3f5ea;
  --ok-text: #0f6b38;
  --warn-bg: #fff4dc;
  --warn-text: #7a5200;
  --error-bg: #fde8e8;
  --error-text: #a11d1d;
  --bubble-out: #dcf5e4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e8eaed;
    --muted: #9aa1aa;
    --border: #33373d;
    --accent: #25b864;
    --accent-text: #0b1a10;
    --ok-bg: #173825;
    --ok-text: #8be0ad;
    --warn-bg: #3a2f14;
    --warn-text: #f2c96b;
    --error-bg: #3d1a1a;
    --error-text: #f19a9a;
    --bubble-out: #1f3b2a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
main.narrow { max-width: 380px; padding-top: 80px; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }
pre { white-space: pre-wrap; word-break: break-all; }

.nav {
  display: flex; gap: 20px; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav .brand { font-weight: 700; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a.active { color: var(--text); font-weight: 600; }
.nav .logout { margin-left: auto; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.cards { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; margin-bottom: 16px;
}

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
button, .button {
  padding: 8px 14px; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600;
  text-decoration: none; display: inline-block;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link { background: none; color: var(--muted); padding: 0; font-weight: 400; }
button.danger { background: var(--error-bg); color: var(--error-text); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem;
  font-weight: 600; background: var(--border); color: var(--text);
}
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.error { background: var(--error-bg); color: var(--error-text); }

.alert { padding: 10px 12px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-text); margin: 8px 0; }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }
.alert.error { background: var(--error-bg); color: var(--error-text); }
.error-text { color: var(--error-text); }

table { width: 100%; border-collapse: collapse; margin: 12px 0; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.setup { margin-top: 24px; }
.setup dd { margin: 0 0 12px; }

/* Inbox */
main.inbox { display: grid; grid-template-columns: 300px 1fr; gap: 16px; max-width: 1300px; }
.conversations { list-style: none; margin: 0; padding: 0; }
.conversations li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px; cursor: pointer;
}
.conversations li:hover { border-color: var(--accent); }
#conversation { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-height: 60vh; }
.messages { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; max-height: 60vh; overflow-y: auto; }
.bubble { max-width: 75%; padding: 8px 12px; border-radius: 10px; background: var(--bg); }
.bubble > div:first-child { white-space: pre-wrap; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble .meta { font-size: 0.75rem; color: var(--muted); display: flex; gap: 6px; margin-top: 2px; }
.reply { display: flex; gap: 8px; }
.reply input { flex: 1; }

@media (max-width: 760px) {
  main.inbox { grid-template-columns: 1fr; }
  .bubble { max-width: 90%; }
}
