:root{
  --ink:#0a0a14;
  --ink-2:#0f1024;
  --ink-3:#161734;
  --pearl:#f4f1ea;
  --pearl-dim:#bdb9b0;
  --gold:#c9a84c;
  --gold-soft:#e8c879;
  --violet:#7c5cff;
  --violet-soft:#a98cff;
  --glass:rgba(255,255,255,0.04);
  --glass-strong:rgba(255,255,255,0.07);
  --border:rgba(255,255,255,0.08);
  --border-strong:rgba(201,168,76,0.35);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;height:100%;overflow:hidden}
body{
  font-family:'Cairo','Inter',system-ui,sans-serif;
  font-weight:300;
  color:var(--pearl);
  background:#05050d;
  position:relative;
}
.bg-gradient{
  position:fixed;inset:0;z-index:-2;
  background:
    radial-gradient(1200px 800px at 80% -10%, #1a1742 0%, transparent 60%),
    radial-gradient(900px 700px at 10% 110%, #0a1a3a 0%, transparent 60%),
    linear-gradient(180deg,#05050d 0%,#0a0a18 100%);
}
.bg-orbs{position:fixed;inset:0;z-index:-1;overflow:hidden;pointer-events:none}
.orb{position:absolute;border-radius:50%;filter:blur(80px);opacity:.35}
.orb-1{width:500px;height:500px;background:#7c5cff;top:-150px;right:-100px;animation:float 18s ease-in-out infinite}
.orb-2{width:400px;height:400px;background:#c9a84c;bottom:-120px;left:-80px;animation:float 22s ease-in-out infinite reverse}
.orb-3{width:300px;height:300px;background:#3a5cff;top:40%;left:30%;opacity:.18;animation:float 26s ease-in-out infinite}
@keyframes float{
  0%,100%{transform:translate(0,0) scale(1)}
  50%{transform:translate(40px,-30px) scale(1.08)}
}

.glass{
  background:var(--glass);
  backdrop-filter:blur(24px) saturate(140%);
  -webkit-backdrop-filter:blur(24px) saturate(140%);
  border:1px solid var(--border);
  border-radius:20px;
}
.hidden{display:none !important}

/* Welcome */
.welcome-overlay{
  position:fixed;inset:0;display:flex;align-items:center;justify-content:center;
  z-index:50;padding:20px;
}
.welcome-card{
  width:100%;max-width:480px;padding:40px 36px;text-align:center;
  animation:rise .7s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes rise{from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}
.logo-mark{
  width:64px;height:64px;margin:0 auto 20px;border-radius:50%;
  background:linear-gradient(135deg,var(--gold),var(--gold-soft));
  display:flex;align-items:center;justify-content:center;color:var(--ink);
  box-shadow:0 0 40px rgba(201,168,76,.4);
}
.logo-mark svg{width:32px;height:32px}
.welcome-card h1{margin:0 0 10px;font-size:30px;font-weight:700;color:var(--pearl);letter-spacing:-.02em}
.tagline{margin:0 0 28px;color:var(--pearl-dim);font-size:14px;line-height:1.7}
.field-label{display:block;text-align:right;font-size:12px;color:var(--pearl-dim);margin-bottom:8px;font-weight:500}
#project-title{
  width:100%;padding:14px 16px;font-family:inherit;font-size:15px;
  background:rgba(0,0,0,.3);border:1px solid var(--border);border-radius:12px;
  color:var(--pearl);outline:none;transition:.2s;
}
#project-title:focus{border-color:var(--gold);box-shadow:0 0 0 3px rgba(201,168,76,.15)}
.btn-primary{
  margin-top:20px;width:100%;padding:14px 20px;border:none;border-radius:12px;
  background:linear-gradient(135deg,var(--gold),var(--gold-soft));color:var(--ink);
  font-family:inherit;font-weight:700;font-size:15px;cursor:pointer;
  display:flex;align-items:center;justify-content:center;gap:10px;
  transition:.25s;box-shadow:0 8px 28px rgba(201,168,76,.3);
}
.btn-primary:hover{transform:translateY(-2px);box-shadow:0 12px 36px rgba(201,168,76,.45)}
.btn-primary svg{width:18px;height:18px}

/* App layout */
.app-shell{
  display:grid;grid-template-columns:300px 1fr 340px;gap:18px;padding:18px;
  height:100vh;
}
.sidebar,.preview{padding:22px;display:flex;flex-direction:column;overflow:hidden}
.stage{display:flex;flex-direction:column;gap:14px;overflow:hidden}

/* Sidebar */
.sidebar-header{display:flex;align-items:center;gap:12px;margin-bottom:22px}
.brand-dot{width:36px;height:36px;border-radius:10px;background:linear-gradient(135deg,var(--gold),var(--gold-soft));box-shadow:0 0 20px rgba(201,168,76,.4)}
.brand-title{font-weight:700;font-size:15px;color:var(--pearl)}
.brand-sub{font-size:12px;color:var(--pearl-dim);margin-top:2px;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.stat-card{
  background:var(--glass-strong);border:1px solid var(--border);border-radius:14px;
  padding:16px;margin-bottom:12px;
}
.stat-label{font-size:11px;color:var(--pearl-dim);text-transform:uppercase;letter-spacing:.1em;margin-bottom:8px}
.stat-value{font-size:32px;font-weight:700;color:var(--gold);font-family:'Inter',sans-serif;line-height:1}
.stat-meta{margin-top:8px;font-size:12px;color:var(--pearl-dim)}
.stat-meta b{color:var(--pearl)}

.section-title{font-size:11px;color:var(--pearl-dim);text-transform:uppercase;letter-spacing:.12em;font-weight:600;margin-bottom:12px}
.tree-section{flex:1;overflow:hidden;display:flex;flex-direction:column;margin-top:8px}
.tree{flex:1;overflow-y:auto;padding-left:4px}
.tree-empty,.preview-empty{font-size:12px;color:var(--pearl-dim);text-align:center;padding:30px 10px;line-height:1.7}
.tree-actor{
  background:rgba(124,92,255,.1);border:1px solid rgba(124,92,255,.25);
  border-radius:10px;padding:8px 12px;margin-bottom:8px;font-size:13px;font-weight:600;color:var(--violet-soft);
  display:flex;align-items:center;gap:8px;
}
.tree-actor::before{content:'';width:6px;height:6px;border-radius:50%;background:var(--violet-soft)}
.tree-fp{
  margin:6px 12px 6px 0;padding:7px 10px;font-size:12px;color:var(--pearl);
  background:rgba(255,255,255,.03);border-right:2px solid var(--gold);border-radius:6px;
  animation:slide-in .35s ease-out;
}
@keyframes slide-in{from{opacity:0;transform:translateX(10px)}to{opacity:1;transform:translateX(0)}}

.btn-export{
  margin-top:16px;width:100%;padding:13px;border:none;border-radius:12px;
  background:linear-gradient(135deg,var(--gold) 0%,var(--gold-soft) 100%);color:var(--ink);
  font-family:inherit;font-weight:700;font-size:14px;cursor:pointer;
  display:flex;align-items:center;justify-content:center;gap:8px;
  box-shadow:0 0 30px rgba(201,168,76,.5);animation:pulse-gold 2s ease-in-out infinite;
}
.btn-export svg{width:18px;height:18px}
@keyframes pulse-gold{0%,100%{box-shadow:0 0 30px rgba(201,168,76,.4)}50%{box-shadow:0 0 50px rgba(201,168,76,.7)}}

/* Stage */
.stage-header{display:flex;align-items:center;justify-content:space-between;padding:0 6px}
.stage-title{font-size:13px;color:var(--pearl-dim);font-weight:500}
.stage-pill{
  background:var(--glass-strong);border:1px solid var(--border-strong);
  color:var(--gold);padding:6px 14px;border-radius:20px;font-size:12px;font-weight:600;
}
.messages{
  flex:1;overflow-y:auto;padding:20px 8px;display:flex;flex-direction:column;gap:24px;
}
.msg{display:flex;gap:14px;align-items:flex-start;animation:msg-in .5s ease-out}
@keyframes msg-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}
.msg.user{flex-direction:row-reverse}
.avatar{
  flex-shrink:0;width:36px;height:36px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:13px;font-weight:700;
}
.msg.agent .avatar{
  background:linear-gradient(135deg,var(--gold),var(--gold-soft));color:var(--ink);
  box-shadow:0 0 20px rgba(201,168,76,.4);
  position:relative;
}
.msg.agent .avatar::after{
  content:'';position:absolute;inset:-4px;border-radius:50%;
  border:1.5px solid var(--gold);opacity:.5;
}
.msg.agent.thinking .avatar::after{animation:wave 1.4s ease-out infinite}
@keyframes wave{0%{transform:scale(1);opacity:.6}100%{transform:scale(1.6);opacity:0}}
.msg.user .avatar{background:rgba(124,92,255,.2);color:var(--violet-soft);border:1px solid rgba(124,92,255,.3)}
.bubble{
  max-width:75%;padding:14px 18px;line-height:1.85;font-size:14.5px;
  border-radius:16px;
}
.msg.agent .bubble{
  background:transparent;color:var(--pearl);
  border:1px solid rgba(255,255,255,.06);
  box-shadow:0 0 0 0 rgba(201,168,76,0);
  position:relative;
}
.msg.agent.fresh .bubble{box-shadow:0 0 30px rgba(201,168,76,.18)}
.msg.user .bubble{
  background:rgba(124,92,255,.12);border:1px solid rgba(124,92,255,.25);color:var(--pearl);
}
.bubble.typing{color:var(--pearl-dim);font-style:italic}
.cursor{display:inline-block;width:8px;height:1.1em;background:var(--gold);vertical-align:-2px;margin-right:2px;animation:blink 1s steps(2) infinite}
@keyframes blink{50%{opacity:0}}

/* Composer */
.composer{
  display:flex;align-items:flex-end;gap:10px;padding:10px 12px;
  position:relative;
}
.composer:focus-within{border-color:var(--gold);box-shadow:0 0 0 3px rgba(201,168,76,.1)}
#input{
  flex:1;background:transparent;border:none;outline:none;resize:none;
  font-family:inherit;font-size:14.5px;color:var(--pearl);padding:10px 8px;
  max-height:140px;line-height:1.6;
}
#input::placeholder{color:var(--pearl-dim)}
.send-btn{
  width:42px;height:42px;border:none;border-radius:50%;cursor:pointer;
  background:linear-gradient(135deg,var(--gold),var(--gold-soft));color:var(--ink);
  display:flex;align-items:center;justify-content:center;transition:.2s;
  box-shadow:0 4px 16px rgba(201,168,76,.35);
}
.send-btn:hover{transform:scale(1.06)}
.send-btn:disabled{opacity:.4;cursor:not-allowed}
.send-btn svg{width:18px;height:18px;transform:scaleX(-1)}

/* Preview */
.preview-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}
.live-dot{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--pearl-dim)}
.live-dot span{width:7px;height:7px;border-radius:50%;background:#3ad590;box-shadow:0 0 8px #3ad590;animation:blink 1.4s infinite}
.preview-content{flex:1;overflow-y:auto;font-size:12.5px;line-height:1.85;color:var(--pearl)}
.preview-content h3{color:var(--gold);font-size:13px;font-weight:700;margin:18px 0 8px;letter-spacing:.02em;border-bottom:1px solid var(--border);padding-bottom:6px}
.preview-content h3:first-child{margin-top:0}
.preview-content .scope{color:var(--pearl-dim);font-size:12px;line-height:1.7}
.preview-content .uc-prev{background:rgba(255,255,255,.03);border-right:2px solid var(--violet-soft);padding:8px 10px;margin:6px 0;border-radius:6px;font-size:11.5px}
.preview-content .uc-prev b{color:var(--violet-soft)}

/* Scrollbars */
::-webkit-scrollbar{width:6px;height:6px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:rgba(255,255,255,.08);border-radius:3px}
::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.15)}

/* Responsive */
@media (max-width:1100px){
  .app-shell{grid-template-columns:260px 1fr}
  .preview{display:none}
}
@media (max-width:720px){
  .app-shell{grid-template-columns:1fr;padding:10px;gap:10px}
  .sidebar{display:none}
}
/* --- Extended workflow: drafts, SRS import, planning --- */
.welcome-card{max-width:760px}
.drafts-panel{
  margin-top:24px;padding-top:18px;border-top:1px solid var(--border);
}
.drafts-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
.pill-note{
  display:inline-flex;align-items:center;justify-content:center;
  padding:6px 10px;border-radius:999px;background:rgba(124,92,255,.14);
  border:1px solid rgba(124,92,255,.25);color:var(--violet-soft);font-size:11px;font-weight:700;
}
.draft-list{display:flex;flex-direction:column;gap:10px;overflow:auto}
.draft-list.compact{max-height:220px}
.draft-empty{
  padding:14px;border:1px dashed rgba(255,255,255,.1);border-radius:12px;
  color:var(--pearl-dim);font-size:12px;line-height:1.7;background:rgba(255,255,255,.02)
}
.draft-card{
  width:100%;text-align:right;border:none;cursor:pointer;padding:13px 14px;border-radius:14px;
  background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);color:var(--pearl);
  transition:.22s;display:flex;flex-direction:column;gap:6px;
}
.draft-card:hover{transform:translateY(-1px);border-color:rgba(201,168,76,.35);box-shadow:0 10px 24px rgba(0,0,0,.18)}
.draft-card.active{border-color:rgba(201,168,76,.45);box-shadow:0 0 0 2px rgba(201,168,76,.12)}
.draft-card.last-opened:not(.active){border-color:rgba(124,92,255,.35)}
.draft-card-top{display:flex;align-items:center;justify-content:space-between;gap:10px}
.draft-title{font-weight:700;font-size:13px;line-height:1.5}
.draft-meta{font-size:12px;color:var(--gold)}
.draft-stats{display:flex;flex-wrap:wrap;gap:8px;font-size:11px;color:var(--pearl-dim)}
.draft-date{font-size:11px;color:var(--pearl-dim)}
.tiny-badge{
  display:inline-flex;align-items:center;padding:4px 8px;border-radius:999px;
  background:rgba(124,92,255,.14);color:var(--violet-soft);font-size:10px;font-weight:700;
}

.stat-grid-2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.stat-mini{margin-bottom:0}
.stat-value.mini{font-size:24px}
.inline-fields{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin:12px 0}
.mini-field{display:flex;flex-direction:column;gap:6px;font-size:11px;color:var(--pearl-dim)}
.mini-field input,
.tool-textarea,
.editor-textarea{
  width:100%;background:rgba(0,0,0,.22);border:1px solid rgba(255,255,255,.08);border-radius:12px;
  color:var(--pearl);font-family:inherit;font-size:13px;outline:none;transition:.2s;
}
.mini-field input{padding:10px 12px}
.mini-field input:focus,
.tool-textarea:focus,
.editor-textarea:focus{border-color:var(--gold);box-shadow:0 0 0 3px rgba(201,168,76,.1)}
.btn-secondary{
  width:100%;padding:11px 14px;border:none;border-radius:12px;cursor:pointer;
  background:rgba(255,255,255,.06);color:var(--pearl);font-family:inherit;font-weight:700;font-size:13px;
  border:1px solid rgba(255,255,255,.08);transition:.2s;
}
.btn-secondary:hover{border-color:rgba(201,168,76,.35);transform:translateY(-1px)}
.btn-secondary.gold{background:linear-gradient(135deg,var(--gold),var(--gold-soft));color:var(--ink)}
.hint-line{margin-top:10px;font-size:11px;color:var(--pearl-dim);line-height:1.7}

.resume-banner{
  padding:12px 16px;border-radius:16px;font-size:13px;line-height:1.8;
  color:var(--pearl);border:1px solid rgba(201,168,76,.25);box-shadow:0 10px 24px rgba(0,0,0,.14)
}

.tool-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.tool-card{
  padding:16px;display:flex;flex-direction:column;gap:12px;min-height:0;overflow:auto;
}
.tool-header{display:flex;justify-content:space-between;align-items:flex-start;gap:12px}
.tool-title{font-size:14px;font-weight:700;color:var(--pearl)}
.tool-subtitle{font-size:11px;color:var(--pearl-dim);line-height:1.7;margin-top:4px}
.tool-badge{
  white-space:nowrap;padding:6px 10px;border-radius:999px;font-size:10px;font-weight:700;
  background:rgba(201,168,76,.12);border:1px solid rgba(201,168,76,.24);color:var(--gold)
}
.tool-badge.dim{color:var(--pearl-dim);border-color:rgba(255,255,255,.08);background:rgba(255,255,255,.04)}
.tool-actions{display:flex;flex-wrap:wrap;align-items:center;gap:10px}
.tool-actions.compact-actions{justify-content:flex-start}
.file-label{
  display:inline-flex;align-items:center;justify-content:center;padding:10px 14px;border-radius:12px;cursor:pointer;
  background:rgba(124,92,255,.14);color:var(--violet-soft);border:1px solid rgba(124,92,255,.3);font-size:12px;font-weight:700;
}
#srs-file{display:none}
.tool-textarea,
.editor-textarea{padding:12px 14px;min-height:96px;resize:vertical;line-height:1.7}
.editor-textarea.io{min-height:120px}
.proposal-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.editor-block{display:flex;flex-direction:column;gap:6px;font-size:12px;color:var(--pearl-dim)}
.editor-block.wide{grid-column:1 / -1}

.drafts-sidebar{margin-top:16px}
.tree-io{
  margin:6px 12px 6px 0;padding:7px 10px;border-radius:8px;font-size:11.5px;
  background:rgba(255,255,255,.03);border-right:2px solid rgba(124,92,255,.55);color:var(--pearl-dim)
}
.tree-io.out{border-right-color:rgba(201,168,76,.75)}

.messages{min-height:0;background:rgba(255,255,255,.02);border:1px solid rgba(255,255,255,.06);border-radius:20px}
.preview-content{display:flex;flex-direction:column;gap:12px}
.summary-strip{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.preview-metric{
  background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);border-radius:12px;padding:12px;
}
.metric-label{font-size:10px;color:var(--pearl-dim);text-transform:uppercase;letter-spacing:.12em}
.metric-value{font-size:22px;font-weight:700;color:var(--gold);margin-top:6px}
.metric-meta{font-size:11px;color:var(--pearl-dim);margin-top:6px;line-height:1.6}
.tag-row{display:flex;flex-wrap:wrap;gap:8px}
.tag-chip{
  display:inline-flex;align-items:center;padding:7px 10px;border-radius:999px;
  background:rgba(124,92,255,.12);border:1px solid rgba(124,92,255,.2);color:var(--violet-soft);font-size:11px;font-weight:700;
}
.io-prev{
  background:rgba(255,255,255,.03);padding:9px 10px;border-radius:8px;border-right:2px solid rgba(124,92,255,.65);
  font-size:11.5px;line-height:1.8
}
.io-prev.out{border-right-color:rgba(201,168,76,.75)}
.io-prev b{color:var(--gold)}
.io-prev span{color:var(--pearl-dim)}
.analysis-card,
.sprint-card,
.milestone-item{
  background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);border-radius:12px;padding:12px;
}
.analysis-card ul,.sprint-card ul{margin:10px 0 0;padding-right:18px}
.analysis-line{font-size:12px;line-height:1.8;color:var(--pearl)}
.milestone-item{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;font-size:11.5px}
.milestone-item b{color:var(--gold);font-size:12px}
.milestone-item span{color:var(--pearl-dim);text-align:left;line-height:1.7}
.sprint-card b{display:block;color:var(--gold);margin-bottom:6px}
.sprint-card span{display:block;font-size:11.5px;color:var(--pearl-dim);margin-bottom:8px}

@media (max-width:1400px){
  .tool-grid{grid-template-columns:1fr}
}
@media (max-width:1100px){
  .summary-strip{grid-template-columns:1fr 1fr}
}
@media (max-width:820px){
  .proposal-grid,.inline-fields,.stat-grid-2,.summary-strip{grid-template-columns:1fr}
  .welcome-card{max-width:100%}
}
