:root{
  /* Enterprise neutrals */
  --bg0:#0b0f14;
  --bg1:#0e141b;
  --panel:rgba(18,24,32,.92);
  --panel2:rgba(14,19,26,.92);

  --text:#eef2f7;
  --muted:rgba(238,242,247,.70);

  /* Enterprise red */
  --red:#d84057;       /* primary */
  --red2:#b93146;      /* deeper */
  --redSoft:rgba(216,64,87,.14);

  /* Lines & depth */
  --border:rgba(255,255,255,.10);
  --border2:rgba(216,64,87,.22);
  --shadow: 0 10px 30px rgba(0,0,0,.40);
  --shadowSm: 0 6px 18px rgba(0,0,0,.32);

  --r10: 10px;
  --r12: 12px;
  --r16: 16px;

  --ease: cubic-bezier(.2,.8,.2,1);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color:var(--text);
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(216,64,87,.16), transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  overflow:hidden;
}

/* App layout */
.app{
  display:grid;
  grid-template-columns: 360px 1fr;
  height:100vh;
  transition: grid-template-columns .25s var(--ease);
}
.app.sidebar-hidden{ grid-template-columns: 0px 1fr; }

/* Sidebar */
.sidebar{
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding:16px;
  overflow:auto;
  box-shadow: inset -1px 0 0 rgba(255,255,255,.03);
  transition: opacity .2s var(--ease);
}
.sidebar::-webkit-scrollbar{ display:none; }
.app.sidebar-hidden .sidebar{
  opacity:0;
  pointer-events:none;
}

.brand .title{
  font-weight:800;
  font-size:18px;
  letter-spacing:.2px;
}
.brand .sub{
  color:var(--muted);
  font-size:12px;
  margin-top:4px;
}

.section{
  margin-top:16px;
  padding-top:12px;
  border-top:1px solid rgba(255,255,255,.06);
}
.label{ color:var(--muted); font-size:12px; margin-bottom:6px; }
.row{ display:flex; gap:8px; margin-bottom:8px; }

/* Inputs */
select, input, textarea{
  width:100%;
  background: rgba(255,255,255,.03);
  color:var(--text);
  border:1px solid rgba(255,255,255,.10);
  border-radius: var(--r10);
  padding:10px;
  outline:none;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
textarea{ resize:none; }

select:focus, input:focus, textarea:focus{
  border-color: rgba(216,64,87,.35);
  box-shadow: 0 0 0 3px rgba(216,64,87,.14);
  background: rgba(255,255,255,.035);
}

/* Buttons */
.btn{
  background: rgba(255,255,255,.03);
  color:var(--text);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r10);
  padding:10px 12px;
  cursor:pointer;
  transition: transform .14s var(--ease), border-color .14s var(--ease), box-shadow .14s var(--ease), background .14s var(--ease);
}
.btn:hover{
  background: rgba(255,255,255,.045);
  border-color: rgba(255,255,255,.18);
  box-shadow: var(--shadowSm);
  transform: translateY(-1px);
}
.btn:active{ transform: translateY(0); }

.btn.small{ padding:6px 10px; border-radius: var(--r10); }

/* Primary: subtle enterprise gradient */
.btn.primary{
  background: linear-gradient(180deg, rgba(216,64,87,.98), rgba(185,49,70,.98));
  border-color: rgba(216,64,87,.55);
  color:#12060a;
  font-weight:800;
  box-shadow: 0 10px 26px rgba(216,64,87,.18);
}
.btn.primary:hover{
  box-shadow: 0 14px 34px rgba(216,64,87,.20);
  border-color: rgba(216,64,87,.70);
}

/* Tabs */
.tabs{ display:flex; gap:8px; margin-top:12px; }
.tab{
  flex:1;
  padding:10px;
  border-radius: var(--r10);
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
  color:var(--text);
  cursor:pointer;
  transition: background .14s var(--ease), border-color .14s var(--ease), transform .14s var(--ease);
}
.tab:hover{
  background: rgba(255,255,255,.045);
  transform: translateY(-1px);
}
.tab.active{
  border-color: rgba(216,64,87,.45);
  background: linear-gradient(180deg, rgba(216,64,87,.16), rgba(255,255,255,.03));
}

/* Panels / lists */
.panel{ margin-top:10px; }
.panel.hidden{ display:none; }

.panelHeader{
  display:flex;
  justify-content:space-between;
  align-items:center;
  color:var(--muted);
  font-size:12px;
}
.list{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* Items */
.item{
  position:relative;
  background: rgba(255,255,255,.03);
  border:1px solid rgba(255,255,255,.10);
  border-radius: var(--r12);
  padding:10px;
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), transform .14s var(--ease);
}
.item:hover{
  border-color: rgba(216,64,87,.22);
  box-shadow: var(--shadowSm);
  transform: translateY(-1px);
}
.item .meta{ color:var(--muted); font-size:12px; margin-bottom:6px; }
.item .content{ font-size:13px; line-height:1.35; }

/* Item actions */
.itemActions{
  position:absolute;
  top:8px;
  right:8px;
  display:flex;
  gap:6px;
}
.iconBtn{
  width:30px;
  height:30px;
  border-radius: 10px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color:var(--text);
  cursor:pointer;
  display:grid;
  place-items:center;
  opacity:.9;
  transition: transform .14s var(--ease), border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.iconBtn:hover{
  transform: translateY(-1px);
  border-color: rgba(216,64,87,.28);
  box-shadow: var(--shadowSm);
}
.iconBtn.danger{ color: rgba(216,64,87,.95); }

/* Main */
.main{ display:flex; flex-direction:column; height:100vh; }

/* Header: enterprise “strip” accent */
.chatHeader{
  padding:16px;
  border-bottom:1px solid rgba(255,255,255,.08);
  background:
    linear-gradient(90deg, rgba(216, 64, 87, 0.397), transparent 55%),
    rgba(44, 65, 92, 0.39);
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
}
.h1{ font-weight:900; font-size:16px; letter-spacing:.2px; }
.h2{ color:var(--muted); font-size:12px; margin-top:4px; }

.chatHeaderLeft{ display:flex; align-items:center; gap:12px; width: 100%;}

.chatHeaderLeft a.logoutBtn {
  margin-left: auto;   /* pushes it to the right */
}

/* Chat log */
.chatLog{
  flex:1;
  overflow:auto;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:12px;
}
.chatLog::-webkit-scrollbar{ width: 10px; }
.chatLog::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.10);
  border-radius: 10px;
}
.chatLog::-webkit-scrollbar-thumb:hover{
  background: rgba(216,64,87,.18);
}

/* Messages */
.msg{
  max-width: 900px;
  border:1px solid rgba(255,255,255,.10);
  border-radius: var(--r16);
  padding: 12px 14px;
  background: rgba(255,255,255,.03);
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), transform .14s var(--ease);
}
.msg:hover{
  transform: translateY(-1px);
  box-shadow: var(--shadowSm);
  border-color: rgba(255,255,255,.14);
}
.msg.user{
  align-self:flex-end;
  border-color: rgba(216,64,87,.22);
  background: linear-gradient(180deg, rgba(216,64,87,.10), rgba(255,255,255,.02));
}
.msg.assistant{
  align-self:flex-start;
  background: rgba(255,255,255,.03);
}
.msg .role{
  color:var(--muted);
  font-size:12px;
  margin-bottom:6px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.msg .text{ white-space: pre-wrap; line-height: 1.45; }

/* Composer */
.composer{
  border-top: 1px solid rgba(255,255,255,.08);
  padding:12px;
  display:flex;
  gap:10px;
  background: var(--panel);
}
.hint{
  padding:10px 16px;
  color:var(--muted);
  font-size:12px;
  border-top: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.12);
}

/* Toast */
.toast{
  position:fixed;
  right:18px;
  bottom:18px;
  z-index:9999;
  max-width: min(420px, calc(100vw - 36px));
  padding:12px 14px;
  border-radius: var(--r12);
  border:1px solid rgba(255,255,255,.10);
  background: rgba(16,22,30,.92);
  color:var(--text);
  box-shadow: var(--shadow);
  font-size:13px;
  line-height:1.35;
}
.toast.hidden{ display:none; }
.toast.ok{ border-color: rgba(216,64,87,.26); }
.toast.warn{ border-color: rgba(255,255,255,.18); }
.toast.show{ animation: toastIn 160ms var(--ease); }
@keyframes toastIn{
  from{ transform: translateY(10px); opacity:0; }
  to  { transform: translateY(0); opacity:1; }
}

/* Light themed toast */
.toast2{
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9999;

  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;

  border-radius: var(--r12);
  border: 1px solid rgba(17, 24, 39, .14);

  /* light glass / card look */
  background: rgba(255, 255, 255, .92);
  color: rgba(17, 24, 39, .92);

  box-shadow: 0 14px 40px rgba(17, 24, 39, .12);
  font-size: 13px;
  line-height: 1.35;

  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.toast2.hidden{ display: none; }

/* Status border accents */
.toast2.ok{
  border-color: rgba(22, 163, 74, .35);  /* green accent */
}

.toast2.warn{
  border-color: rgba(234, 179, 8, .45);  /* amber accent */
}

.toast2.err{
  border-color: rgba(220, 38, 38, .40);  /* red accent (optional) */
}

.toast2.show{ animation: toastIn2 160ms var(--ease); }

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


/* Message input auto-grow */
#messageInput{
  width:100%;
  resize:none;
  overflow:hidden;
  box-sizing:border-box;
}

/* Copy button: subtle + enterprise */
.copyBtn{
  margin-left:8px;
  font-size:12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--muted);
  cursor:pointer;
  padding: 4px 8px;
  border-radius: 999px;
  opacity:0;
  transition: opacity .14s var(--ease), border-color .14s var(--ease), color .14s var(--ease), transform .14s var(--ease);
}
.msg:hover .copyBtn{
  opacity:.85;
  transform: translateY(-1px);
}
.copyBtn:hover{
  border-color: rgba(216,64,87,.28);
  color: rgba(216,64,87,.95);
}

#structureSelect option {
  color: #000 !important;
}


/* -----------------------
   Login / Auth page
------------------------ */
.authBody {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 700px at 20% 20%, rgba(255, 60, 90, 0.14), transparent 60%),
              radial-gradient(900px 600px at 80% 70%, rgba(255, 0, 60, 0.10), transparent 55%),
              #070607;
  color: #f6f3f4;
  display: grid;
  place-items: center;
}

.authBg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.authGlow {
  position: absolute;
  width: 700px;
  height: 700px;
  left: -200px;
  top: -200px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 80, 110, 0.30), transparent 55%);
  filter: blur(12px);
  opacity: 0.9;
}

.authGlow.two {
  left: auto;
  right: -260px;
  top: auto;
  bottom: -260px;
  background: radial-gradient(circle at 60% 60%, rgba(255, 50, 90, 0.22), transparent 60%);
}

.authWrap {
  width: min(460px, calc(100vw - 32px));
  z-index: 2;
}

.authCard {
  border-radius: 18px;
  border: 1px solid rgba(255, 120, 140, 0.18);
  background: linear-gradient(180deg, rgba(26, 12, 14, 0.92), rgba(14, 8, 10, 0.88));
  box-shadow:
    0 16px 44px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 90, 110, 0.06) inset;
  padding: 22px;
  backdrop-filter: blur(10px);
}

.authBrand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.authTitle {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 20px;
  color: rgba(255, 180, 190, 0.92);
  text-transform: uppercase;
}

.authSub {
  font-size: 20px;
  font-weight: 750;
  color: #ffffff;
  letter-spacing: 0.01em;
}

.authHint {
  margin: 10px 0 16px 0;
  color: rgba(246, 231, 234, 0.72);
  line-height: 1.45;
  font-size: 13px;
}

.authForm {
  display: grid;
  gap: 10px;
}

.authLabel {
  font-size: 12px;
  color: rgba(246, 231, 234, 0.66);
  margin-top: 6px;
}

.authInput {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 120, 140, 0.16);
  background: rgba(10, 8, 9, 0.75);
  color: #fff;
  padding: 11px 12px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.authInput:focus {
  border-color: rgba(255, 90, 120, 0.45);
  box-shadow: 0 0 0 4px rgba(255, 70, 110, 0.12);
}

.authBtn {
  margin-top: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 120, 140, 0.22);
  background: linear-gradient(135deg, rgba(255, 70, 110, 0.92), rgba(210, 30, 70, 0.92));
  color: #120607;
  font-weight: 800;
  padding: 11px 12px;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 10px 24px rgba(255, 40, 90, 0.16);
}

.authBtn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 14px 30px rgba(255, 40, 90, 0.22);
}

.authBtn:active {
  transform: translateY(0px);
  filter: brightness(0.98);
}

.authError {
  margin-top: 6px;
  font-size: 12px;
  color: rgba(255, 170, 180, 0.95);
  border: 1px solid rgba(255, 120, 140, 0.18);
  background: rgba(255, 60, 90, 0.08);
  padding: 10px 12px;
  border-radius: 12px;
}

.authFooter {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  font-size: 12px;
  color: rgba(246, 231, 234, 0.55);
  border-top: 1px solid rgba(255, 120, 140, 0.12);
  padding-top: 12px;
}

.authFooterLeft {
  color: rgba(246, 231, 234, 0.7);
}

/***************************************************/

/* --- Widget Mode Overrides --- */


.widgetHideSidebar {
  display: none !important;
}



.widgetHeader {
  position: sticky;
  top: 0;
  z-index: 10;
}

.widgetChatLog {
  height: calc(100vh - 120px); /* header + composer */
  overflow-y: auto;
}

.widgetComposer textarea {
  resize: none;
}

.widgetHideHint {
  display: none !important;
}


body.widgetMode {
  /* Light portal tokens */
  --bg0: #f3f5f8;
  --bg1: #eef2f6;
  --panel: #ffffff;
  --panel2: #ffffff;

  --text: #1f2937;
  --muted: rgba(31, 41, 55, 0.65);

  --red: #e53935;
  --red2: #c62828;
  --redSoft: rgba(229, 57, 53, 0.10);

  --border: rgba(15, 23, 42, 0.12);
  --border2: rgba(229, 57, 53, 0.22);

  --shadow: 0 14px 40px rgba(15, 23, 42, 0.12);
  --shadowSm: 0 8px 22px rgba(15, 23, 42, 0.10);
}

body.widgetMode {
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(900px 480px at 15% -10%, rgba(229,57,53,.06), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

/* Ensure widget fills iframe */
body.widgetMode .widgetApp {
  height: 100vh;
  width: 100vw;
  display: block;
}

/* Main becomes a white “card” surface filling the iframe */
body.widgetMode .widgetMain {
  background: var(--panel);
  width: 100% !important;
}

/* Header: portal-like strip (white with subtle red wash) */
body.widgetMode .chatHeader {
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(90deg, rgba(229,57,53,.14), transparent 55%),
    #ffffff;
  box-shadow: 0 8px 22px rgba(15,23,42,.08);
}

body.widgetMode .h1 { color: #111827; }
body.widgetMode .h2 { color: rgba(31,41,55,.60); }

/* Messages: white cards with soft shadow */
body.widgetMode .msg {
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadowSm);
}
body.widgetMode .msg:hover {
  box-shadow: var(--shadow);
  border-color: rgba(229,57,53,.18);
}
body.widgetMode .msg.user {
  border-color: rgba(229,57,53,.22);
  background: linear-gradient(180deg, rgba(229,57,53,.06), #ffffff);
}

/* Composer: white toolbar */
body.widgetMode .composer {
  background: #fff;
  border-top: 1px solid var(--border);
}

/* Inputs: white with subtle border */
body.widgetMode textarea,
body.widgetMode input,
body.widgetMode select {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
body.widgetMode textarea:focus,
body.widgetMode input:focus,
body.widgetMode select:focus {
  border-color: rgba(229,57,53,.35);
  box-shadow: 0 0 0 3px rgba(229,57,53,.12);
}

/* Buttons: light + primary red */
body.widgetMode .btn {
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(15,23,42,.03);
}
body.widgetMode .btn:hover {
  background: #ffffff;
  box-shadow: var(--shadowSm);
}
body.widgetMode .btn.primary {
  background: linear-gradient(180deg, var(--red), var(--red2));
  border-color: rgba(229,57,53,.40);
  color: #fff;
  box-shadow: 0 12px 26px rgba(229,57,53,.18);
}

/* Scrollbar: subtle */
body.widgetMode .chatLog::-webkit-scrollbar-thumb {
  background: rgba(15,23,42,.14);
}
body.widgetMode .chatLog::-webkit-scrollbar-thumb:hover {
  background: rgba(229,57,53,.18);
}

body.widgetMode .widgetComposer {
  align-items: flex-end;          /* keeps button aligned with textarea bottom */
  gap: 10px;
  padding: 12px;
}

body.widgetMode #messageInput {
  box-sizing: border-box;
  line-height: 1.35;              /* key: avoid tight line-height */
  padding: 10px 12px;             /* enough vertical padding */
  min-height: 50px;               /* prevents “cropped first render” */
  overflow: hidden;               /* keep your auto-grow behavior */
}

/* If your placeholder looks clipped, this helps too */
body.widgetMode #messageInput::placeholder {
  line-height: 1.35;
}