:root {
  --ag-bg: #f3f6f4;
  --ag-ink: #14231a;
  --ag-muted: #5b6b61;
  --ag-green: #1b6b3a;
  --ag-green-dark: #0f3d24;
  --ag-line: #d7e0da;
  --ag-card: #ffffff;
  --ag-user: #1b6b3a;
  --ag-bot: #ffffff;
  --ag-danger: #b91c1c;
  --ag-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ag-safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ag-ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(27, 107, 58, 0.12), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(15, 61, 36, 0.08), transparent 50%),
    var(--ag-bg);
}

.ag-login-body {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.ag-login { width: min(400px, 100%); }
.ag-login-card {
  background: var(--ag-card);
  border: 1px solid var(--ag-line);
  border-radius: 20px;
  padding: 1.5rem 1.35rem 1.35rem;
  box-shadow: 0 18px 40px rgba(20, 35, 26, 0.08);
}
.ag-brand {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ag-green);
  font-weight: 700;
}
.ag-login-card h1,
.ag-top h1 {
  margin: 0.2rem 0 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
.ag-login-sub {
  margin: 0.35rem 0 1.1rem;
  color: var(--ag-muted);
  font-size: 0.92rem;
}
.ag-login-card label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
}
.ag-login-card input {
  width: 100%;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  background: #fff;
}
.ag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.ag-btn-primary {
  width: 100%;
  margin-top: 1.1rem;
  background: var(--ag-green-dark);
  color: #fff;
}
.ag-alert {
  background: #fef2f2;
  color: var(--ag-danger);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
}

.ag-body {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 720px;
  margin: 0 auto;
}

.ag-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: calc(0.7rem + var(--ag-safe-top)) 1rem 0.7rem;
  border-bottom: 1px solid var(--ag-line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.ag-identity {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.ag-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--ag-line);
  flex-shrink: 0;
}
.ag-top h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.ag-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--ag-line);
  background: #fff;
  color: var(--ag-green-dark);
  font-weight: 700;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
}
.ag-logout:hover { background: #eef3f0; }

.ag-main {
  min-height: 0;
  overflow: auto;
  padding: 1rem 0.85rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.ag-messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
}

.ag-bubble {
  max-width: 92%;
  padding: 0.85rem 1rem;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.ag-bubble--user {
  align-self: flex-end;
  background: var(--ag-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.ag-bubble--bot {
  align-self: flex-start;
  background: var(--ag-bot);
  border: 1px solid var(--ag-line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 6px 16px rgba(20, 35, 26, 0.04);
}
.ag-bubble--meta {
  font-size: 0.78rem;
  color: var(--ag-muted);
  margin-top: 0.45rem;
}
.ag-bubble--error {
  border-color: #fecaca;
  background: #fff7f7;
  color: #991b1b;
}
.ag-bubble--voice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ag-voice-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ag-composer {
  position: sticky;
  bottom: 0;
  padding: 0.55rem 0.75rem calc(0.75rem + var(--ag-safe-bottom));
  background: rgba(243, 246, 244, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--ag-line);
}
.ag-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: #fff;
  border: 1px solid var(--ag-line);
  border-radius: 22px;
  padding: 0.45rem 0.5rem 0.4rem;
  box-shadow: 0 10px 24px rgba(20, 35, 26, 0.06);
}
.ag-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.ag-tools {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
}
.ag-attach-preview {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0 0.15rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}
.ag-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--ag-line);
  background: #fff;
}
.ag-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ag-thumb-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.ag-bubble-imgs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}
.ag-bubble-imgs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.35);
}
.ag-bubble--bot .ag-bubble-imgs img {
  border-color: var(--ag-line);
}
.ag-form textarea {
  resize: none;
  border: 0;
  outline: none;
  font: inherit;
  padding: 0.65rem 0.25rem;
  max-height: 140px;
  min-height: 44px;
  background: transparent;
}
.ag-icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: #eef3f0;
  color: var(--ag-green-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.ag-icon-btn.ag-send {
  background: var(--ag-green-dark);
  color: #fff;
}
.ag-icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ag-icon-btn.is-recording {
  background: #fee2e2;
  color: #b91c1c;
}
.ag-voice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0.15rem 0;
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--ag-line);
  border-radius: 999px;
  background: #fff;
  color: var(--ag-ink);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.ag-voice-toggle input {
  accent-color: var(--ag-green);
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
}
.ag-hint {
  margin: 0.45rem 0.2rem 0;
  font-size: 0.72rem;
  color: var(--ag-muted);
  line-height: 1.35;
}
.ag-recording[hidden],
.ag-attach-preview[hidden] {
  display: none !important;
}
.ag-recording {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #991b1b;
}
.ag-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: agPulse 1s ease-in-out infinite;
}
.ag-text-btn {
  border: 0;
  background: transparent;
  color: var(--ag-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.ag-text-btn--send {
  margin-left: auto;
  color: #fff;
  background: var(--ag-green-dark);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
}
@keyframes agPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.ag-bubble video,
.ag-bubble audio { width: 100%; margin-top: 0.45rem; border-radius: 10px; background: #0f172a; }
.ag-bubble video { max-height: 320px; }
.ag-media-link { display: inline-block; margin-top: 0.15rem; color: #166534; font-weight: 700; text-decoration: none; }
.ag-media-link:hover { text-decoration: underline; }

@media (min-width: 720px) {
  .ag-body {
    border-left: 1px solid var(--ag-line);
    border-right: 1px solid var(--ag-line);
    background: rgba(255,255,255,0.35);
  }
}
