:root{
  --bg:#0b1220;
  --panel:#ffffff;
  --ink:#0f172a;
  --muted:#6b7280;
  --line:#e5e7eb;
  --me:#00c2a8;
  --bot:#111827;
}

*{box-sizing:border-box}

html,body{
  height:100%;
  margin:0;
  background:var(--panel);
  overflow:hidden;
  -webkit-text-size-adjust:100%;
}

body{
  font:15px/1.45 system-ui,-apple-system,Segoe UI,Roboto,Inter,Arial,sans-serif;
  color:var(--ink);
  touch-action:manipulation;
}

/* touch targets >=16px, kad nesiszoomintų */
@media (hover:none), (pointer:coarse){
  input,textarea,select,button,#msg{ font-size:16px; }
}

/* PAGRINDAS: chat-as užima 100% body, jokio fixed, jokio vh */
.chat-shell{
  position:fixed;
  inset:0;
  display:flex;
  flex-direction:column;
  background:var(--panel);
  overflow:hidden;
  padding-top:52px; /* vieta header'iui */
}

/* Header – visada viršuje, nescrollinamas */
.chat-header{
  position:fixed;
  top:0;
  left:0;
  right:0;
  height:52px;
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:10px;
  padding:0 14px;
  border-bottom:1px solid var(--line);
  background:var(--panel); /* kad nebūtų permatomas */
  z-index:10;
}

/* Vienintelis scrolleris – žinutės */
.chat-timeline{
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
  padding:14px 14px 10px;
  scroll-behavior:smooth;
}

/* Close button */
.chat-close{
  position:absolute; top:0; right:0;
  margin:8px 10px 0 0;
  display:inline-flex; align-items:center; justify-content:center;
  width:28px; height:28px;
  border:1px solid var(--line); border-radius:8px;
  background:#fff; cursor:pointer;
  line-height:1; font-size:18px;
  z-index:2;
}
.chat-close:hover{ background:#f5f5f5 }

.brand{display:flex;align-items:center;gap:8px;font-weight:600}
.brand .dot{width:10px;height:10px;border-radius:50%;background:var(--me);display:inline-block}
.brand .title{letter-spacing:.2px}

/* Badges + typing spinner */
.badge{
  display:inline-block;
  padding:2px 6px;
  border-radius:6px;
  font-weight:700;
  font-size:11px;
  color:#fff;
  margin-right:6px;
}
.badge.red{background:#ef4444}
.badge.green{background:#16a34a}
.badge.amber{background:#f59e0b;color:#111}
.typing .spinner{
  display:inline-block;width:14px;height:14px;border:2px solid #d1d5db;border-top-color:#111;border-radius:50%;
  animation:spin 1s linear infinite;vertical-align:-2px;margin-right:6px
}
@keyframes spin{to{transform:rotate(360deg)}}

/* Messages */
.msg-row{display:flex;margin:6px 0}
.msg{
  max-width:min(740px,80%);
  padding:10px 12px;
  border-radius:14px;
  box-shadow:0 1px 0 rgba(0,0,0,.05);
  word-wrap:break-word;
  white-space:pre-wrap;
}
.msg.me{
  margin-left:auto;
  background:#5c7a60;
  color:#fff;
  border-bottom-right-radius:4px;
}
.msg.bot{
  margin-right:auto;
  background:#f3f4f6;
  color:var(--bot);
  border-bottom-left-radius:4px;
}
.msg.small{font-size:14px}
.meta{display:flex;gap:8px;margin:2px 4px;color:var(--muted);font-size:12px}

/* Footer – sticky apačioje, flex item, visada matomas */
.chat-inputbar{
  flex:0 0 auto;
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top:1px solid var(--line);
  background:var(--panel);
}

.icon-btn,.send-btn{
  height:40px;width:40px;border-radius:10px;border:1px solid var(--line);
  display:grid;place-items:center;background:transparent;cursor:pointer
}
.icon-btn:hover,.send-btn:hover{background:#f5f5f5}

.input-wrap{
  flex:1;
  display:flex;
  align-items:center;
}
.input-wrap textarea{
  width:100%;
  max-height:110px;
  min-height:40px;
  resize:none;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 12px;
  font:15px/1.35 inherit;
  outline:none;
  background:#fff;
  color:#111;
}
.input-wrap textarea:focus{
  border-color:#cbd5e1;
  box-shadow:0 0 0 3px rgba(0,194,168,.15)
}

/* Attachment preview */
.attach-preview{
  position:absolute;
  left:14px;
  bottom:72px;
  align-items:center;
  gap:8px;
  background:#fafafa;
  border:1px solid var(--line);
  padding:6px 8px;
  border-radius:12px;
  box-shadow:0 2px 8px rgba(0,0,0,.06);
  display:none;
}
.attach-preview[hidden]{display:none}
.attach-preview:not([hidden]){display:flex}
.attach-preview img{
  width:44px;
  height:44px;
  object-fit:cover;
  border-radius:8px;
  border:1px solid var(--line)
}
.x-btn{
  height:26px;
  width:26px;
  border:1px solid var(--line);
  border-radius:8px;
  background:transparent;
  cursor:pointer
}
.x-btn:hover{background:#f5f5f5}

/* Responsive */
@media (max-width:680px){
  .msg{max-width:90%}
  .chat-timeline{padding:10px 10px 8px}
}
