:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --sidebar-bg: #f9f9f9;
  --panel: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --accent: #10a37f;
  --accent-dark: #0d8b6c;
  --user-bubble: #f3f4f6;
  --overlay: rgba(17, 24, 39, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

button,
input,
textarea,
select {
  border: 1px solid var(--border);
}

button {
  background: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: flex;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand-block h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.brand-block p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.new-chat-btn {
  min-height: 44px;
  width: 100%;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 14px;
  cursor: pointer;
}

.new-chat-btn:hover {
  background: #f3f4f6;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 2px;
  overflow: auto;
  padding-right: 4px;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.current-user {
  font-size: 12px;
  color: var(--muted);
  padding: 0 2px;
}

.conversation-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border-color: transparent;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.conversation-item:hover {
  background: #ececec;
}

.conversation-item.active {
  background: #ececec;
}

.conversation-item-title,
.conversation-item-time {
  display: block;
}

.conversation-item-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 4px;
}

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

.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.chat-header {
  min-height: 60px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header-copy {
  min-width: 0;
}

.conversation-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.model-select,
.ghost-btn,
.icon-btn,
.login-form input {
  min-height: 38px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}

.model-select,
.ghost-btn,
.login-form input {
  padding: 0 12px;
}

.sidebar-footer .model-select,
.sidebar-footer .ghost-btn {
  width: 100%;
}

.ghost-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ghost-btn:hover,
.icon-btn:hover,
.model-select:hover,
.login-form input:hover,
textarea:hover {
  border-color: var(--border-strong);
}

.model-select:focus,
.ghost-btn:focus,
.icon-btn:focus,
.login-form input:focus,
textarea:focus,
.new-chat-btn:focus,
.send-btn:focus {
  outline: none;
  border-color: #86efac;
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.12);
}

.icon-btn {
  width: 38px;
  padding: 0;
  font-size: 18px;
  cursor: pointer;
}

.sidebar-toggle-btn,
.sidebar-close-btn {
  display: none;
}

.chat-body {
  flex: 1;
  min-height: 0;
}

.message-list {
  height: 100%;
  overflow: auto;
  padding: 28px 20px 120px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.assistant {
  justify-content: center;
}

.message-row.user {
  justify-content: center;
}

.message-bubble {
  width: min(100%, 768px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.message-row.user .message-bubble {
  display: flex;
  justify-content: flex-end;
}

.message-row.user .message-bubble > * {
  max-width: min(100%, 78%);
}

.message-role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.message-row.assistant .message-content {
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.message-row.user .message-content {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px 16px;
}

.message-content {
  line-height: 1.75;
  font-size: 15px;
  word-break: break-word;
  white-space: normal;
}

.message-content > :first-child {
  margin-top: 0;
}

.message-content > :last-child {
  margin-bottom: 0;
}

.message-content p {
  margin: 0 0 0.75em;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 1em 0 0.55em;
  line-height: 1.35;
  font-weight: 600;
}

.message-content h1 {
  font-size: 1.35em;
}

.message-content h2 {
  font-size: 1.22em;
}

.message-content h3 {
  font-size: 1.1em;
}

.message-content ul,
.message-content ol {
  margin: 0.55em 0 0.85em;
  padding-left: 1.4em;
}

.message-content li + li {
  margin-top: 0.25em;
}

.message-content blockquote {
  margin: 0.85em 0;
  padding-left: 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.message-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: rgba(17, 24, 39, 0.08);
  border-radius: 6px;
  padding: 0.1em 0.35em;
}

.message-content pre {
  margin: 0.9em 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #111827;
  color: #f9fafb;
  overflow: auto;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

.message-content a {
  color: #0b7a60;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content hr {
  margin: 1em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.95em;
}

.message-content th,
.message-content td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.message-content th {
  background: #f3f4f6;
}

.composer-shell {
  position: sticky;
  bottom: 0;
  padding: 0 20px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.94) 22%, rgba(255,255,255,1) 50%);
}

.composer {
  width: min(100%, 768px);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 24px;
  max-height: 180px;
  padding: 10px 6px 10px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
}

.send-btn:hover {
  background: var(--accent-dark);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.empty-state {
  width: min(100%, 768px);
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px 16px;
}

.empty-state.small {
  width: 100%;
  margin: 8px 0 0;
  padding: 14px 10px;
  text-align: left;
  font-size: 13px;
}

.sidebar-empty {
  color: var(--muted-soft);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg-soft);
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
  font-weight: 600;
}

.login-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form .ghost-btn {
  justify-content: center;
}

.primary-btn {
  min-height: 42px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.success-box {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.admin-body {
  min-height: 100vh;
  margin: 0;
  overflow: auto;
  background:
    radial-gradient(900px 420px at -6% -10%, rgba(16, 163, 127, 0.14), rgba(16, 163, 127, 0)),
    radial-gradient(760px 380px at 106% -12%, rgba(14, 165, 233, 0.12), rgba(14, 165, 233, 0)),
    var(--bg-soft);
  color: var(--text);
}

.admin-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px 16px 44px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 18px 20px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(209, 213, 219, 0.8);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(8px);
}

.admin-header h1 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0.01em;
}

.admin-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-header-actions .ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #ffffff;
}

.admin-section {
  margin-bottom: 22px;
}

.admin-section h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.admin-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
}

.admin-card {
  background: var(--panel);
  border: 1px solid rgba(209, 213, 219, 0.95);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.05);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.admin-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.08);
  border-color: #cbd5e1;
}

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

.admin-card-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: #0f172a;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 27px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}

.status-chip.enabled {
  color: #065f46;
  background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%);
  border-color: #6ee7b7;
}

.status-chip.disabled {
  color: #92400e;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border-color: #fcd34d;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 11px;
}

.admin-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #334155;
  font-weight: 500;
}

.admin-card input,
.admin-card textarea {
  border-radius: 11px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid #d1d5db;
  padding: 10px 11px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.admin-card input:hover,
.admin-card textarea:hover {
  border-color: #9ca3af;
}

.admin-card input:focus,
.admin-card textarea:focus {
  outline: none;
  border-color: #34d399;
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.16);
  background: #ffffff;
}

.admin-card textarea {
  min-height: 88px;
  resize: vertical;
}

.secret-preview {
  font-size: 13px;
  color: #475569;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 11px 12px;
}

.secret-preview code {
  color: #0f172a;
  font-weight: 600;
}

.checkbox-line {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  color: var(--text) !important;
}

.checkbox-line input {
  width: auto;
}

.admin-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

.admin-actions .primary-btn {
  min-width: 116px;
  box-shadow: 0 8px 18px rgba(16, 163, 127, 0.22);
}

.admin-actions .primary-btn:hover {
  box-shadow: 0 10px 22px rgba(13, 139, 108, 0.25);
}

@media (max-width: 900px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: min(280px, 84vw);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--overlay);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-toggle-btn,
  .sidebar-close-btn {
    display: inline-flex;
  }

  .message-list {
    padding: 22px 16px 116px;
  }

  .composer-shell {
    padding: 0 16px 16px;
  }
}

@media (max-width: 640px) {
  .chat-header {
    padding: 10px 12px;
  }

  .conversation-subtitle {
    display: none;
  }

  .model-select,
  .ghost-btn {
    min-width: 0;
    font-size: 13px;
    padding: 0 10px;
  }

  .message-list {
    padding: 18px 12px 104px;
    gap: 18px;
  }

  .message-row.user .message-bubble > * {
    max-width: min(100%, 88%);
  }

  .message-content {
    font-size: 14px;
  }

  .composer-shell {
    padding: 0 12px 12px;
  }

  .composer {
    padding: 10px;
    border-radius: 22px;
  }

  .admin-header {
    flex-direction: column;
    padding: 16px;
  }

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

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