:root {
  --bg: #f7f7f4;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --user: #dbeafe;
  --assistant: #fef9c3;
  --error: #fee2e2;
  --pill-appointment: #c7d2fe;
  --pill-call: #bbf7d0;
  --pill-practical: #fde68a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--border);
}

.topbar .brand a { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar .who { color: var(--muted); font-size: 0.9rem; }

.inline-form { display: inline; }
.inline-form button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font: inherit;
}
.inline-form button:hover { text-decoration: underline; }

main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.flash.notice { background: #dcfce7; color: #166534; }
.flash.alert  { background: var(--error); color: #991b1b; }

.muted { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); font-style: italic; }

/* Auth */
.auth-card {
  background: var(--card);
  padding: 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  max-width: 420px;
  margin: 2rem auto;
}
.auth-card h1 { margin-top: 0; }
.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.25rem; }
.field input, .field textarea, .field select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.errors { background: var(--error); padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; }
.errors ul { margin: 0; padding-left: 1.25rem; }

.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--primary-hover); }
.btn.primary { background: var(--primary); }

/* Chat */
.chat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}
.chat-header h1 { margin: 0 0 0.25rem 0; font-size: 1.4rem; }
.messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.25rem 0;
  max-height: 60vh;
  overflow-y: auto;
}
.message {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.message-user { background: var(--user); align-self: flex-end; max-width: 85%; }
.message-assistant { background: var(--assistant); align-self: flex-start; max-width: 85%; }
.message-error { background: var(--error); align-self: stretch; }
.message-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.message-meta strong { color: var(--text); margin-right: 0.5rem; }
.message-body p { margin: 0.25rem 0; }
.message-activities {
  margin-top: 0.5rem;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.chat-input textarea {
  flex: 1;
  resize: vertical;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

/* Pills */
.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.35rem;
}
.pill-appointment { background: var(--pill-appointment); }
.pill-call { background: var(--pill-call); }
.pill-practical_service { background: var(--pill-practical); }

/* Pages */
.page {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.week-nav { display: flex; gap: 1rem; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
th.num, td.num { text-align: right; }
tfoot th { border-top: 2px solid var(--border); }

.row-actions { white-space: nowrap; }
.row-actions a, .row-actions button { margin-right: 0.5rem; }

.stack { display: flex; flex-direction: column; gap: 0.5rem; max-width: 520px; }
.row { display: flex; gap: 0.75rem; align-items: center; }
