:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #17202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

.auth {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 248, 0.92);
  padding: 18px;
}

.auth[hidden] {
  display: none;
}

.auth form {
  width: min(420px, 100%);
  border: 1px solid #d7dee6;
  background: #ffffff;
  border-radius: 8px;
  padding: 18px;
}

.auth label {
  display: block;
  font-weight: 700;
  margin: 10px 0 8px;
}

.auth div {
  display: grid;
  grid-template-columns: auto;
  gap: 10px;
  margin-top: 12px;
}

.auth input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #c8d0d9;
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
}

.auth p {
  margin-top: 10px;
  color: #9c2d2d;
}

.shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 16px;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

h1 {
  margin: 0 0 4px;
  font-size: 24px;
  line-height: 1.1;
}

p {
  margin: 0;
  color: #5d6875;
  font-size: 14px;
}

.badge {
  flex: 0 0 auto;
  border: 1px solid #cfd7df;
  background: #ffffff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
}

select {
  min-height: 38px;
  border: 1px solid #c8d0d9;
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
  font: inherit;
}

.admin {
  border: 1px solid #d7dee6;
  background: #ffffff;
  border-radius: 8px;
  padding: 12px;
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.stats-table {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-top: 1px solid #e2e6eb;
  padding: 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #5d6875;
  font-weight: 700;
}

#codexToggle.off {
  background: #9c2d2d;
}

.limits {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.limits div {
  border: 1px solid #d7dee6;
  background: #ffffff;
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.limits span {
  display: block;
  color: #66717d;
  font-size: 12px;
  margin-bottom: 6px;
}

.limits strong {
  display: block;
  font-size: 16px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.chat {
  overflow: auto;
  border: 1px solid #d7dee6;
  background: #ffffff;
  border-radius: 8px;
  padding: 14px;
}

.message {
  max-width: 860px;
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
  font-size: 14px;
}

.message.user {
  margin-left: auto;
  background: #e9f2ff;
  border: 1px solid #c8dcf8;
}

.message.assistant {
  background: #f7f8fa;
  border: 1px solid #e2e6eb;
}

.message.system {
  max-width: none;
  color: #5d6875;
  background: #fff8df;
  border: 1px solid #eadca2;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid #c8d0d9;
  border-radius: 8px;
  padding: 12px;
  font: inherit;
  line-height: 1.4;
  min-height: 72px;
}

button {
  border: 0;
  border-radius: 8px;
  background: #1769aa;
  color: #ffffff;
  min-height: 44px;
  padding: 0 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

@media (max-width: 760px) {
  .shell {
    padding: 12px;
  }

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

  .top-actions {
    justify-content: stretch;
  }

  .top-actions select,
  .top-actions button,
  .top-actions .badge {
    width: 100%;
  }

  .limits {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  button {
    width: 100%;
  }
}
