:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #eef3f1;
  --line: #d8e1dd;
  --line-strong: #bdcbc6;
  --text: #17211d;
  --muted: #64716c;
  --faint: #8a9792;
  --accent: #24715e;
  --accent-strong: #155846;
  --accent-soft: #e0f0eb;
  --amber: #93620e;
  --amber-soft: #fff3d8;
  --danger: #a73535;
  --danger-soft: #fbe4e4;
  --shadow: 0 18px 45px rgba(30, 45, 38, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(280px, 440px);
  justify-content: center;
  align-items: center;
  gap: 28px;
  padding: 32px;
}

.login-card,
.login-disclosure,
.admin-card,
.insight-section,
.notice-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-card {
  padding: 34px;
  box-shadow: var(--shadow);
}

.brand-lockup,
.side-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 34px;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
  margin-bottom: 6px;
  letter-spacing: 0;
}

h3 {
  font-size: 16px;
  line-height: 1.3;
  margin-bottom: 14px;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.login-form,
.admin-card {
  display: grid;
  gap: 14px;
}

.login-form {
  margin-top: 30px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 7px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 750;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: #b8d8cf;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.button-icon {
  font-weight: 850;
}

.full-width {
  width: 100%;
}

.login-disclosure {
  padding: 30px;
}

.small-title {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
}

.disclosure-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.disclosure-grid span {
  color: var(--muted);
}

.form-error,
.form-status {
  min-height: 22px;
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--danger);
}

.form-status {
  color: var(--accent);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 340px;
}

.sidebar,
.insight-pane,
.admin-pane {
  min-width: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.side-brand strong {
  display: block;
  font-size: 15px;
}

.side-brand span:last-child {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.side-section h2,
.notice-box h2 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

.conversation-list {
  display: grid;
  gap: 8px;
}

.conversation-item {
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface-muted);
  border-color: var(--line);
}

.conversation-item strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

.conversation-item span {
  color: var(--muted);
  font-size: 12px;
}

.notice-box {
  margin-top: auto;
  padding: 13px;
}

.notice-box p {
  font-size: 13px;
  margin-bottom: 0;
}

.chat-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #fff;
}

.chat-header,
.admin-header {
  min-height: 82px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.chat-header p,
.admin-header p {
  margin-bottom: 0;
  font-size: 14px;
}

.risk-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--line);
}

.risk-badge.coaching {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.risk-badge.elevated {
  background: var(--amber-soft);
  color: var(--amber);
}

.risk-badge.safeguarding {
  background: var(--danger-soft);
  color: var(--danger);
}

.chat-thread {
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  max-width: 620px;
  margin: auto;
  text-align: center;
}

.empty-state h2 {
  font-size: 28px;
}

.message {
  max-width: 760px;
  border-radius: 8px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  line-height: 1.58;
}

.message.parent {
  align-self: flex-end;
  background: #1f3f35;
  color: #fff;
  border-color: #1f3f35;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
}

.message p,
.message ul,
.message ol,
.message blockquote,
.message .message-table-wrap {
  margin-bottom: 10px;
}

.message h1,
.message h2,
.message h3 {
  margin: 12px 0 7px;
  color: var(--accent-strong);
  line-height: 1.25;
}

.message h1 {
  font-size: 1.2rem;
}

.message h2 {
  font-size: 1.05rem;
}

.message h3 {
  font-size: 0.96rem;
}

.message ul,
.message ol {
  padding-left: 22px;
}

.message li {
  margin: 5px 0;
}

.message blockquote {
  border-left: 3px solid #9ac7b8;
  padding: 8px 12px;
  background: #eef7f3;
  border-radius: 0 8px 8px 0;
}

.message blockquote p:last-child {
  margin-bottom: 0;
}

.message hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 13px 0;
}

.message code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #eef3f0;
  padding: 1px 5px;
  font-size: 0.92em;
}

.message strong {
  color: var(--text);
}

.message em {
  color: var(--muted);
}

.message-table-wrap {
  overflow-x: auto;
}

.message table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
  font-size: 0.9rem;
}

.message th,
.message td {
  border: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}

.message th {
  background: #eef7f3;
  color: var(--accent-strong);
}

.message > *:last-child {
  margin-bottom: 0;
}

.message.parent p {
  color: #fff;
}

.message.parent strong,
.message.parent em,
.message.parent h1,
.message.parent h2,
.message.parent h3 {
  color: #fff;
}

.composer {
  padding: 18px 24px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  background: #fbfcfb;
}

.insight-pane {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.insight-section {
  padding: 15px;
}

.insight-section.amber {
  background: var(--amber-soft);
  border-color: #efd8a7;
}

.insight-section.amber h2,
.insight-section.amber p {
  color: var(--amber);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading span {
  color: var(--faint);
  font-size: 12px;
  font-weight: 750;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tag-list span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 760;
  color: var(--accent-strong);
}

.source-list {
  display: grid;
  gap: 10px;
}

.source-item {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.source-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-item p,
.empty-note {
  font-size: 12px;
  margin: 5px 0 0;
  overflow-wrap: anywhere;
}

.admin-pane {
  grid-column: 2 / 4;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  background: #fff;
}

.admin-grid {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  padding: 22px;
}

.admin-card {
  align-self: start;
  padding: 18px;
}

.chat-review-card {
  min-width: 0;
}

.admin-chat-list {
  display: grid;
  gap: 12px;
}

.admin-chat-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfb;
}

.admin-chat-item header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.admin-chat-item strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.admin-chat-item .meta {
  color: var(--muted);
  font-size: 12px;
}

.admin-chat-item details {
  margin-top: 10px;
}

.admin-chat-item summary {
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 760;
  font-size: 13px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 240px minmax(420px, 1fr);
  }

  .insight-pane {
    grid-column: 1 / 3;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .admin-pane {
    grid-column: 2;
  }
}

@media (max-width: 760px) {
  .login-view,
  .app-shell,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .login-view {
    padding: 18px;
  }

  .sidebar,
  .insight-pane,
  .admin-pane {
    border-left: 0;
    border-right: 0;
  }

  .insight-pane,
  .admin-pane {
    grid-column: 1;
  }

  .insight-pane {
    display: flex;
    flex-direction: column;
  }

  .message p,
  .message li,
  .message h1,
  .message h2,
  .message h3,
  .message th,
  .message td,
  .conversation-item strong {
    overflow-wrap: anywhere;
  }

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

  .message {
    max-width: 100%;
  }
}
