/* =========================================================
   NEURA — Neo Brutalism AI Chat
   Design tokens
   ========================================================= */
:root{
  /* base */
  --bg: #FBF6EA;
  --bg-grid: #EFE7D3;
  --ink: #17161C;
  --border: #17161C;
  --shadow: #17161C;
  --card: #FFFFFF;
  --muted: #6f6c60;

  /* accent palette — warm cream base + cobalt / coral / acid-lime / violet */
  --cobalt: #3355FF;
  --coral: #FF5A46;
  --lime: #C6F135;
  --violet: #8A5CFF;
  --sun: #FFC53D;

  --user-bubble: var(--sun);
  --ai-bubble: #FFFFFF;
  --danger: #E8394B;
  --success: #1F9E77;

  --radius: 16px;
  --border-w: 4px;
}
html[data-theme="dark"]{
  --bg: #14141A;
  --bg-grid: #1D1D25;
  --ink: #F3EFE2;
  --border: #F3EFE2;
  --shadow: #000000;
  --card: #1F1F28;
  --muted: #9c9a90;

  --cobalt: #6E85FF;
  --coral: #FF7A66;
  --lime: #D3F65C;
  --violet: #A481FF;
  --sun: #FFC53D;

  --user-bubble: var(--sun);
  --ai-bubble: #1F1F28;
  --danger: #FF6B7A;
  --success: #3FCB9C;
}

*{ box-sizing:border-box; }
html,body{
  margin:0; padding:0; height:100%;
  background: var(--bg);
  color: var(--ink);
  font-family:'Plus Jakarta Sans', sans-serif;
  overflow-x:hidden;
  -webkit-tap-highlight-color: transparent;
}
body{
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 30px 30px;
  display:flex;
  flex-direction:column;
  height:100dvh;
  width:100%;
  position:relative;
  transition: background-color .25s ease, color .25s ease;
}
::selection{ background: var(--lime); color:#17161C; }
h1,h2,h3,.display{ font-family:'Space Grotesk', sans-serif; }
button{ font-family:inherit; cursor:pointer; }

::-webkit-scrollbar{ width:10px; height:10px; }
::-webkit-scrollbar-track{ background:transparent; }
::-webkit-scrollbar-thumb{
  background: var(--ink);
  border-radius: 10px;
  border: 2px solid var(--bg);
}

/* ---------- decorative shapes ---------- */
.deco{
  position:fixed;
  pointer-events:none;
  z-index:1;
  color: var(--violet);
  opacity:.9;
}
.deco-star{
  top: 74px; right: 6%;
  width: 26px; height:26px;
  animation: float-rotate 7s ease-in-out infinite;
}
.deco-circle{
  bottom: 130px; left: 4%;
  width: 20px; height:20px;
  border-radius:50%;
  background: var(--lime);
  border: 3px solid var(--border);
  animation: float-y 5s ease-in-out infinite;
}
.deco-blob{
  top: 40%; right: 2.5%;
  width: 34px; height:34px;
  background: var(--coral);
  border: 3px solid var(--border);
  border-radius: 40% 60% 55% 45% / 50% 45% 55% 50%;
  animation: float-rotate 9s ease-in-out infinite reverse;
}
@keyframes float-y{
  0%,100%{ transform: translateY(0); }
  50%{ transform: translateY(-14px); }
}
@keyframes float-rotate{
  0%,100%{ transform: translateY(0) rotate(0deg); }
  50%{ transform: translateY(-10px) rotate(14deg); }
}
@media (max-width: 760px){ .deco{ display:none; } }

/* ---------- Header ---------- */
header{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 12px 18px;
  background: var(--card);
  border-bottom: var(--border-w) solid var(--border);
  position:relative;
  z-index:20;
}
.brand{ display:flex; align-items:center; gap:10px; min-width:0; }
.logo{
  width:42px; height:42px; flex:0 0 auto;
  background: var(--cobalt);
  color:#fff;
  border: var(--border-w) solid var(--border);
  border-radius: 12px;
  display:flex; align-items:center; justify-content:center;
  box-shadow: 4px 4px 0 var(--shadow);
  transform: rotate(-4deg);
}
.logo svg{ width:22px; height:22px; }
.brand-text{ min-width:0; }
.brand-name{
  font-family:'Space Grotesk',sans-serif;
  font-weight:800;
  font-size:19px;
  line-height:1.1;
  display:flex; align-items:center; gap:8px;
  white-space:nowrap;
  letter-spacing:.01em;
}
.status-dot{
  width:9px; height:9px; border-radius:50%;
  background: var(--success);
  border: 2px solid var(--border);
  flex:0 0 auto;
  animation: pulse 2s infinite;
}
@keyframes pulse{
  0%,100%{ box-shadow: 0 0 0 0 rgba(31,158,119,.5); }
  50%{ box-shadow: 0 0 0 5px rgba(31,158,119,0); }
}
.brand-sub{ font-size:11.5px; color: var(--muted); font-weight:600; letter-spacing:.02em; }
.header-actions{ display:flex; gap:8px; flex:0 0 auto; }
.icon-btn{
  width:42px; height:42px;
  border: var(--border-w) solid var(--border);
  background: var(--card);
  border-radius: 12px;
  display:flex; align-items:center; justify-content:center;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
  color: var(--ink);
  flex:0 0 auto;
  position:relative;
  overflow:hidden;
}
.icon-btn:hover{ transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--shadow); }
.icon-btn:active{ transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--shadow); }
.icon-btn svg{ width:19px; height:19px; }

/* ---------- Chat area ---------- */
main{
  flex:1 1 auto;
  overflow-y:auto;
  overflow-x:hidden;
  padding: 22px 16px 12px;
  scroll-behavior:smooth;
  position:relative;
  z-index:2;
}
.chat-inner{
  max-width: 820px;
  margin:0 auto;
  display:flex;
  flex-direction:column;
  gap:18px;
  min-height:100%;
}
.empty-state{ margin:auto; text-align:center; max-width:440px; padding: 20px; }
.empty-badge{
  display:inline-flex; align-items:center; gap:8px;
  background: var(--lime);
  border: var(--border-w) solid var(--border);
  box-shadow: 4px 4px 0 var(--shadow);
  border-radius: 999px;
  padding:6px 16px;
  font-weight:700; font-size:13px; color:#17161C;
  margin-bottom:18px;
  transform: rotate(-2deg);
}
.empty-state h2{ font-size:27px; margin:0 0 10px; }
.empty-state p{ color:var(--muted); font-size:14.5px; line-height:1.55; margin:0; }
.empty-state strong{ color:var(--cobalt); }

/* ---------- Bubbles ---------- */
.msg-row{ display:flex; width:100%; animation: rise .32s cubic-bezier(.2,.9,.3,1) both; }
@keyframes rise{ from{ opacity:0; transform: translateY(10px) scale(.98);} to{ opacity:1; transform: translateY(0) scale(1);} }
.msg-row.user{ justify-content:flex-end; }
.msg-row.ai{ justify-content:flex-start; }

.bubble{
  max-width: 78%;
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  position:relative;
  box-shadow: 5px 5px 0 var(--shadow);
  word-wrap:break-word;
  overflow-wrap:break-word;
}
.msg-row.user .bubble{ background: var(--user-bubble); border-bottom-right-radius: 4px; color:#17161C; }
.msg-row.ai .bubble{ background: var(--ai-bubble); border-bottom-left-radius: 4px; }

.bubble .content{ font-size:15px; line-height:1.55; }
.bubble .content p{ margin:0 0 8px; }
.bubble .content p:last-child{ margin-bottom:0; }
.bubble .content h1,.bubble .content h2,.bubble .content h3{ margin:10px 0 6px; line-height:1.25; }
.bubble .content h1{ font-size:19px; }
.bubble .content h2{ font-size:17px; }
.bubble .content h3{ font-size:15.5px; }
.bubble .content ul{ margin:6px 0; padding-left:20px; }
.bubble .content li{ margin-bottom:4px; }
.bubble .content strong{ font-weight:700; }
.bubble .content em{ font-style:italic; }
.bubble .content code{
  font-family:'JetBrains Mono', monospace;
  background: rgba(51,85,255,.1);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 13px;
  border: 1.5px solid rgba(51,85,255,.2);
}
html[data-theme="dark"] .bubble .content code{
  background: rgba(110,133,255,.16);
  border-color: rgba(110,133,255,.3);
}
.code-block-wrap{ margin: 10px 0; border-radius: 10px; overflow:hidden; border: 2.5px solid var(--border); }
.code-block-head{
  display:flex; align-items:center; justify-content:space-between;
  background: var(--ink);
  color: var(--bg);
  font-family:'JetBrains Mono', monospace;
  font-size:11px;
  font-weight:600;
  padding: 6px 12px;
  letter-spacing:.03em;
  text-transform:uppercase;
}
.bubble .content pre{
  background:#17161C;
  color:#F3EFE2;
  padding: 12px 14px;
  overflow-x:auto;
  margin: 0;
}
.bubble .content pre code{ background:none; border:none; padding:0; color:inherit; font-size:13px; }

.bubble-meta{ display:flex; align-items:center; gap:8px; margin-top:8px; flex-wrap:wrap; }
.timestamp{ font-size:10.5px; color: var(--muted); font-weight:600; letter-spacing:.02em; }
.msg-row.user .timestamp{ color:#5c4200; }

.msg-actions{ display:flex; gap:6px; margin-left:auto; flex-wrap:wrap; }
.mini-btn{
  display:flex; align-items:center; gap:4px;
  background:transparent;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 3px 8px;
  font-size:11px; font-weight:700;
  color: var(--ink);
  transition: background .15s ease, transform .1s ease, color .15s ease;
}
.mini-btn:hover{ background: var(--sun); transform: translateY(-1px); }
.mini-btn.preview-btn:hover{ background: var(--cobalt); color:#fff; }
.mini-btn:active{ transform: translateY(0); }
.mini-btn svg{ width:12px; height:12px; }

/* ---------- Typing bubble ---------- */
.typing-bubble{ display:flex; gap:5px; align-items:center; padding: 4px 2px; }
.typing-dot{ width:8px; height:8px; border-radius:50%; background: var(--cobalt); opacity:.4; animation: bounce 1.1s infinite ease-in-out; }
.typing-dot:nth-child(2){ animation-delay:.15s; }
.typing-dot:nth-child(3){ animation-delay:.3s; }
@keyframes bounce{ 0%,60%,100%{ transform:translateY(0); opacity:.4;} 30%{ transform:translateY(-6px); opacity:1;} }

/* ---------- Input area ---------- */
.input-wrap{
  flex:0 0 auto;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: var(--border-w) solid var(--border);
  position:relative;
  z-index:20;
}
.input-inner{ max-width:820px; margin:0 auto; display:flex; align-items:flex-end; gap:10px; }
.textarea-shell{
  flex:1 1 auto;
  background: var(--bg);
  border: var(--border-w) solid var(--border);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 4px 6px;
  min-width:0;
}
textarea#chatInput{
  width:100%; resize:none; border:none; outline:none;
  background:transparent;
  color: var(--ink);
  font-family:'Plus Jakarta Sans', sans-serif;
  font-size:15px; line-height:1.4;
  padding: 8px 8px;
  max-height: 150px;
  overflow-y:auto;
}
textarea#chatInput::placeholder{ color: var(--muted); }

#sendBtn{
  flex:0 0 auto; width:52px; height:52px;
  border: var(--border-w) solid var(--border);
  background: var(--coral);
  color:#fff;
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--shadow);
  display:flex; align-items:center; justify-content:center;
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
  position:relative; overflow:hidden;
}
#sendBtn svg{ width:20px; height:20px; transition: transform .2s ease; }
#sendBtn:hover:not(:disabled){ transform: translate(-1px,-1px); box-shadow:5px 5px 0 var(--shadow); }
#sendBtn:active:not(:disabled){ transform: translate(2px,2px); box-shadow:1px 1px 0 var(--shadow); }
#sendBtn:disabled{ opacity:.6; cursor:not-allowed; }
#sendBtn.loading svg{ animation: spin .8s linear infinite; }
@keyframes spin{ to{ transform: rotate(360deg); } }

.ripple{ position:absolute; border-radius:50%; background: rgba(255,255,255,.55); transform: scale(0); animation: ripple .5s ease-out; pointer-events:none; }
@keyframes ripple{ to{ transform: scale(3); opacity:0; } }

/* ---------- Toasts ---------- */
#toastContainer{
  position:fixed; top:16px; left:50%; transform: translateX(-50%);
  z-index:999; display:flex; flex-direction:column; gap:8px;
  width: min(90vw, 380px); pointer-events:none;
}
.toast{
  background: var(--card);
  border: var(--border-w) solid var(--border);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 12px 14px;
  font-size:13.5px; font-weight:600;
  display:flex; align-items:center; gap:8px;
  animation: toastIn .3s ease both;
}
.toast.error{ border-left: 6px solid var(--danger); }
.toast.success{ border-left: 6px solid var(--success); }
.toast.fade-out{ animation: toastOut .3s ease forwards; }
@keyframes toastIn{ from{ opacity:0; transform: translateY(-14px);} to{opacity:1; transform:translateY(0);} }
@keyframes toastOut{ to{ opacity:0; transform: translateY(-14px);} }

/* ---------- Modal (confirm) ---------- */
.modal-overlay{
  position:fixed; inset:0; background: rgba(23,22,28,.6);
  display:flex; align-items:center; justify-content:center;
  z-index:998; padding:20px; animation: fadeIn .2s ease;
}
@keyframes fadeIn{ from{opacity:0;} to{opacity:1;} }
.modal-box{
  background: var(--card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 var(--shadow);
  padding: 22px; max-width: 340px; width:100%; text-align:center;
}
.modal-box h3{ margin: 0 0 8px; font-size:18px; }
.modal-box p{ margin:0 0 18px; color:var(--muted); font-size:13.5px; }
.modal-actions{ display:flex; gap:10px; }
.modal-actions button{
  flex:1; padding: 10px 0;
  border: var(--border-w) solid var(--border);
  border-radius: 10px; font-weight:700; font-size:13.5px;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .1s ease;
}
.modal-actions button:active{ transform: translate(2px,2px); box-shadow:1px 1px 0 var(--shadow); }
.btn-cancel{ background: var(--card); color:var(--ink); }
.btn-confirm{ background: var(--danger); color:#fff; }

/* ---------- Preview modal ---------- */
.preview-overlay{
  position:fixed; inset:0; background: rgba(23,22,28,.7);
  display:flex; align-items:center; justify-content:center;
  z-index:1000; padding: 18px; animation: fadeIn .2s ease;
}
.preview-box{
  background: var(--card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: 10px 10px 0 var(--shadow);
  width: min(96vw, 1000px);
  height: min(88vh, 720px);
  display:flex; flex-direction:column;
  overflow:hidden;
}
.preview-header{
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 16px;
  border-bottom: var(--border-w) solid var(--border);
  background: var(--lime);
  flex:0 0 auto;
}
.preview-header .ph-title{
  font-family:'Space Grotesk', sans-serif;
  font-weight:800; font-size:15px; color:#17161C;
  display:flex; align-items:center; gap:8px;
}
.preview-close{
  width:32px; height:32px; border: 2.5px solid var(--border);
  border-radius: 9px; background: #fff; color:#17161C;
  display:flex; align-items:center; justify-content:center;
  box-shadow: 2px 2px 0 var(--shadow);
  transition: transform .1s ease;
}
.preview-close:hover{ transform: translate(-1px,-1px); }
.preview-close:active{ transform: translate(1px,1px); box-shadow:1px 1px 0 var(--shadow); }
.preview-close svg{ width:16px; height:16px; }
.preview-body{ flex:1 1 auto; position:relative; background:#fff; }
.preview-body iframe{ width:100%; height:100%; border:none; display:block; }

/* ---------- Responsive ---------- */
@media (max-width:600px){
  .brand-name{ font-size:16px; }
  .brand-sub{ display:none; }
  .bubble{ max-width:86%; }
  .logo{ width:38px; height:38px; }
  .logo svg{ width:19px; height:19px; }
  .icon-btn{ width:38px; height:38px; }
  #sendBtn{ width:48px; height:48px; }
  .preview-box{ height: min(92vh, 640px); }
}
@media (min-width: 900px){
  .bubble{ max-width:65%; }
}
