:root {
  color-scheme: light;
  --pink-1: #fff0f7;
  --pink-2: #ffd7eb;
  --pink-3: #ff7fbd;
  --ink: #2e2230;
  --muted: #76576c;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(130, 54, 94, 0.18);
  --shadow: 0 24px 70px rgba(142, 42, 96, 0.22);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 64, 129, 0.16) 0 12.5%, rgba(255, 152, 0, 0.14) 12.5% 25%, rgba(255, 235, 59, 0.16) 25% 37.5%, rgba(76, 175, 80, 0.13) 37.5% 50%, rgba(3, 169, 244, 0.13) 50% 62.5%, rgba(63, 81, 181, 0.12) 62.5% 75%, rgba(156, 39, 176, 0.14) 75% 87.5%, rgba(255, 64, 129, 0.12) 87.5% 100%),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 34rem),
    linear-gradient(135deg, var(--pink-1), var(--pink-2));
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.login-brand p {
  margin: 5px 0 0;
  color: var(--muted);
}

.login-panel label,
.user-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.login-panel input,
.user-form input,
.user-row input {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid rgba(130, 54, 94, 0.22);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  outline: none;
}

.login-panel input:focus,
.user-form input:focus,
.user-row input:focus {
  border-color: #e83591;
  box-shadow: 0 0 0 4px rgba(232, 53, 145, 0.16);
}

.login-button,
.secondary-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.login-button {
  color: white;
  background: #e83591;
}

.secondary-button {
  padding: 0 10px;
  color: #e83591;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(130, 54, 94, 0.16);
}

.login-button:disabled,
.secondary-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: #9b174f;
  font-size: 0.88rem;
  font-weight: 700;
}

.chat-panel {
  width: min(920px, 100%);
  height: min(760px, calc(100vh - 48px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 8px 1fr auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.66);
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #fff4c7, #ffd2e8);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.75);
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: 0;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid rgba(130, 54, 94, 0.2);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

#budgetStatus {
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  flex: 0 0 auto;
}

.user-badge {
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-select {
  height: 40px;
  min-width: 132px;
  border: 1px solid rgba(130, 54, 94, 0.2);
  border-radius: 8px;
  padding: 0 34px 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  outline: none;
}

.model-select:focus {
  border-color: #e83591;
  box-shadow: 0 0 0 4px rgba(232, 53, 145, 0.16);
}

.model-select:disabled {
  opacity: 0.55;
  cursor: wait;
}

.icon-button,
.send-button,
.image-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  background: #e83591;
  transition: transform 140ms ease, filter 140ms ease;
}

.icon-button {
  width: 40px;
  height: 40px;
  font-size: 1.35rem;
}

.send-button,
.image-button {
  width: 46px;
  height: 46px;
  font-size: 1.3rem;
}

.icon-button:hover,
.send-button:hover,
.image-button:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.icon-button:disabled,
.send-button:disabled,
.image-button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.image-button {
  height: 34px;
  width: 48px;
  color: #e83591;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(130, 54, 94, 0.16);
  font-size: 0.78rem;
  font-weight: 800;
}

.rainbow-strip {
  background: linear-gradient(90deg, #ff4fa3, #ff9f1c, #ffe066, #45c26f, #31a9ff, #8b5cf6, #ff4fa3);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 22px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  max-width: 78%;
}

.message.user {
  align-self: flex-end;
}

.message.liv {
  align-self: flex-start;
}

.bubble {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(123, 45, 91, 0.1);
}

.message.user .bubble {
  color: white;
  background: linear-gradient(135deg, #df2c8a, #8b5cf6);
}

.message.liv .bubble {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 127, 189, 0.25);
}

.message.pending .bubble {
  color: var(--muted);
}

.message-image {
  display: block;
  width: min(240px, 100%);
  max-height: 260px;
  object-fit: contain;
  margin-top: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.72);
}

.composer {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
}

.composer-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.composer input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(130, 54, 94, 0.22);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: white;
  outline: none;
}

.composer input:focus {
  border-color: #e83591;
  box-shadow: 0 0 0 4px rgba(232, 53, 145, 0.16);
}

.selected-image {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px;
  border: 1px solid rgba(130, 54, 94, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.selected-image[hidden] {
  display: none;
}

.selected-image img {
  width: 44px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}

.selected-image span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-image button {
  height: 34px;
  border: 1px solid rgba(130, 54, 94, 0.18);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

.selected-image button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.tool-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 6px;
}

.emoji-panel {
  display: grid;
  grid-template-columns: repeat(18, minmax(34px, 1fr));
  gap: 6px;
}

.emoji-button {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid rgba(130, 54, 94, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 1.08rem;
  line-height: 1;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.emoji-button:hover {
  border-color: rgba(232, 53, 145, 0.42);
  background: rgba(255, 255, 255, 0.96);
  transform: translateY(-1px);
}

.emoji-button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.admin-panel {
  position: fixed;
  right: 24px;
  top: 24px;
  width: min(560px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  z-index: 5;
}

.admin-panel[hidden] {
  display: none;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.user-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 10px;
}

.users-list {
  display: grid;
  gap: 8px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(120px, 160px) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(130, 54, 94, 0.14);
  border-radius: 8px;
  background: rgba(255, 240, 247, 0.54);
}

.user-details {
  display: grid;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.user-details span {
  width: fit-content;
  padding: 2px 7px;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
  font-size: 0.76rem;
}

.user-row button {
  min-height: 36px;
  border: 1px solid rgba(130, 54, 94, 0.16);
  border-radius: 8px;
  color: #e83591;
  background: white;
  cursor: pointer;
  font-weight: 800;
}

.user-row button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    border: 0;
  }

  .topbar {
    padding: 14px;
    gap: 10px;
    align-items: flex-start;
  }

  .identity {
    gap: 10px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .user-badge {
    display: none;
  }

  .model-select {
    width: 118px;
    min-width: 118px;
    padding-left: 8px;
    font-size: 0.82rem;
  }

  .message {
    max-width: 92%;
  }

  .messages {
    padding: 16px;
  }

  .composer {
    padding: 12px;
  }

  .emoji-panel {
    grid-template-columns: repeat(9, minmax(30px, 1fr));
  }

  .emoji-button {
    height: 32px;
  }

  .image-button {
    height: 32px;
    width: 44px;
  }

  .selected-image {
    grid-template-columns: 40px minmax(0, 1fr) auto;
  }

  .selected-image img {
    width: 40px;
    height: 36px;
  }

  .admin-panel {
    right: 12px;
    top: 12px;
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .user-form,
  .user-row {
    grid-template-columns: 1fr;
  }
}
