:root {
  --bg: #f7fafc;
  /* page (light) */
  --panel: #ffffff;
  /* outer shell */
  --card: #ffffff;
  /* chat area */
  --ink: #0f172a;
  /* text */
  --ink-dim: #334155;
  /* muted text */
  --stroke: #e5e7eb;
  /* borders */
  --accent: #2563eb;
  /* blue */
  --accent-2: #059669;
  /* green */
  --accent-3: #b45309;
  /* amber */
  --danger: #dc2626;
  /* red */
  --ok: #16a34a;
  /* green */
  --glow: 0 10px 40px rgba(37, 99, 235, .10);
  --ring: 0 0 0 2px rgba(37, 99, 235, .35);
  --radius: 16px;

  /* mobile safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --composer-h: 64px;
  /* approx; updated below via actual padding/font size */
  --status-h: 44px;
  /* approx */
}

/* reset */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: -webkit-fill-available;
}

body {
  margin: 0;
  font-family: 'Noto Serif Devanagari', serif;
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(37, 99, 235, .08), transparent 60%),
    radial-gradient(900px 450px at 110% 0%, rgba(5, 150, 105, .08), transparent 60%),
    var(--bg);
  color: var(--ink);

  /* ✅ Prevent horizontal scroll; page itself not scrollable.
     Only the .chat area will scroll vertically. */
  overflow-x: hidden;
  overflow-y: hidden;
  width: 100%;
  max-width: 100vw;
}

/* Single panel layout */
.shell.only-panel {
  max-width: 860px;
  height: 100dvh;
  /* use dvh for mobile browser chrome */
  display: grid;
  grid-template-columns: 1fr;
  padding: 24px;
  margin: 0 auto;
  align-items: stretch;
}

@media (max-width: 980px) {
  .shell.only-panel {
    padding: 12px;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--glow);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  /* allow children to size inside flex */
  position: relative;
  /* for jump button positioning */
}

/* Chat area (only this scrolls) */
.chat {
  flex: 1 1 auto;
  background: var(--card);
  padding: 16px;
  overflow: auto;
  /* ✅ scroll container */
  min-height: 0;

  /* keep last messages visible above composer & statusbar */
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--composer-h) + var(--status-h) + var(--safe-bottom));
  scroll-padding-bottom: calc(var(--composer-h) + var(--status-h) + 20px + var(--safe-bottom));
}

@media (max-width:480px) {
  .chat {
    padding: 12px;
  }
}

/* messages */
.msg {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  padding: 10px 0;
  animation: slideUp .25s ease;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #eff6ff;
  border: 1px solid var(--stroke);
}

.bubble {
  background: #f8fafc;
  border: 1px solid var(--stroke);
  padding: 12px 14px;
  border-radius: 14px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  /* ✅ long URLs won’t cause horizontal scroll */
}

.bubble.user {
  background: #f0f9ff;
  border-color: rgba(37, 99, 235, .35);
}

.bubble.assistant {
  background: #f8fafc;
}

.bubble.success {
  border-color: rgba(5, 150, 105, .45);
}

.bubble.error {
  border-color: rgba(220, 38, 38, .55);
}

.bubble .title {
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.bubble a {
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
  word-break: break-word;
}

@keyframes slideUp {
  from {
    transform: translateY(6px);
    opacity: 0
  }

  to {
    transform: none;
    opacity: 1
  }
}

/* Composer (input + button) */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #f8fafc;
  border-top: 1px solid var(--stroke);
  flex: 0 0 auto;
  /* never collapse */
  z-index: 1;
  /* above chat content edge */

  /* update computed height hint */
  --composer-h: 60px;
}

.inputWrap {
  flex: 1;
  position: relative;
}

.input {
  width: 100%;
  padding: 14px 14px;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  outline: none;
  transition: .2s box-shadow, .2s border-color;
}

.input:focus {
  box-shadow: var(--ring);
  border-color: rgba(37, 99, 235, .6);
}

.btn {
  padding: 12px 16px;
  border: 1px solid var(--stroke);
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  color: #fff;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: .2px;

  /* ✅ keep button stable, no squeeze or line-wrap */
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 128px;
}

.btn[disabled] {
  opacity: .6;
  cursor: not-allowed;
}

@media (max-width:480px) {
  .composer {
    gap: 8px;
    padding: 10px;
    --composer-h: 56px;
  }

  .btn {
    font-size: 14px;
    padding: 10px 12px;
    min-width: unset;
  }
}

/* Status bar (inside panel bottom) */
.statusbar {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink-dim);
  font-size: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border-top: 1px solid var(--stroke);
  flex: 0 0 auto;

  /* respect bottom safe area */
  padding-bottom: calc(10px + var(--safe-bottom));
  --status-h: 44px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(37, 99, 235, .6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, .6)
  }

  70% {
    box-shadow: 0 0 0 12px rgba(37, 99, 235, 0)
  }

  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0)
  }
}

/* loader */
.loader {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce .6s infinite alternate;
}

.loader span:nth-child(2) {
  animation-delay: .2s;
}

.loader span:nth-child(3) {
  animation-delay: .4s;
}

@keyframes bounce {
  from {
    transform: translateY(0)
  }

  to {
    transform: translateY(-6px)
  }
}

/* Jump to latest FAB */
.jump {
  position: absolute;
  right: 16px;
  bottom: 140px;
  /* sits above statusbar */
  z-index: 5;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: #ffffff;
  color: var(--ink);
  box-shadow: var(--glow);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}

.jump:hover {
  filter: brightness(0.98);
}

/* Countdown chip */
.countdown {
  margin-top: 8px;
  font-weight: 600;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px dashed var(--stroke, #e5e7eb);
  border-radius: 8px;
  user-select: none;
}

.countdown-pulse {
  animation: timerpulse 1.2s ease-in-out infinite;
}

@keyframes timerpulse {
  0% {
    opacity: .55
  }

  50% {
    opacity: 1
  }

  100% {
    opacity: .55
  }
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  /* 👈 top corner */
  right: 16px;
  /* 👈 right corner */
  padding: 12px 14px;
  background: darkorange;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  color: var(--ink);
  box-shadow: var(--glow);
  z-index: 9999;
  /* ensure it's above other elements */
}

/* Switch (if you use it) */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.switch input {
  appearance: none;
  width: 36px;
  height: 22px;
  background: #f1f5f9;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  position: relative;
  outline: none;
  transition: .2s;
}

.switch input:checked {
  background: rgba(37, 99, 235, .2);
  border-color: rgba(37, 99, 235, .6);
}

.switch input:before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  left: 3px;
  top: 2px;
  transition: .2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
}

.switch input:checked:before {
  transform: translateX(14px);
}

.switch-label {
  font-size: 12px;
  color: var(--ink-dim);
}

/* --- Accessibility (focus) --- */
:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .55);
  outline-offset: 2px;
}

/* --- Small tweaks for very narrow screens --- */
@media (max-width:360px) {
  .msg {
    grid-template-columns: 32px 1fr;
  }

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .bubble {
    padding: 10px 12px;
  }
}

/* --- Print isolation (in case you print the page) --- */
@media print {

  html,
  body {
    height: auto;
  }

  body {
    overflow: visible;
    background: #fff;
  }

  .shell.only-panel {
    padding: 0;
  }

  .panel {
    border: none;
    box-shadow: none;
  }

  .composer,
  .statusbar,
  .jump,
  .toast {
    display: none !important;
  }

  .chat {
    padding: 0;
    overflow: visible;
  }
}