:root {
  --bg: #f7f7f8;
  --bg-soft: #f3f4f6;
  --card: rgba(255, 255, 255, 0.75);
  --card-strong: #ffffff;
  --line: rgba(17, 24, 39, 0.09);
  --line-strong: rgba(17, 24, 39, 0.13);
  --text: #111827;
  --muted: #6b7280;
  --accent: #0284c7;
  --accent-soft: #f0f9ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, "Helvetica Neue", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 420px at 78% -10%, rgba(186, 230, 253, 0.5), rgba(186, 230, 253, 0) 60%),
    radial-gradient(900px 380px at 25% 110%, rgba(209, 250, 229, 0.45), rgba(209, 250, 229, 0) 55%),
    linear-gradient(180deg, #f8fafc 0%, #f5f6f8 54%, #f7f7f8 100%);
}

.hidden {
  display: none !important;
}

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

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

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(14, 165, 233, 0.5);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.primary,
button[type="submit"] {
  border: none;
  background: #111827;
  color: #fff;
  border-radius: 12px;
  padding: 10px 13px;
  cursor: pointer;
}

.primary:hover,
button[type="submit"]:hover {
  background: #030712;
}

.ghost {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: #374151;
  padding: 8px 11px;
  text-decoration: none;
  cursor: pointer;
}

.ghost:hover {
  background: #fff;
  border-color: var(--line-strong);
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 24px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.08);
}

.auth-card h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.01em;
}

.sub {
  margin: 8px 0 16px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #374151;
}

.auth-switch {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.link-btn {
  border: 0;
  background: transparent;
  color: #0369a1;
  cursor: pointer;
  padding: 0 0 0 6px;
}

.link-btn:hover {
  text-decoration: underline;
}

.error {
  min-height: 20px;
  margin: 8px 0 0;
  color: #b91c1c;
  font-size: 13px;
}

.app-wrap {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 272px 1fr;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.sidebar-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.session-list {
  margin: 0;
  padding: 9px;
  list-style: none;
  overflow: auto;
  display: grid;
  gap: 7px;
  min-height: 0;
}

.session-item {
  border: 1px solid rgba(203, 213, 225, 0.8);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.86);
}

.session-item:hover {
  background: #fff;
  border-color: rgba(148, 163, 184, 0.65);
}

.session-item.active {
  border-color: rgba(56, 189, 248, 0.65);
  background: #f0f9ff;
}

.session-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.session-main {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  color: inherit;
  cursor: pointer;
}

.session-title {
  font-size: 14px;
  margin-bottom: 4px;
}

.session-time {
  font-size: 12px;
  color: var(--muted);
}

.session-menu-wrap {
  position: relative;
}

.session-menu-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
  opacity: 0.6;
}

.session-item:hover .session-menu-btn,
.session-menu-wrap:focus-within .session-menu-btn {
  opacity: 1;
}

.session-menu-btn:hover {
  background: #f8fafc;
  border-color: rgba(203, 213, 225, 0.9);
  color: #374151;
}

.session-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 124px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid rgba(203, 213, 225, 0.95);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.session-menu-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #374151;
  padding: 7px 8px;
  cursor: pointer;
}

.session-menu-item:hover {
  background: #f8fafc;
}

.session-menu-item.danger {
  color: #b91c1c;
}

.session-menu-item.danger:hover {
  background: #fef2f2;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 890px) clamp(160px, 20vw, 340px);
  justify-content: center;
  overflow: hidden;
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(203, 213, 225, 0.7);
  background: rgba(248, 250, 252, 0.65);
  backdrop-filter: blur(8px);
}

#userEmail {
  font-size: 14px;
  color: #4b5563;
  margin-right: auto;
}

#adminLink,
#logoutBtn {
  margin-left: 0;
}

.messages {
  padding: 16px;
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
}

.msg {
  max-width: min(84%, 780px);
  border-radius: 16px;
  padding: 10px 13px;
  line-height: 1.48;
  word-break: break-word;
}

.msg-text {
  white-space: normal;
}

.msg.user .msg-text {
  white-space: pre-wrap;
}

.msg-text > :first-child {
  margin-top: 0;
}

.msg-text > :last-child {
  margin-bottom: 0;
}

.msg-text p,
.msg-text ul,
.msg-text ol,
.msg-text pre,
.msg-text blockquote,
.msg-text table {
  margin: 0.5em 0;
}

.msg-text ul,
.msg-text ol {
  padding-left: 1.25em;
}

.msg-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  background: rgba(148, 163, 184, 0.18);
  padding: 0.12em 0.32em;
  border-radius: 6px;
}

.msg-text pre {
  overflow: auto;
  border: 1px solid rgba(203, 213, 225, 0.9);
  background: rgba(248, 250, 252, 0.95);
  border-radius: 10px;
  padding: 10px;
}

.msg-text pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.msg-text a {
  color: #0369a1;
  text-decoration: none;
}

.msg-text a:hover {
  text-decoration: underline;
}

.msg-text table {
  border-collapse: collapse;
  width: 100%;
}

.msg-text th,
.msg-text td {
  border: 1px solid rgba(203, 213, 225, 0.9);
  padding: 6px 8px;
  text-align: left;
}

.msg-text blockquote {
  border-left: 3px solid rgba(125, 211, 252, 0.9);
  margin-left: 0;
  padding-left: 10px;
  color: #475569;
}

.msg.assistant {
  justify-self: start;
  border: 1px solid rgba(203, 213, 225, 0.7);
  background: rgba(255, 255, 255, 0.9);
}

.msg.user {
  justify-self: end;
  border: 1px solid rgba(125, 211, 252, 0.8);
  background: #e0f2fe;
}

.msg-meta {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.meta-details {
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.8);
  padding: 6px 8px;
}

.meta-details summary {
  cursor: pointer;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
}

.meta-content {
  margin-top: 6px;
  font-size: 12px;
  color: #334155;
  white-space: pre-wrap;
}

.meta-title {
  margin-top: 6px;
  font-size: 12px;
  color: #475569;
  font-weight: 600;
}

.meta-list {
  margin: 4px 0 0;
  padding-left: 16px;
  font-size: 12px;
  color: #334155;
}

.meta-list a {
  color: #0369a1;
  text-decoration: none;
}

.meta-list a:hover {
  text-decoration: underline;
}

.composer {
  margin: 0 12px 12px;
  border: 1px solid rgba(209, 213, 219, 0.75);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  border-radius: 26px;
  box-shadow: 0 14px 38px rgba(15, 23, 42, 0.08);
  padding: 8px;
  display: grid;
  gap: 6px;
}

#messageInput {
  border: 0;
  background: transparent;
  box-shadow: none;
  min-height: 80px;
  max-height: 180px;
  resize: none;
  overflow: auto;
  padding: 10px 12px 0;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 4px;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-toggle {
  position: relative;
}

.tool-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: #6b7280;
  background: transparent;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
}

.tool-pill:hover {
  background: #f9fafb;
  color: #4b5563;
}

.tool-icon {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-toggle input:checked + .tool-pill {
  color: var(--accent);
  border-color: rgba(125, 211, 252, 0.95);
  background: var(--accent-soft);
}

.tool-toggle input:focus-visible + .tool-pill {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  outline-offset: 1px;
}

.send-btn {
  margin-left: auto;
  border: 0;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  padding: 9px 16px;
  cursor: pointer;
}

.send-btn:hover {
  background: #030712;
}

.right-blank {
  border-left: 1px solid rgba(226, 232, 240, 0.8);
  background:
    radial-gradient(420px 240px at 60% 20%, rgba(191, 219, 254, 0.5), rgba(191, 219, 254, 0) 65%),
    linear-gradient(180deg, rgba(248, 250, 252, 0.65), rgba(241, 245, 249, 0.25));
}

.admin-wrap {
  min-height: 100vh;
  max-width: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  padding: 14px 20px;
}

.admin-email {
  margin-left: auto;
  color: #4b5563;
  font-size: 14px;
}

.admin-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px 20px 36px;
}

.admin-main h1 {
  margin: 0 0 16px;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  padding: 14px;
}

.stat-label {
  color: #6b7280;
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
}

.admin-table-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  overflow: auto;
}

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

.admin-table th,
.admin-table td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.9);
  text-align: left;
  font-size: 14px;
}

.admin-table th {
  background: rgba(248, 250, 252, 0.95);
  color: #4b5563;
}

.badge-admin {
  display: inline-block;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 8px;
  color: #0369a1;
  background: #e0f2fe;
  border: 1px solid rgba(125, 211, 252, 0.8);
}

.badge-user {
  display: inline-block;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 8px;
  color: #6b7280;
  background: #f3f4f6;
  border: 1px solid rgba(209, 213, 219, 0.85);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .right-blank {
    display: none;
  }

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

@media (max-width: 860px) {
  .app-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: 190px 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .composer {
    margin: 0 8px 8px;
  }

  .tool-pill span:last-child {
    display: none;
  }
}

@media (max-width: 640px) {
  .admin-stats {
    grid-template-columns: 1fr;
  }
}
