:root {
  --ink: #10231c;
  --muted: #4d6359;
  --paper: #f3f7f4;
  --panel: #ffffff;
  --accent: #0f7a5a;
  --accent-deep: #095c44;
  --glow: #c8f0df;
  --line: rgba(16, 35, 28, 0.1);
  --user-bg: #0f7a5a;
  --user-fg: #f4fff9;
  --assistant-bg: rgba(255, 255, 255, 0.72);
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(16, 35, 28, 0.1);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
  --radius: 1.25rem;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 12% 8%, rgba(200, 240, 223, 0.95), transparent 40%),
    radial-gradient(circle at 92% 0%, rgba(15, 122, 90, 0.16), transparent 36%),
    linear-gradient(160deg, #eef6f1 0%, #f7faf8 48%, #e7f1ec 100%);
  overflow: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(16, 35, 28, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 35, 28, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 88%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-14px); }
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 880px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 0.25rem 0.85rem;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  font-size: 0.78rem;
  backdrop-filter: blur(8px);
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #b08900;
}

.status-pill.ok .status-dot { background: var(--accent); }
.status-pill.bad .status-dot { background: var(--danger); }

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.ghost-btn:hover {
  background: #fff;
  border-color: rgba(15, 122, 90, 0.35);
}

.ghost-btn:active {
  transform: scale(0.98);
}

.chat-shell {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 0.15rem);
  background: rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.1rem 1rem;
  scroll-behavior: smooth;
}

.empty {
  height: 100%;
  min-height: 280px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem 1rem;
  animation: rise 0.55s ease both;
}

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

.empty h1 {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  letter-spacing: -0.03em;
  font-weight: 650;
}

.empty p {
  margin: 0 auto;
  max-width: 28rem;
  color: var(--muted);
  line-height: 1.55;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  margin-top: 1.35rem;
}

.suggestion {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.suggestion:hover {
  border-color: rgba(15, 122, 90, 0.4);
  background: #fff;
  transform: translateY(-1px);
}

.row {
  display: flex;
  margin: 0 0 1rem;
  animation: rise 0.35s ease both;
}

.row.user { justify-content: flex-end; }
.row.assistant { justify-content: flex-start; }

.bubble {
  max-width: min(100%, 640px);
  padding: 0.85rem 1rem;
  border-radius: 1.1rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.97rem;
}

.row.user .bubble {
  background: var(--user-bg);
  color: var(--user-fg);
  border-bottom-right-radius: 0.35rem;
}

.row.assistant .bubble {
  background: var(--assistant-bg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 0.35rem;
}

.thinking {
  margin-bottom: 0.65rem;
  border: 1px dashed rgba(15, 122, 90, 0.35);
  border-radius: 0.85rem;
  background: rgba(200, 240, 223, 0.35);
  overflow: hidden;
}

.thinking summary {
  cursor: pointer;
  padding: 0.45rem 0.7rem;
  color: var(--accent-deep);
  font-size: 0.8rem;
  font-weight: 600;
  list-style: none;
}

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

.thinking-body {
  padding: 0 0.7rem 0.65rem;
  color: var(--muted);
  font-size: 0.84rem;
  white-space: pre-wrap;
}

.composer-wrap {
  padding: 0.9rem 0 1.15rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(12px);
  border-radius: calc(var(--radius) + 0.2rem);
  padding: 0.7rem;
  box-shadow: var(--shadow);
}

.composer:focus-within {
  border-color: rgba(15, 122, 90, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 122, 90, 0.12), var(--shadow);
}

textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.45;
  max-height: 160px;
  padding: 0.45rem 0.5rem;
}

textarea::placeholder { color: #7a9086; }

.send {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(160deg, var(--accent), var(--accent-deep));
  color: #f4fff9;
  font: inherit;
  font-weight: 650;
  font-size: 0.9rem;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease, opacity 0.2s ease;
}

.send:hover { filter: brightness(1.05); }
.send:active { transform: scale(0.98); }
.send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.55rem;
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

.cursor {
  display: inline-block;
  width: 0.45rem;
  height: 1em;
  margin-left: 0.1rem;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.error-banner {
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(180, 35, 24, 0.25);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
  font-size: 0.88rem;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(16, 35, 28, 0.28);
  backdrop-filter: blur(6px);
}

.auth-card {
  width: min(100%, 380px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  padding: 1.35rem;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.45rem;
}

.auth-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.7rem 0.85rem;
  font: inherit;
  margin-bottom: 0.75rem;
}

.auth-card input:focus {
  outline: 2px solid rgba(15, 122, 90, 0.25);
  border-color: rgba(15, 122, 90, 0.45);
}

.hidden { display: none !important; }

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .bubble { max-width: 100%; }
  .composer { grid-template-columns: 1fr; }
  .send { width: 100%; }
}
