:root {
  color-scheme: dark;

  --bg: #17191a;
  --panel: #222527;
  --panel-2: #2a2e31;
  --panel-3: #1c1f21;

  --text: #e5e7e8;
  --muted: #aeb3b7;

  --border: #3c4145;
  --border-strong: #555d63;

  --accent: #b4c7d2;
  --danger: #d3a3a3;
  --ok: #a7c2ae;

  --shadow:
    0 14px 36px rgba(0, 0, 0, .24);
}

* {
  box-sizing: border-box;
}

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

body {
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

button:disabled {
  opacity: .55;
  cursor: progress;
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 1rem 1rem 8rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
}

.brand p {
  margin: .3rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.library-panel {
  padding: .8rem;
  margin-bottom: 1rem;
}

.library-panel details + details {
  margin-top: .6rem;
}

summary {
  cursor: pointer;
  user-select: none;
}

.quick-grid {
  display: grid;
  grid-template-columns:
    repeat(auto-fit, minmax(210px, 1fr));
  gap: .55rem;
  margin-top: .7rem;
}

.list {
  display: grid;
  gap: .45rem;
  margin-top: .7rem;
}

.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .45rem;
  align-items: center;
}

.list-item > button:first-child {
  text-align: left;
}

.chat {
  min-height: 54vh;
  padding: 1rem;
  overflow-wrap: anywhere;
}

.empty-chat {
  display: grid;
  gap: .35rem;
  place-content: center;
  min-height: 48vh;
  text-align: center;
  color: var(--muted);
}

.empty-chat strong {
  color: var(--text);
  font-size: 1.08rem;
}

.message {
  max-width: 91%;
  margin: 0 0 1rem;
}

.message.user {
  margin-left: auto;
}

.bubble {
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel-3);
}

.message.user .bubble {
  background: #2a2e31;
}

.message-content {
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.message.user .message-content {
  white-space: pre-wrap;
}

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

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

.message-content p {
  margin: 0 0 .9rem;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 1.05rem 0 .55rem;
  line-height: 1.3;
}

.message-content h1 {
  font-size: 1.3rem;
}

.message-content h2 {
  font-size: 1.2rem;
}

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

.message-content ul,
.message-content ol {
  margin: .55rem 0 .9rem 1.35rem;
  padding: 0;
}

.message-content li {
  margin: .3rem 0;
}

.message-content blockquote {
  margin: .8rem 0;
  padding: .1rem 0 .1rem .8rem;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.message-content code {
  padding: .12rem .3rem;
  border-radius: .35rem;
  background: #131516;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: .92em;
}

.message-content pre {
  overflow-x: auto;
  margin: .85rem 0;
  padding: .85rem;
  border: 1px solid var(--border);
  border-radius: .65rem;
  background: #131516;
}

.message-content pre code {
  padding: 0;
  background: transparent;
}

.message small {
  display: block;
  margin-top: .55rem;
  color: var(--muted);
  font-size: .78rem;
}

.research {
  margin-top: .75rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .88rem;
}

.research pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.status {
  min-height: 1.5rem;
  margin: .7rem 0;
  color: var(--muted);
  font-size: .9rem;
}

.status.error,
.error {
  color: var(--danger);
}

.ok {
  color: var(--ok);
}

.app-footer {
  min-height: 1.2rem;
  color: var(--muted);
  font-size: .76rem;
  text-align: center;
}

.composer {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  width: min(calc(100% - 1rem), 980px);
  transform: translateX(-50%);
  padding: .7rem;
  background:
    linear-gradient(
      180deg,
      rgba(23, 25, 26, 0),
      rgba(23, 25, 26, .98) 22%
    );
}

.composer-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
  padding: .65rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

#messageInput {
  min-height: 50px;
  max-height: 180px;
  resize: vertical;
  padding: .55rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.primary-button,
.secondary-button,
.icon-button,
.quick-button {
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: .7rem;
  background: var(--panel);
  color: var(--text);
}

.primary-button {
  border-color: var(--border-strong);
  background: #31383d;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.quick-button:hover {
  background: var(--panel-2);
}

.quick-button {
  text-align: left;
  line-height: 1.35;
}

.drawer-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  background: rgba(0, 0, 0, .5);
}

.drawer {
  position: fixed;
  z-index: 31;
  top: 0;
  right: 0;
  bottom: 0;

  width: min(94vw, 440px);
  padding: 1rem;

  overflow-y: auto;
  overscroll-behavior: contain;

  border-left: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.drawer-header {
  position: sticky;
  z-index: 2;
  top: -1rem;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;

  margin: -1rem -1rem 1rem;
  padding: 1rem;

  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.drawer-header h2 {
  margin: 0;
}

.settings-section {
  padding: .8rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-section h3 {
  margin: 0 0 .75rem;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: .35rem;
  margin-bottom: .85rem;
}

.field label {
  color: var(--muted);
  font-size: .88rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: .7rem;
  border: 1px solid var(--border);
  border-radius: .65rem;
  background: #181a1b;
  color: var(--text);
}

.field textarea {
  min-height: 105px;
  resize: vertical;
}

.advanced-settings {
  margin: 1rem 0;
  padding: .8rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
}

.advanced-settings[open] summary {
  margin-bottom: .8rem;
}

.settings-note {
  margin: 1rem 0;
}

.settings-actions {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  padding-bottom: 1rem;
}

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

.hidden {
  display: none !important;
}

@media (max-width: 680px) {
  .app-shell {
    padding-inline: .6rem;
  }

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

  .message {
    max-width: 100%;
  }

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

  .settings-actions {
    flex-direction: column;
  }
}


.check-field {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .65rem;
  align-items: start;
  margin: .2rem 0 1rem;
  color: var(--text);
}

.check-field input {
  margin-top: .22rem;
}

.check-field span {
  display: grid;
  gap: .2rem;
}

.check-field small {
  color: var(--muted);
  line-height: 1.45;
}

.field input:disabled,
.field textarea:disabled,
.field select:disabled {
  opacity: .55;
  cursor: not-allowed;
}


.toolbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.help-inline {
  margin-left: .45rem;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 500;
  text-decoration: none;
}

.help-inline:hover {
  text-decoration: underline;
}

.help-page {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.help-card {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
}

.help-card h2 {
  margin-top: 0;
}

.help-card code {
  padding: .12rem .3rem;
  border-radius: .35rem;
  background: #131516;
}

.help-card a {
  overflow-wrap: anywhere;
}


.settings-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}

.settings-action-grid > * {
  width: 100%;
}

@media (max-width: 520px) {
  .settings-action-grid {
    grid-template-columns: 1fr;
  }
}
