:root{
  --bg:#0b1020; --panel:#11182e; --muted:#27345b; --line:#1e2a4b;
  --text:#e8edff; --sub:#aeb9ff; --accent:#7aa2ff;
  --ok:#19c37d; --err:#ff5c5c; --warn:#ffcc00;
}

*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.45 system-ui,-apple-system,Segoe UI,Roboto}

/* App shell + header */
.app-shell{min-height:100vh;display:flex;flex-direction:column;align-items:center}
.app-header{width:100%;display:flex;justify-content:center;align-items:center;padding:18px 12px}
.app-header h1{margin:0;font-size:18px;letter-spacing:.4px;color:#dfe6ff}

/* Main grid */
.stage{
  width:min(1280px,96vw);
  margin:8px auto 24px;
  display:grid;
  grid-template-columns:260px 1fr 320px;
  gap:16px;
}
@media (max-width:1200px){ .stage{grid-template-columns:220px 1fr 260px} }
@media (max-width:980px){ .stage{grid-template-columns:1fr} }

/* Panels */
.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:18px;
  overflow:visible;
  box-shadow:0 10px 30px rgba(0,0,0,.25);
}

/* ================= Left: History ================= */
.history-rail{display:flex;flex-direction:column;max-height:76vh}
.hist-head{display:flex;align-items:center;gap:8px;padding:12px;border-bottom:1px solid var(--line)}
.hist-head h2{font-size:14px;margin:0}
.pill.ghost{margin-left:auto;background:#0f1833;border:1px solid #3a4a7a;color:#dfe6ff;border-radius:10px;padding:6px 10px;text-decoration:none}
.conv-list{overflow:auto}
.conv-empty{padding:12px;color:var(--sub)}
.conv-item{
  position:relative;
  display:flex;align-items:center;justify-content:space-between;
  padding:10px 12px;border-bottom:1px solid #162042;color:#dfe6ff;
}
.conv-item .conv-link{flex:1;text-decoration:none;color:inherit}
.conv-item .conv-title{font-size:14px;margin:0 0 4px}
.conv-item .conv-meta{font-size:12px;color:var(--sub)}
.conv-item.active{background:#0f1833}
.conv-del{
  background:none;border:none;color:#777;font-size:16px;line-height:1;
  cursor:pointer;padding:2px 6px;margin-left:6px;border-radius:6px;
  transition:background .2s,color .2s;
}
.conv-del:hover{background:rgba(255,255,255,.08);color:#ff6666}
.conv-item.active .conv-del:hover{background:rgba(255,255,255,.12)}

/* ================= Center: Chat ================= */
.chatpanel{display:flex;flex-direction:column;max-height:76vh}
.header{padding:12px 16px;border-bottom:1px solid var(--line);display:flex;align-items:center;gap:8px}
.brand{font-size:14px}
.modelpick select{
  background:#0f1833;border:1px solid #3a4a7a;color:#e7ecff;border-radius:8px;padding:6px 8px;margin-left:auto
}

.history{flex:1;overflow:auto;padding:16px;display:flex;flex-direction:column;gap:12px}
.msg{display:flex}
.msg.user{justify-content:flex-end}
.msg.assistant{justify-content:flex-start}
.bubble{
  max-width:80%;
  background:#16234b;border:1px solid #2a3a6c;
  padding:12px 14px;border-radius:14px;white-space:pre-wrap;word-wrap:break-word
}
.msg.user .bubble{background:#16253a;border-color:#28415c}
.imgpart img{max-width:260px;border-radius:10px;border:1px solid #2b3a6a;margin-top:8px;display:block}

/* Composer */
.composer{padding:12px;border-top:1px solid var(--line)}
.input-wrap{
  position:relative;display:flex;align-items:center;
  background:#0c1430;border:1px solid #26355f;border-radius:20px;
  padding:6px 92px 6px 12px;
  transition:border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.input-wrap.drag{
  border-color:#7aa2ff;
  box-shadow:0 0 0 2px rgba(122,162,255,.35), inset 0 0 0 1px rgba(122,162,255,.25);
  background:#101b3d;
}
.drop-hint{
  position:absolute;inset:6px 88px 6px 10px;display:flex;align-items:center;justify-content:center;
  border:1px dashed rgba(122,162,255,.75);border-radius:15px;background:rgba(12,20,48,.92);
  color:#dfe6ff;font-size:13px;font-weight:600;letter-spacing:.02em;opacity:0;pointer-events:none;
  transform:scale(.985);transition:opacity .16s ease, transform .16s ease;z-index:2;
}
.input-wrap.drag .drop-hint{opacity:1;transform:scale(1)}
.input-wrap textarea{
  flex:1;min-height:44px;max-height:160px;resize:vertical;
  background:transparent;color:var(--text);border:none;outline:none;padding:6px;
}
.sr-only{
  position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;
  clip:rect(0,0,0,0);white-space:nowrap;border:0;
}
/* Composer buttons */
.btn{
  position:absolute;top:50%;transform:translateY(-50%);
  width:32px;height:32px;border-radius:10px;
  border:1px solid #ECEFF7;background:#FAFBFE;cursor:pointer;
  box-shadow:0 1px 0 rgba(0,0,0,.04);
  background-repeat:no-repeat;background-position:center;
}
.btn:hover{background-color:#FFFFFF;border-color:#E7EAF4}
.btn:active{background-color:#F3F6FE;border-color:#DCE2F2}
.btn.attach{
  right:48px;background-size:18px 18px;
  background-image:url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 12l6.5-6.5a3.536 3.536 0 115 5L10 19a5 5 0 11-7.07-7.07L13 1.86' stroke='%23444' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.btn.send{
  right:8px;background-size:16px 16px;
  background-image:url("data:image/svg+xml,%3Csvg width='22' height='22' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 4l16 8-16 8 4-8-4-8z' fill='%23444'/%3E%3C/svg%3E");
}
.file-badges{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}
.chip{font-size:12px;border:1px solid #3a4a7a;padding:4px 8px;border-radius:999px;background:#0f1833}

/* ================= Right: Flow ================= */
.flowpanel{display:flex;flex-direction:column;max-height:none;overflow:visible}
.flowpanel .toggle{
  padding: 0 14px;
  margin-top: 10px;
}
.flowpanel .toggle label{ display:inline-block; min-width:0; }
.flow-head{padding:12px 14px;border-bottom:1px solid var(--line)}
.flow-head .sub{color:var(--sub);font-size:12px}
.flow-graph{padding:18px;display:flex;flex-direction:column;gap:10px;overflow:visible}
.node{
  background:#0f1833;border:1px solid #2a3c74;border-radius:14px;padding:12px 12px;
  position:relative;box-shadow:inset 0 0 0 1px rgba(255,255,255,.03);
  min-height:0;overflow:visible;
}
.node .node-title{font-size:13px;margin-bottom:6px}
.badge.small{
  display:inline-flex;align-items:center;gap:6px;flex-wrap:wrap;max-width:100%;
  white-space:normal;overflow-wrap:anywhere;line-height:1.35;
  font-size:11px;border:1px solid #3a4a7a;border-radius:999px;padding:2px 8px;color:#dfe6ff
}
.node.ok{border-color:rgba(25,195,125,.45);box-shadow:0 0 0 1px rgba(25,195,125,.25) inset}
.node.ok .badge{border-color:rgba(25,195,125,.6)}
.node.pending{border-color:rgba(122,162,255,.45)}
.node.err{
  border-color:#ff5c5c !important;
  box-shadow:0 0 0 1px rgba(255,92,92,.35) inset, 0 0 0 1px rgba(255,92,92,.25);
}

/* Centered solid connector with arrow */
.pipe{
  position:relative;align-self:center;width:2px;height:30px;background:#304275;margin:0 auto;
}
.pipe::after{
  content:'';position:absolute;bottom:-6px;left:50%;transform:translateX(-50%);
  width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #304275;
}
.flow-foot{padding:10px 14px;border-top:1px solid var(--line);font-size:12px;color:var(--sub);white-space:normal;overflow-wrap:anywhere}

/* Header actions row: Settings + Logout side-by-side */
.app-header { 
  width: min(1280px, 96vw);
  margin: 16px auto 8px;
  position: relative;
  display:flex; align-items:center; justify-content:center;
}
.app-header h1 { text-align:center; }

.app-header .actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.app-header .actions .btn.small{
  position: static !important;
  top: auto !important;
  right: auto !important;
  transform: none !important;
  width: auto !important;
  height: auto !important;
  padding: 6px 12px !important;
  background: #25345c !important;
  background-image: none !important;
  border: 1px solid #3a4a7a !important;
  border-radius: 8px !important;
  color: #cfe0ff !important;
  box-shadow: none !important;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.app-header .actions .btn.small:hover{ background:#2f4376 !important; }

/* Emphasize DLP error messages */
.dlp-error { color:#ff4444; font-weight:700; font-size:14px; margin-top:6px; }
.flow-foot .dlp-error { font-size:15px; }

/* ================= Settings Modal (scoped, polished) ================= */
/* Only affects the Settings modal wrapper used in index.php:
   <div id="settingsModal" class="modal-backdrop"><div class="modal">... */

#settingsModal.modal-backdrop{
  position: fixed;
  inset: 0;
  display: none;                 /* JS sets this to flex */
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  z-index: 9999;
}

#settingsModal .modal{
  width: min(760px, calc(100vw - 36px));
  margin: 0;
  max-height: calc(100vh - 36px);
  overflow: auto;

  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,.45);
  padding: 16px 16px 14px;
}

#settingsModal .modal h3{
  margin: 0 0 10px 0;
  font-size: 16px;
  letter-spacing: .2px;
}

#settingsModal .row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 760px){
  #settingsModal .row{ grid-template-columns: 1fr; }
}

#settingsModal label{
  display:block;
  font-size: 12px;
  color: var(--sub);
  margin: 0 0 6px 2px;
}

#settingsModal input[type="text"],
#settingsModal input[type="password"],
#settingsModal input[type="email"]{
  width: 100%;
  background: #0c1430;
  border: 1px solid #26355f;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}

#settingsModal input[type="text"]:focus,
#settingsModal input[type="password"]:focus,
#settingsModal input[type="email"]:focus{
  border-color:#3a4a7a;
  box-shadow: 0 0 0 3px rgba(122,162,255,.15);
}

/* Profile toggles (works for both built-in + custom chips) */
#settingsModal .prof-toggle{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 8px 10px;
  margin: 6px 8px 0 0;
  border-radius: 999px;
  border: 1px solid #2b3a66;
  background: rgba(12,20,48,.55);
  color: #d8e6ff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform .05s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
#settingsModal .prof-toggle:active{ transform: translateY(1px); }

#settingsModal .prof-toggle::before{
  content:'';
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #4b5f92;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

#settingsModal .prof-toggle.on{
  border-color: rgba(25,195,125,.45);
  background: rgba(25,195,125,.12);
}
#settingsModal .prof-toggle.on::before{ background: rgba(25,195,125,.95); }

#settingsModal .prof-toggle.off{
  opacity: .75;
}
#settingsModal .prof-toggle.off::before{ background: rgba(255,255,255,.18); }

/* Keep your existing chip close button behavior looking tidy */
#settingsModal .prof-toggle.chip--closable{ padding-right: 6px; }
#settingsModal .chip-x{
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.25);
  color: #e7efff;
  line-height: 16px;
  font-size: 14px;
  cursor: pointer;
}
#settingsModal .chip-x:hover{
  background: rgba(255,92,92,.15);
  border-color: rgba(255,92,92,.35);
}

/* Footer buttons alignment */
#settingsModal .bar{
  display:flex;
  justify-content:flex-end;
  gap: 10px;
}


/* ================= DLP Flow: don't nest chips inside the badge pill ================= */
/* JS adds .no-fill when it injects chips into the badge. */
.badge.no-fill{
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;

  /* make the chips line up nicely */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* Make sure the chips look consistent inside flow badges */
.badge.no-fill .chip{
  margin: 0;
}

/* ================= Custom profile chips: move × to the right (not on top) ================= */
/* Override the absolute-position close button ONLY for custom profile chips */
.chip.chip--closable.custom-prof{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-right: 10px; /* no longer reserving space for absolute button */
  position: static;    /* neutralize any "relative" positioning */
}

.chip.chip--closable.custom-prof .chip-x{
  position: static !important;
  top: auto !important;
  right: auto !important;
  transform: none !important;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 18px;
  height: 18px;
  border-radius: 999px;
  line-height: 1;
  font-size: 14px;

  border: 1px solid rgba(122,162,255,.35);
  background: rgba(255,255,255,.06);
  opacity: .9;
}

.chip.chip--closable.custom-prof .chip-x:hover{
  opacity: 1;
  background: rgba(255,255,255,.10);
}
/* ================= History "New Chat" Button ================= */
.hist-head .pill.ghost{
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .2px;

  background: linear-gradient(180deg, #2f4376 0%, #25345c 100%);
  border: 1px solid #3f5696;
  color: #e8edff;
  text-decoration: none;

  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  transition: all .15s ease;
}

.hist-head .pill.ghost:hover{
  background: linear-gradient(180deg, #3a5396 0%, #2b3f70 100%);
  border-color: #5673c2;
  box-shadow: 0 4px 10px rgba(0,0,0,.35);
  transform: translateY(-1px);
}

.hist-head .pill.ghost:active{
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
/* ================= DLP Toggle Switch ================= */
.flowpanel .toggle{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 10px 14px;
}

.flowpanel .toggle-label{
  display:flex;
  flex-direction:column;
  gap:2px;
}

.flowpanel .toggle-label .title{
  font-size:13px;
  color:var(--text);
  font-weight:600;
}

.flowpanel .toggle-label .sub{
  font-size:12px;
  color:var(--sub);
}

/* switch */
.flowpanel .switch{
  position:relative;
  display:inline-block;
  width:46px;
  height:26px;
  flex: 0 0 auto;
}

.flowpanel .switch input{
  opacity:0;
  width:0;
  height:0;
}

.flowpanel .slider{
  position:absolute;
  inset:0;
  cursor:pointer;
  background:#1c274a;
  border:1px solid #3a4a7a;
  border-radius:999px;
  transition:.18s ease;
}

.flowpanel .slider:before{
  content:"";
  position:absolute;
  height:20px;
  width:20px;
  left:3px;
  top:2px;
  background:#ffffff;
  border-radius:50%;
  transition:.18s ease;
  box-shadow:0 2px 6px rgba(0,0,0,.35);
}

.flowpanel .switch input:checked + .slider{
  background: var(--accent);
  border-color: var(--accent);
}

.flowpanel .switch input:checked + .slider:before{
  transform: translateX(20px);
}
/* ================= Login Page ================= */
.login-body{
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 20% 10%, rgba(122,162,255,.18), transparent 55%),
    radial-gradient(900px 520px at 80% 30%, rgba(25,195,125,.12), transparent 60%),
    var(--bg);
}

.login-box{
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 22px 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
}

.login-box h1{
  margin: 0 0 14px 0;
  font-size: 18px;
  letter-spacing: .3px;
  color: #dfe6ff;
}

.login-box .error{
  background: rgba(255,92,92,.12);
  border: 1px solid rgba(255,92,92,.35);
  color: #ffb6b6;
  padding: 10px 12px;
  border-radius: 12px;
  margin: 0 0 12px 0;
  font-size: 13px;
}

.login-box label{
  display:block;
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--sub);
}

.login-box input[type="text"],
.login-box input[type="password"]{
  width: 100%;
  background: #0c1430;
  border: 1px solid #26355f;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  transition: border .15s, box-shadow .15s;
}

.login-box input:focus{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122,162,255,.16);
}

.login-btn{
  width: 100%;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(122,162,255,.45);
  background: linear-gradient(180deg, rgba(122,162,255,.95), rgba(122,162,255,.75));
  color: #0b1020;
  font-weight: 700;
  letter-spacing: .2px;
  cursor: pointer;
  transition: transform .12s, filter .12s, box-shadow .12s;
  box-shadow: 0 10px 24px rgba(122,162,255,.12);
}

.login-btn:hover{
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(122,162,255,.16);
}

.login-btn:active{
  transform: translateY(0);
}
/* Ensure login form stacks vertically */
.login-box form{
  display:flex;
  flex-direction:column;
}

/* Add spacing before the button */
.login-btn{
  margin-top: 18px;
}
