:root {
  color-scheme: dark;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --border-subtle: rgba(92, 93, 97, 0.45);
  --border-faint: rgba(92, 93, 97, 0.25);
  --bg-app: #101010;
  --bg-sidebar: #1b1b1f;
  --bg-chat: #0f0f0f;
  --bg-message-user: rgba(52, 53, 65, 0.8);
  --bg-message-assistant: rgba(64, 65, 79, 0.6);
  --bg-composer: #1d1d20;
  --text-primary: #f7f7f8;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --accent: #10a37f;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-xs: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #21222c 0%, #0f0f11 45%, #09090a 100%);
  color: var(--text-primary);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
  background: rgba(15, 15, 17, 0.9);
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
  }

  .sidebar__nav {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
  }

  .sidebar__section {
    min-width: 180px;
  }
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  gap: 12px;
  padding: 16px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar__new-chat {
  width: 100%;
  border: 1px solid var(--border-faint);
  background: transparent;
  color: var(--text-primary);
  font-weight: 600;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.sidebar__new-chat:hover {
  border-color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.sidebar__icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xs);
  font-weight: 600;
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-right: 6px;
}

.sidebar__section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar__section-title {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sidebar__chat-item-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar__chat-item {
  border: none;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  text-decoration: none;
}

.sidebar__chat-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar__chat-item.is-active {
  background: rgba(16, 163, 127, 0.2);
}

.sidebar__chat-delete {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
  opacity: 0;
  margin-left: 4px;
}

.sidebar__chat-item-wrapper:hover .sidebar__chat-delete {
  opacity: 1;
}

.sidebar__chat-delete:hover {
  color: var(--text-primary);
  background: rgba(255, 0, 0, 0.1);
}

.sidebar__chat-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.sidebar__chat-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border-faint);
  padding-top: 12px;
  flex-shrink: 0;
  margin-top: auto;
}

.sidebar__footer-item {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: color 0.2s ease;
}

.sidebar__footer-item:hover {
  color: var(--text-primary);
}

.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg-chat);
  height: 100vh;
  overflow: hidden;
}

.chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(26, 27, 33, 0.85) 0%, transparent 100%);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.chat-panel__title {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.chat-panel__title h1 {
  margin: 0;
  font-size: 1.4rem;
}

.chat-panel__subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.chat-panel__share {
  border: 1px solid var(--border-faint);
  background: transparent;
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-panel__share:hover:enabled {
  border-color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.chat-panel__share:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-panel__scroll {
  position: relative;
  padding: 24px 32px 160px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.chat-thread {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-thread__item {
  display: flex;
}

.chat-thread__item--user .chat-message__content {
  background: var(--bg-message-user);
}

.chat-thread__item--assistant .chat-message__content {
  background: var(--bg-message-assistant);
}

.chat-message {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 16px;
  width: 100%;
}

.chat-message__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-message__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.loading-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-secondary);
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.loading-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-message__content {
  padding: 18px 22px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.98rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.chat-message__content p {
  margin: 0;
}

.chat-composer {
  position: sticky;
  bottom: 0;
  padding: 24px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, transparent 0%, rgba(11, 12, 16, 0.95) 40%);
  backdrop-filter: blur(16px);
}

.chat-composer__input {
  width: 100%;
  resize: none;
  padding: 16px 20px;
  font-size: 1rem;
  line-height: 1.5;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-faint);
  background: var(--bg-composer);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
  overflow-y: hidden;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.chat-composer__input::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.chat-composer__input:focus {
  border-color: rgba(255, 255, 255, 0.4);
}

.chat-composer__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.chat-composer__send {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-xs);
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.chat-composer__send[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.chat-composer__send:not([disabled]):hover {
  filter: brightness(1.1);
}

.chat-composer__icon-button {
  position: absolute;
  right: 10px;
  bottom: 13px;
  background: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chat-composer__icon-button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-composer__icon-button:not([disabled]):hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transform: scale(1.05);
  transition: transform 0.2s, box-shadow 0.2s;
}

.chat-composer__icon-button--left {
  left: 10px;
  right: auto;
}

@media (max-width: 720px) {
  .chat-panel__header,
  .chat-panel__scroll,
  .chat-composer {
    padding-left: 18px;
    padding-right: 18px;
  }

  .chat-message {
    grid-template-columns: 32px 1fr;
    gap: 12px;
  }

  .chat-composer__actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-composer__send {
    align-self: flex-end;
  }
}

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.auth-card {
  width: min(420px, 100%);
  background: rgba(24, 24, 28, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
}

.auth-title {
  margin: 0;
  font-size: 1.8rem;
}

.auth-subtitle {
  margin-top: 8px;
  margin-bottom: 28px;
  color: var(--text-secondary);
}

.auth-error {
  margin: 0 0 20px;
  padding: 12px 16px;
  background: rgba(181, 63, 63, 0.2);
  border: 1px solid rgba(181, 63, 63, 0.6);
  border-radius: 12px;
  color: #ffb4b4;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.auth-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-faint);
  background: rgba(17, 17, 20, 0.95);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.auth-input:focus {
  border-color: rgba(255, 255, 255, 0.4);
}

.auth-submit {
  margin-top: 12px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.auth-submit:hover {
  filter: brightness(1.1);
}

.auth-footer {
  margin-top: 28px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-align: center;
}

.admin-wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.admin-title {
  margin: 0;
  font-size: 2rem;
}

.admin-subtitle {
  margin: 6px 0 0;
  color: var(--text-secondary);
}

.admin-actions {
  display: flex;
  gap: 12px;
}

.admin-link {
  color: var(--accent);
  font-weight: 600;
}

.admin-card {
  padding: 28px;
  background: rgba(24, 24, 28, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
}

.admin-card__title {
  margin-top: 0;
  font-size: 1.3rem;
}

.notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.notice--error {
  background: rgba(181, 63, 63, 0.2);
  border: 1px solid rgba(181, 63, 63, 0.6);
  color: #ffb4b4;
}

.notice--success {
  background: rgba(32, 183, 143, 0.15);
  border: 1px solid rgba(32, 183, 143, 0.6);
  color: #adffe7;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-form__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.admin-form__field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.admin-form__field input {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-faint);
  background: rgba(17, 17, 20, 0.95);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.admin-form__field input:focus {
  border-color: rgba(255, 255, 255, 0.4);
}

.admin-form__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.admin-button {
  align-self: flex-start;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.admin-button:hover {
  filter: brightness(1.1);
}

.admin-button--ghost {
  background: transparent;
  border: 1px solid var(--border-faint);
  color: var(--text-primary);
}

.admin-button--danger {
  background: rgba(181, 63, 63, 0.85);
}

.admin-table-wrapper {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.admin-table th,
.admin-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.admin-table tr.is-admin {
  background: rgba(16, 163, 127, 0.08);
}

.admin-username {
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--admin {
  background: rgba(16, 163, 127, 0.25);
  color: #adffe7;
}

.admin-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-inline-form {
  display: inline-flex;
}

.admin-self-note {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.admin-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 0;
}

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

@media (max-width: 620px) {
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-actions {
    flex-direction: column;
    width: 100%;
  }

  .admin-link {
    display: inline-flex;
    justify-content: center;
    width: 100%;
    padding: 10px 0;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.06);
  }

  .admin-form__grid {
    grid-template-columns: 1fr;
  }
}

