:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #20242c;
  --muted: #687083;
  --line: #d9dee8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #18a67a;
  --warn: #d97706;
  --bad: #dc2626;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
}

p {
  margin: 0;
  color: var(--muted);
}

.panel,
.stats,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.loginPanel {
  margin-top: 28px;
  padding: 24px;
}

label {
  display: block;
  margin-bottom: 10px;
  font-weight: 650;
}

.loginRow {
  display: flex;
  gap: 10px;
}

input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
}

button {
  height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

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

.iconButton {
  min-width: 72px;
  background: #2d3340;
}

.appPanel {
  margin-top: 24px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.stats > div {
  min-height: 86px;
  padding: 18px;
  background: #fff;
}

.stats span {
  display: block;
  margin-bottom: 4px;
  font-size: 26px;
  font-weight: 750;
}

.stats small {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 152px;
  height: auto;
  padding: 16px;
  color: var(--text);
  text-align: left;
  background: #fff;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.card:hover {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 10px 24px rgba(26, 35, 58, 0.08);
  transform: translateY(-1px);
}

.card.loading {
  pointer-events: none;
  opacity: 0.72;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
  background: var(--ok);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.card.expired .badge,
.card.disabled .badge {
  background: var(--bad);
}

.card strong {
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.capacity {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
  margin-top: auto;
}

.capacity i {
  height: 8px;
  border-radius: 999px;
  background: var(--ok);
}

.message {
  min-height: 22px;
  margin-top: 14px;
  color: var(--warn);
}

@media (max-width: 920px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 16px;
  }

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

  .loginRow {
    flex-direction: column;
  }

  .loginRow button {
    width: 100%;
  }
}

.chatBody {
  background: #f4f5f7;
}

.chatShell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 16px;
  width: min(920px, calc(100vw - 28px));
  height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
}

.chatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
}

.linkButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  height: 38px;
  border-radius: 6px;
  color: #fff;
  background: #2d3340;
  text-decoration: none;
  font-weight: 650;
}

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

.bubble {
  width: fit-content;
  max-width: min(760px, 84%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  border-color: #bed4ff;
  background: #e8f0ff;
}

.bubble.assistant {
  align-self: flex-start;
}

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

textarea {
  width: 100%;
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.composer button {
  align-self: end;
  height: 42px;
}

@media (max-width: 620px) {
  .chatShell {
    width: min(100vw - 20px, 920px);
    padding: 12px 0;
  }

  .chatHeader {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 12px;
  }

  .bubble {
    max-width: 94%;
  }

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

  .composer button {
    width: 100%;
  }
}
