/* ── Login ── */
.login-screen{
  display:flex;align-items:center;justify-content:center;
  height:100vh;background:#efeae2;
  background-image:url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='p' width='40' height='40' patternUnits='userSpaceOnUse'%3E%3Cpath d='M20 5 Q22 8 20 11 Q18 8 20 5z' fill='%23d6d1c8' opacity='.4'/%3E%3Ccircle cx='8' cy='25' r='2' fill='%23d6d1c8' opacity='.3'/%3E%3Cpath d='M32 30 L35 34 L29 34z' fill='%23d6d1c8' opacity='.3'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='200' height='200' fill='url(%23p)'/%3E%3C/svg%3E");
}
.login-box{
  background:#fff;border-radius:16px;padding:40px;
  box-shadow:0 8px 30px rgba(0,0,0,.12);
  text-align:center;width:340px;
}
.login-avatar{width:80px;height:80px;border-radius:50%;object-fit:cover;margin-bottom:16px}
.login-box h1{font-size:22px;color:#075e54;margin-bottom:4px}
.login-box p{font-size:13px;color:#888;margin-bottom:24px}
.login-box form{display:flex;flex-direction:column;gap:12px}
.login-box input{
  padding:12px 16px;border:1px solid #ddd;border-radius:10px;
  font-size:14px;font-family:inherit;color:#333;
}
.login-box input:focus{outline:none;border-color:#00a884}
.login-box button{
  padding:12px;background:#00a884;color:#fff;
  border:none;border-radius:10px;font-size:14px;font-weight:600;
  cursor:pointer;
}
.login-box button:hover{background:#009e7a}
.login-error{color:#ef4444;font-size:13px;margin-top:4px}

/* ── Reset ── */
*{margin:0;padding:0;box-sizing:border-box}
:root{
  --wa-green:#075e54;
  --wa-green-light:#00a884;
  --wa-bg:#efeae2;
  --wa-bubble-out:#d9fdd3;
  --wa-bubble-in:#ffffff;
  --wa-text:#111b21;
  --wa-time:#667781;
  --wa-input-bg:#f0f2f5;
  --wa-header:#075e54;
  --wa-send:#00a884;
  --wa-check:#53bdeb;
  --sidebar-bg:#f7f8fa;
  --sidebar-border:#e0e0e0;
  --blue:#3b82f6;
  --green:#25d366;
  --yellow:#f59e0b;
  --red:#ef4444;
  --font:system-ui,-apple-system,'Segoe UI',sans-serif;
}
body{font-family:var(--font);background:#ddd;height:100vh;overflow:hidden;color:var(--wa-text)}

/* ── App grid ── */
.app{display:grid;grid-template-columns:1fr 1fr;height:100vh}

/* ══════════════════════════════════
   CHAT — WhatsApp style
   ══════════════════════════════════ */
.chat{display:flex;flex-direction:column;overflow:hidden;background:var(--wa-bg)}

/* Header */
.wa-header{
  display:flex;align-items:center;gap:16px;
  padding:14px 20px;
  background:var(--wa-header);color:#fff;
  flex-shrink:0;
}
.wa-avatar{width:52px;height:52px;border-radius:50%;object-fit:cover}
.wa-info{flex:1}
.wa-name{font-size:17px;font-weight:600}
.wa-status{font-size:12px;opacity:.75}

.stats-inline{display:flex;gap:10px}
.si{font-size:10px;opacity:.8}
.si span{font-weight:700}
.si-ok span{color:#a0ffb0}
.si-ed span{color:#ffe580}

/* Messages area — WhatsApp doodle background */
.messages{
  flex:1;overflow-y:auto;padding:16px 60px;
  display:flex;flex-direction:column;gap:2px;
  background-color:#efeae2;
  background-image:url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='p' width='40' height='40' patternUnits='userSpaceOnUse'%3E%3Cpath d='M20 5 Q22 8 20 11 Q18 8 20 5z' fill='%23d6d1c8' opacity='.4'/%3E%3Ccircle cx='8' cy='25' r='2' fill='%23d6d1c8' opacity='.3'/%3E%3Cpath d='M32 30 L35 34 L29 34z' fill='%23d6d1c8' opacity='.3'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='200' height='200' fill='url(%23p)'/%3E%3C/svg%3E");
}

/* ── Bubbles ── */
.bubble{
  max-width:65%;padding:6px 12px 18px;
  font-size:14px;line-height:1.4;
  white-space:pre-wrap;word-wrap:break-word;
  position:relative;
  box-shadow:0 1px 1px rgba(0,0,0,.06);
  animation:fadeIn .2s ease-out;
}

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

/* Outgoing (user) */
.bubble-user{
  align-self:flex-end;
  background:var(--wa-bubble-out);
  color:var(--wa-text);
  border-radius:8px 0 8px 8px;
  margin-right:0;
}

/* Incoming (bot) */
.bubble-bot{
  align-self:flex-start;
  background:var(--wa-bubble-in);
  color:var(--wa-text);
  border-radius:0 8px 8px 8px;
  margin-left:0;
}

/* Timestamp inside bubble */
.bubble::after{
  content:attr(data-time);
  position:absolute;bottom:4px;right:8px;
  font-size:11px;color:var(--wa-time);
}

/* Bot wrapper */
.bot-wrap{
  align-self:flex-start;max-width:65%;
  display:flex;flex-direction:column;gap:2px;
}
.bot-wrap .bubble-bot{max-width:100%}

.routing-tag{
  font-size:11px;color:var(--wa-green-light);
  padding:0 4px;font-weight:500;
}

/* ── Feedback buttons ── */
.fb{display:flex;gap:4px;padding:2px 0}
.fb button{
  padding:3px 10px;border:none;border-radius:4px;
  font-size:11px;font-weight:600;cursor:pointer;
  transition:opacity .15s;
}
.fb button:hover{opacity:.85}
.fb-ok{background:var(--green);color:#fff}
.fb-ed{background:var(--yellow);color:#000}
.fb-cancel{background:#e0e0e0;color:#666}

.fb-done{font-size:11px;padding:2px 4px}

/* Edit inline */
.edit-box{display:flex;flex-direction:column;gap:6px;padding:4px 0}
.edit-box textarea{
  width:100%;min-height:48px;
  background:#fff;border:1px solid #ccc;border-radius:8px;
  color:var(--wa-text);padding:8px 10px;font:inherit;font-size:13px;resize:vertical;
}
.edit-box textarea:focus{outline:none;border-color:var(--wa-green-light)}
.edit-box select{
  background:#fff;border:1px solid #ccc;border-radius:6px;
  color:var(--wa-text);padding:4px 8px;font-size:12px;
}
.edit-actions{display:flex;gap:6px}

/* Proposal summary */
.proposal-summary{
  background:#e8f5e9;border:1px solid #a5d6a7;
  border-radius:8px;padding:10px 12px;
  font-size:13px;color:#2e7d32;line-height:1.5;
}

/* Loading dots */
.dots{display:flex;gap:5px;padding:6px 12px}
.dots span{width:7px;height:7px;background:#999;border-radius:50%;animation:bounce .9s infinite}
.dots span:nth-child(2){animation-delay:.15s}
.dots span:nth-child(3){animation-delay:.3s}
@keyframes bounce{0%,80%,100%{transform:translateY(0)}40%{transform:translateY(-6px)}}

.sys-msg{text-align:center;font-size:12px;color:var(--wa-time);padding:4px;
  background:rgba(255,255,255,.7);border-radius:6px;align-self:center;margin:4px 0;
}

/* ── Input bar ── */
.wa-input-bar{
  padding:6px 16px;
  background:var(--wa-input-bg);
  flex-shrink:0;
}
.wa-form{display:flex;align-items:flex-end;gap:8px}

.wa-form textarea{
  flex:1;
  background:#fff;border:1px solid #ddd;border-radius:24px;
  color:var(--wa-text);padding:10px 16px;
  font:inherit;font-size:14px;resize:none;
  max-height:100px;line-height:1.4;
}
.wa-form textarea:focus{outline:none;border-color:#bbb}
.wa-form textarea::placeholder{color:#999}

.wa-form button{
  width:42px;height:42px;
  background:var(--wa-send);border:none;border-radius:50%;
  color:#fff;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  transition:background .15s;
  flex-shrink:0;
}
.wa-form button:hover{background:#009e7a}
.wa-form button:disabled{background:#ccc;cursor:not-allowed}

/* ══════════════════════════════════
   SIDEBAR — Knowledge base
   ══════════════════════════════════ */
.sidebar{
  background:var(--sidebar-bg);
  border-left:1px solid var(--sidebar-border);
  display:flex;flex-direction:column;overflow:hidden;
}

.sidebar-header{
  padding:14px 20px;
  border-bottom:1px solid var(--sidebar-border);
  background:#fff;
}
.sidebar-header h2{font-size:14px;font-weight:600;color:#333}

.sidebar-content{
  flex:1;overflow-y:auto;padding:16px;
  display:flex;flex-direction:column;gap:20px;
}

.placeholder{color:#999;font-size:13px;text-align:center;padding:24px 12px}

/* Knowledge */
.kb-section{display:flex;flex-direction:column;gap:8px}
.kb-head{display:flex;justify-content:space-between;align-items:center}
.kb-section label{font-size:13px;font-weight:600;color:#333}

.btn-pill{
  padding:4px 14px;border-radius:20px;
  border:1px solid #ddd;background:#f0f0f0;
  color:#999;font-size:11px;font-weight:600;cursor:default;
}
.btn-pill.changed{border-color:var(--wa-green-light);color:var(--wa-green-light);background:#e8f5e9;cursor:pointer}

#kb-editor{
  width:100%;min-height:50vh;
  background:#fff;border:1px solid #ddd;border-radius:10px;
  color:var(--wa-text);padding:14px;
  font-family:'Cascadia Code','Fira Code','SF Mono',monospace;
  font-size:11.5px;line-height:1.7;resize:vertical;
}
#kb-editor:focus{outline:none;border-color:var(--wa-green-light)}

/* KB preview (highlighted prompt) */
.kb-preview{
  width:100%;min-height:50vh;max-height:70vh;
  overflow-y:auto;
  background:#fff;border:2px solid var(--wa-green-light);border-radius:10px;
  color:var(--wa-text);padding:14px;
  font-family:'Cascadia Code','Fira Code','SF Mono',monospace;
  font-size:11.5px;line-height:1.7;
  white-space:pre-wrap;word-wrap:break-word;
}
.kb-highlight{
  background:#c8f7c5;
  color:#1a5e1a;
  padding:2px 0;
  border-radius:2px;
  font-weight:600;
}

/* History */
.history-list{display:flex;flex-direction:column;gap:6px}

.h-card{
  background:#fff;border:1px solid #eee;border-radius:8px;padding:10px 12px;
  font-size:12px;
  box-shadow:0 1px 2px rgba(0,0,0,.04);
}
.h-note{color:#333;margin-bottom:4px}
.h-meta{color:#999;font-size:11px;display:flex;justify-content:space-between;align-items:center}
.h-restore{
  background:none;border:1px solid #ddd;border-radius:4px;
  color:var(--wa-green-light);font-size:10px;font-weight:600;
  padding:2px 8px;cursor:pointer;
}
.h-restore:hover{background:#e8f5e9;border-color:var(--wa-green-light)}

/* Lightbox */
.lightbox{
  position:fixed;top:0;left:0;width:100%;height:100%;
  background:rgba(0,0,0,.85);
  display:flex;align-items:center;justify-content:center;
  z-index:1000;cursor:pointer;
  animation:fadeIn .2s ease-out;
}
.lightbox img{
  max-width:80vw;max-height:80vh;
  border-radius:8px;box-shadow:0 8px 40px rgba(0,0,0,.5);
  object-fit:contain;
}
.wa-avatar{cursor:pointer}

.hidden{display:none!important}

/* Scrollbar */
::-webkit-scrollbar{width:6px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#ccc;border-radius:3px}

@media(max-width:900px){
  .app{grid-template-columns:1fr}
  .sidebar{display:none}
  .messages{padding:12px 16px}
}
