@font-face {
  font-family: "NB International Pro";
  src: url("/fonts/nbinternationalproreg-webfont.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "NB International Pro";
  src: url("/fonts/nbinternationalprolig-webfont.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
}

@font-face {
  font-family: "NB International Pro";
  src: url("/fonts/nbinternationalpromed-webfont.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
}

@font-face {
  font-family: "NB International Pro";
  src: url("/fonts/nbinternationalprobol-webfont.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-size: inherit;
}

:root {
  --bg: #f8fcf9;
  --fg: rgba(0, 0, 0, 0.78);
  --muted: rgba(0, 0, 0, 0.52);
  --muted-strong: rgba(0, 0, 0, 0.65);
  --border: rgba(0, 0, 0, 0.12);
  --accent: #2d5a45;
  --user-bg: rgba(0, 0, 0, 0.07);
  --user-fg: rgba(0, 0, 0, 0.78);
  --assistant-bg: transparent;
  --tool-bg: #e8f0e8;
  --tool-border: rgba(0, 0, 0, 0.1);
  --error-bg: #fdf2f2;
  --error-border: rgba(0, 0, 0, 0.08);
  --input-bg: #ffffff;
  --debug-bg: #1a261a;
  --debug-fg: rgba(255, 255, 255, 0.75);
  --debug-info: #9cdcfe;
  --debug-success: #89d185;
  --debug-warn: #dcdcaa;
  --debug-error: #f48771;
  --shimmer-dim: rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #192219;
    --fg: rgba(255, 255, 255, 0.85);
    --muted: rgba(255, 255, 255, 0.52);
    --muted-strong: rgba(255, 255, 255, 0.65);
    --border: rgba(255, 255, 255, 0.12);
    --accent: #53d55e;
    --user-bg: #264a28;
    --user-fg: rgba(255, 255, 255, 0.85);
    --assistant-bg: transparent;
    --tool-bg: rgba(255, 255, 255, 0.04);
    --tool-border: rgba(255, 255, 255, 0.08);
    --error-bg: rgba(255, 0, 0, 0.06);
    --error-border: rgba(255, 0, 0, 0.12);
    --input-bg: rgba(255, 255, 255, 0.06);
    --debug-bg: #111a11;
    --debug-fg: rgba(255, 255, 255, 0.75);
    --shimmer-dim: rgba(255, 255, 255, 0.28);
  }
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "NB International Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 400;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* Top overlay — floats over the message list with a gradient fade */

#top-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(to bottom, var(--bg) 40%, transparent);
  pointer-events: none;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  padding: 10px 12px 0;
}

#new-chat-btn {
  display: none;
  pointer-events: all;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s;
  position: relative;
  margin-top: -4px;
  margin-left: -4px;
}

#new-chat-btn:hover {
  color: var(--fg);
  background: var(--user-bg);
}

#new-chat-btn::after {
  content: "New chat";
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  display: flex;
  align-items: center;
}

#new-chat-btn:hover::after {
  opacity: 1;
}

/* Welcome state */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  padding: 24px 16px;
  text-align: center;
  min-height: 100%;
}

.welcome-logo {
  margin-bottom: -8px;
}

.welcome-logo {
  margin-bottom: 8px;
}

.welcome-subtitle {
  color: var(--muted);
  font-weight: 300;
  font-size: 17px;
  margin-bottom: 16px;
}

.welcome-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  margin-top: -8px;
}

.prompt-chip {
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  background: var(--user-bg);
  color: var(--fg);
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.3s;
}

.prompt-chip:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Messages area */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 80px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.message {
  max-width: 90%;
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: fadeIn 0.3s ease-out;
}

.message-user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-fg);
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
  animation: fadeIn 0.3s ease-out;
}

.message-assistant {
  align-self: flex-start;
  line-height: 1.6;
  max-width: 100%;
  padding-left: 0;
  padding-right: 8px;
}

.message-assistant p {
  margin-bottom: 12px;
}

.message-assistant p:last-child {
  margin-bottom: 0;
}

.message-assistant h1,
.message-assistant h2,
.message-assistant h3 {
  font-weight: 500;
  margin-bottom: 4px;
  margin-top: 12px;
}

.message-assistant h1:first-child,
.message-assistant h2:first-child,
.message-assistant h3:first-child {
  margin-top: 0;
}

.message-assistant h1 {
  font-size: 17px;
}
.message-assistant h2 {
  font-size: 15px;
}
.message-assistant h3 {
  font-size: 14px;
}

.message-assistant ul,
.message-assistant ol {
  padding-left: 20px;
  margin-bottom: 8px;
}

.message-assistant li {
  margin-bottom: 6px;
}

.message-assistant ul li::marker {
  font-size: 1.4em;
}

.message-assistant ol li::marker {
  font-size: 1.1em;
}

.message-assistant li:last-child {
  margin-bottom: 0;
}

.message-assistant code {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
}

.message-assistant pre {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin-bottom: 8px;
}

.message-assistant pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

.message-assistant a {
  color: var(--accent);
  text-decoration: underline;
}

.message-assistant strong {
  font-weight: 700;
}

.message-assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message-assistant table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 12px;
  font-size: 13px;
}

.message-assistant th {
  text-align: left;
  font-weight: 500;
  padding: 6px 12px 6px 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.message-assistant td {
  padding: 6px 12px 6px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.message-assistant tr:last-child td {
  border-bottom: none;
}

.message-tool {
  align-self: flex-start;
  max-width: 95%;
  background: var(--tool-bg);
  border: none;
  border-radius: 10px;
  font-size: 11px;
  padding: 0;
}

.message-tool summary {
  cursor: pointer;
  color: var(--muted-strong);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
  padding: 8px 12px;
}

.message-tool summary::-webkit-details-marker {
  display: none;
}

.tool-badge-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform 0.3s;
}

details[open] .tool-badge-icon {
  transform: rotate(90deg);
}

.tool-badge-count {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
}

.tool-badge-number {
  display: inline-block;
}

@keyframes countPop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

.tool-count-pop {
  animation: countPop 0.3s ease-out;
}

/* Smooth expand/collapse */
.tool-badge-content-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

details[open] .tool-badge-content-wrap {
  grid-template-rows: 1fr;
}

.tool-badge-content {
  overflow: hidden;
}

.message-tool pre {
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 11px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  white-space: pre-wrap;
}

.message-error {
  align-self: flex-start;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: rgba(180, 40, 40, 0.85);
  font-size: 12px;
}

.message-status {
  align-self: center;
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  padding: 4px;
}

/* Activity status (thinking + tool execution) */

.activity {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.activity-logo {
  flex-shrink: 0;
  display: flex;
  animation: logoBreathe 2s ease-in-out infinite;
}

@keyframes logoBreathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

.activity-text {
  font-size: 13px;
  background: linear-gradient(
    90deg,
    var(--muted) 0%,
    var(--muted) 25%,
    var(--shimmer-dim) 50%,
    var(--muted) 75%,
    var(--muted) 100%
  );
  background-size: 200% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.tool-log-entry {
  margin-bottom: 8px;
  padding: 0 12px;
  padding-top: 8px;
  border-top: 1px solid var(--tool-border);
}

.tool-log-entry:last-child {
  padding-bottom: 4px;
}

.tool-log-label {
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 4px;
}

.tool-log-error {
  color: rgba(180, 40, 40, 0.85);
}

/* Input area */

#input-form {
  padding: 12px 16px;
  background: var(--bg);
  flex-shrink: 0;
}

#input-wrapper {
  position: relative;
}

#input {
  width: 100%;
  padding: 12px 52px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  color: var(--fg);
  background: var(--input-bg);
  resize: none;
  max-height: 200px;
  line-height: 1.4;
  outline: none;
  display: block;
}

#input::placeholder {
  color: var(--muted);
}

#input:focus {
  border-color: rgba(46, 139, 58, 0.35);
}

#send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    opacity 0.3s,
    transform 0.15s ease;
}

#send-btn:hover:not(:disabled) {
  opacity: 0.85;
}

#send-btn:active:not(:disabled) {
  transform: scale(0.88);
}

#send-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Debug panel (toggle with Ctrl+Shift+D) */

#debug-panel {
  flex-shrink: 0;
}

#debug-log {
  display: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: var(--debug-bg);
  color: var(--debug-fg);
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 10px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#debug-log.visible {
  display: block;
}

.debug-line {
  user-select: text;
  -webkit-user-select: text;
}

.debug-info {
  color: var(--debug-info);
}

.debug-success {
  color: var(--debug-success);
}

.debug-warn {
  color: var(--debug-warn);
}

.debug-error {
  color: var(--debug-error);
}

/* ── API Key Setup ─────────────────────────────────────────────────────── */

#api-key-setup {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

#api-key-setup form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

#api-key-setup label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-strong);
}

#api-key-setup input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--input-bg);
  outline: none;
  width: 100%;
}

#api-key-setup input:focus {
  border-color: rgba(46, 139, 58, 0.35);
}

#api-key-setup button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
  align-self: flex-end;
}

#api-key-setup button:hover:not(:disabled) {
  opacity: 0.85;
}

#api-key-setup button:disabled {
  opacity: 0.25;
  cursor: default;
}

/* ── Settings Modal ────────────────────────────────────────────────────── */

#settings-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#settings-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

#settings-modal form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#settings-modal label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-strong);
}

#settings-modal input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--input-bg);
  outline: none;
  width: 100%;
}

#settings-modal input:focus {
  border-color: rgba(46, 139, 58, 0.35);
}

#settings-modal div {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#settings-modal button[type="button"] {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

#settings-modal button[type="button"]:hover {
  background: var(--user-bg);
}

#settings-modal button[type="submit"] {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

#settings-modal button[type="submit"]:hover:not(:disabled) {
  opacity: 0.85;
}

#settings-modal button[type="submit"]:disabled {
  opacity: 0.25;
  cursor: default;
}

/* ── Settings button (cogwheel in top overlay) ─────────────────────────── */

#settings-btn {
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s;
  position: relative;
  margin-top: -4px;
  margin-left: 2px;
}

#settings-btn:hover {
  color: var(--fg);
  background: var(--user-bg);
}

#settings-btn::after {
  content: "Settings";
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#settings-btn:hover::after {
  opacity: 1;
}
