:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #687386;
  --line: #dce2ea;
  --brand: #166a73;
  --brand-strong: #0f5158;
  --accent: #8a5a14;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 18px 50px rgba(24, 36, 54, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

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

button.secondary {
  background: #e8edf2;
  color: var(--ink);
}

button.secondary:hover {
  background: #dce4ec;
}

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

button.danger {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #ffd4d0;
}

button.danger:hover {
  background: #ffdeda;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22, 106, 115, 0.14);
}

textarea {
  min-height: 92px;
  max-height: 240px;
  resize: vertical;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--accent);
}

.stack {
  display: grid;
  gap: 14px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 36px;
  align-items: center;
  width: min(1060px, calc(100% - 40px));
  margin: 0 auto;
}

.login-intro {
  padding: 20px 0;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--brand);
  font-weight: 800;
}

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

h1 {
  margin-bottom: 16px;
  font-size: clamp(40px, 5vw, 68px);
  line-height: 1;
}

h2 {
  margin-bottom: 20px;
  font-size: 26px;
}

.login-intro p {
  max-width: 620px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.login-card,
.settings-panel,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card {
  padding: 28px;
}

.alert {
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.5;
}

.alert.error {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #ffd4d0;
}

.alert.success {
  background: #ecfdf3;
  color: var(--success);
  border: 1px solid #b7ebc8;
}

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

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

.brand-block {
  display: grid;
  gap: 4px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand-block strong {
  font-size: 22px;
}

.brand-block span,
.chat-topbar span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 650;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.panel-actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.conversation-panel {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  display: grid;
  gap: 10px;
}

.conversation-list {
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
}

.conversation-item {
  width: 100%;
  min-height: 0;
  display: grid;
  gap: 4px;
  justify-items: start;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px;
}

.conversation-item:hover,
.conversation-item.active {
  background: #e9f5f6;
  border-color: #c5e2e5;
}

.conversation-item strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.chat-topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.chat-topbar div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.chat-topbar strong {
  font-size: 18px;
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.message {
  max-width: min(780px, 92%);
  display: grid;
  gap: 7px;
}

.message.user {
  justify-self: end;
}

.message-role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message.user .message-role {
  text-align: right;
}

.message-body,
.empty-state,
.attachment-card {
  white-space: pre-wrap;
  line-height: 1.65;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 13px 15px;
  overflow-wrap: anywhere;
}

.message.user .message-body {
  background: #e9f5f6;
  border-color: #c5e2e5;
}

.empty-state {
  color: var(--muted);
}

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

.composer textarea {
  min-height: 104px;
}

.composer-actions {
  display: grid;
  gap: 10px;
}

.pending-attachments {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 13px;
}

.pending-chip button {
  min-height: 26px;
  padding: 0 8px;
  background: transparent;
  color: var(--danger);
}

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

.attachment-list.in-message {
  margin-top: 8px;
}

.attachment-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: #fff;
  padding: 9px;
  white-space: normal;
}

.attachment-card.image {
  grid-template-columns: 84px minmax(0, 1fr);
}

.attachment-card img {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.attachment-card strong,
.attachment-card span {
  display: block;
  overflow-wrap: anywhere;
}

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

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e8edf2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.admin-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.admin-content {
  overflow-y: auto;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.create-user,
.user-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.create-user h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

.create-grid,
.user-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.user-list {
  display: grid;
  gap: 14px;
}

.user-card {
  display: grid;
  gap: 14px;
}

.user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.user-head div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.user-head span,
.usage-line {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.user-grid {
  grid-template-columns: 1.2fr 130px 150px 170px 140px 110px;
}

.usage-line {
  grid-column: 1 / -2;
}

@media (max-width: 820px) {
  .login-page,
  .chat-shell {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .login-page {
    padding: 28px 16px;
  }

  .chat-shell {
    padding: 12px;
  }

  .settings-panel {
    order: 2;
  }

  .chat-panel {
    min-height: 70vh;
  }

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

  .create-grid,
  .user-grid {
    grid-template-columns: 1fr;
  }

  .usage-line {
    grid-column: auto;
  }
}
