@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Serif:wght@600;700&display=swap');

:root {
  --bg: #f4f2ef;
  --bg-accent: #faf7f3;
  --ink: #1d1a16;
  --muted: #6a5f56;
  --primary: #ef7d2a;
  --primary-ink: #ffffff;
  --surface: #ffffff;
  --surface-alt: #fff5ea;
  --border: rgba(59, 40, 23, 0.14);
  --shadow: 0 12px 30px rgba(59, 40, 23, 0.12);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at -10% -10%, #ffffff 0%, transparent 55%),
              radial-gradient(900px 500px at 110% -20%, #f8f5f1 0%, transparent 50%),
              var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 22px 18px;
  display: grid;
  grid-template-rows: 180px 1fr auto;
  gap: 10px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 6px;
}

.fixed-top {
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.fixed-top .panel {
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #111111;
  color: #f7f2ea;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: 'IBM Plex Serif', serif;
  letter-spacing: 0.04em;
}

.title .name {
  font-family: 'IBM Plex Serif', serif;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.title .sub {
  font-size: 12px;
  color: var(--muted);
}

.panel {
  background: transparent;
  border-radius: var(--radius);
  padding: 0;
  border: none;
  box-shadow: none;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.auth-actions {
  justify-content: flex-start;
  gap: 10px;
}

.token-state {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  z-index: 0;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  padding: 18px;
  width: min(420px, 92vw);
  box-shadow: 0 24px 40px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  z-index: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  font-weight: 600;
}

.modal-body {
  display: grid;
  gap: 12px;
}

.field.inline label {
  min-width: 48px;
}

.field.inline input {
  flex: 1;
}

input, textarea {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-accent);
  color: var(--ink);
  outline: none;
}

input:focus, textarea:focus {
  border-color: rgba(34, 86, 242, 0.45);
  box-shadow: 0 0 0 3px rgba(34, 86, 242, 0.15);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 10px 16px rgba(239, 125, 42, 0.25);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
}

.btn.mini {
  background: #111111;
  color: #ffffff;
  padding: 8px 12px;
  font-size: 12px;
}

.btn:hover {
  transform: translateY(-1px);
}

.chat {
  background: transparent;
  border: none;
  border-radius: var(--radius);
  padding: 16px 8px;
  overflow-y: auto;
  min-height: 48vh;
  box-shadow: none;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

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

.bubble {
  padding: 14px 16px;
  border-radius: 16px;
  max-width: 78%;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--border);
}

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

.message.user .bubble {
  background: #fff1e3;
  color: #4a2a12;
  border: 1px solid #ef7d2a;
}

.message.assistant .bubble {
  background: var(--surface);
}

.message.tool .bubble {
  background: var(--surface-alt);
}

.tool-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 12px;
  color: var(--muted);
}

.status.ok {
  color: #0b6b3a;
}

.status.err {
  color: #b20000;
}

details {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

details summary {
  cursor: pointer;
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: transparent;
  border-radius: var(--radius);
  padding: 10px 0;
  border: none;
  box-shadow: none;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ef7d2a;
  opacity: 0.4;
  animation: pulse 1.2s infinite;
}

.typing .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  50% { transform: translateY(-3px); opacity: 1; }
}

.input-wrap {
  display: flex;
}

#messageInput {
  width: 100%;
  min-height: 44px;
  resize: none;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
}

@media (max-width: 720px) {
  .app {
    padding: 16px 14px 16px;
  }

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

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

  .bubble {
    max-width: 100%;
  }

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

  .chat {
    padding: 10px 4px;
  }

  .btn.primary {
    width: 100%;
  }
}
