:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dde3ee;
  --text: #172033;
  --muted: #6d7688;
  --accent: #1f7a5a;
  --accent-strong: #176145;
  --student: #eef3ff;
  --admin: #eaf8f1;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

.brand p,
.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.auth-panel,
.token-panel {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.auth-panel label,
.token-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.new-token {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(31, 122, 90, 0.35);
  border-radius: 7px;
  background: var(--admin);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.token-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.token-item {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.token-title {
  font-weight: 800;
}

.token-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.token-revoke {
  margin-top: 8px;
  padding: 6px 9px;
  background: #f3f5f9;
  color: var(--danger);
  font-size: 12px;
}

.auth-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
}

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

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 90, 0.14);
}

input {
  height: 40px;
  padding: 0 11px;
}

.conversation-list {
  min-height: 0;
  overflow: auto;
}

.conversation {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 14px 20px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.conversation:hover,
.conversation.active {
  background: #f1f7f4;
}

.conversation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.student-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.last-message {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 22px;
}

.empty-state {
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.message {
  max-width: min(720px, 78%);
  padding: 11px 13px;
  border-radius: 8px;
  line-height: 1.42;
  white-space: pre-wrap;
}

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

.message.admin {
  align-self: flex-end;
  background: var(--admin);
}

.message-meta {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  min-height: 56px;
  max-height: 140px;
  resize: vertical;
  padding: 11px;
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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