:root{
  --bg:#0B0C10; --surface:#14161D; --surface2:#1B1E27;
  --line:#2A2F3A; --fg:#F5F6F7; --muted:#9AA0A6; --accent:#838BE2;
  --ok:#5FD08A; --err:#E2707A;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--fg);
  font-family:"Hiragino Sans","Hiragino Kaku Gothic ProN","Noto Sans JP",system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:15px; line-height:1.7;
}
button{font:inherit; cursor:pointer; border:0; border-radius:8px; padding:10px 16px; background:var(--accent); color:#0B0C10; font-weight:600}
button:disabled{opacity:.45; cursor:default}
button.ghost{background:transparent; color:var(--fg); border:1px solid var(--line); font-weight:500}
button.link{background:none; padding:0; color:var(--muted); font-weight:400; font-size:12px; text-decoration:underline}
a.ghost{display:inline-block; background:transparent; color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:6px 12px; font-weight:500; font-size:12px; text-decoration:none}
a.ghost.primary{background:var(--accent); color:#0B0C10; border-color:var(--accent); font-weight:600}
a.ghost:hover{opacity:.85}
input,textarea{
  width:100%; background:var(--surface2); color:var(--fg); border:1px solid var(--line);
  border-radius:8px; padding:10px 12px; font:inherit; outline:none;
}
input:focus,textarea:focus{border-color:var(--accent-dim, #5B62A8)}
textarea{resize:vertical; min-height:88px}
a{color:var(--accent)}
.tiny{font-size:12px; color:var(--muted)}
.err{color:var(--err); font-size:13px; min-height:20px}

/* login */
.login{height:100%; display:grid; place-items:center; padding:24px}
.login .card{width:100%; max-width:420px; background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:32px}
.login h1{margin:0 0 6px; font-size:26px; letter-spacing:.02em}
.login .sub{margin:0 0 24px; color:var(--muted); font-size:13px}
.login input{margin-bottom:10px}
.login button{width:100%; margin-top:6px}

/* shell */
.app{height:100%; display:grid; grid-template-columns:264px 1fr}
.side{border-right:1px solid var(--line); background:var(--surface); padding:18px 14px; display:flex; flex-direction:column; gap:14px; overflow:hidden}
.brand{font-weight:700; letter-spacing:.06em; font-size:13px; color:var(--muted); text-transform:uppercase}
.who{display:flex; justify-content:space-between; align-items:center; gap:8px; font-size:13px}
.who span{overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.meter-bar{height:4px; background:var(--surface2); border-radius:99px; overflow:hidden; margin-bottom:6px}
.meter-bar i{display:block; height:100%; width:0; background:var(--accent); transition:width .3s}
.newdoc button{width:100%}
.docs{overflow:auto; display:flex; flex-direction:column; gap:2px}
.doc{text-align:left; background:none; color:var(--muted); border-radius:6px; padding:8px 10px; font-size:13px; font-weight:400; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.doc:hover{background:var(--surface2); color:var(--fg)}
.doc.active{background:var(--surface2); color:var(--fg)}

/* main */
.main{display:grid; grid-template-columns:minmax(320px,420px) 1fr; overflow:hidden}
.chat{display:flex; flex-direction:column; border-right:1px solid var(--line); overflow:hidden}
.log{flex:1; overflow:auto; padding:20px 16px; display:flex; flex-direction:column; gap:14px}
.msg{border-radius:10px; padding:10px 12px; font-size:14px; white-space:pre-wrap; word-break:break-word}
.msg.user{background:var(--surface2); align-self:flex-end; max-width:92%}
.msg.assistant{background:transparent; border-left:2px solid var(--line); padding-left:12px; color:var(--fg)}
.msg.sys{color:var(--muted); font-size:12px}
.files{display:flex; flex-wrap:wrap; gap:6px; padding:0 16px}
.chip{font-size:12px; background:var(--surface2); border:1px solid var(--line); border-radius:99px; padding:3px 10px; color:var(--muted)}
.composer{border-top:1px solid var(--line); padding:12px 16px 16px}
.composer .row{display:flex; gap:8px; align-items:center; margin-top:8px}
.upload{font-size:12px; color:var(--muted); border:1px dashed var(--line); border-radius:8px; padding:7px 12px; cursor:pointer}
.spacer{flex:1}

/* spec */
.spec{border-top:1px solid var(--line); padding:10px 16px; background:var(--surface)}
.spec summary{font-size:12px; color:var(--muted); cursor:pointer; list-style:none}
.spec summary::-webkit-details-marker{display:none}
.spec summary::before{content:"▸ "; color:var(--accent)}
.spec[open] summary::before{content:"▾ "}
.specgrid{display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:10px}
.specgrid label{font-size:11px; color:var(--muted); display:flex; flex-direction:column; gap:3px}
.specgrid input,.specgrid select{padding:6px 8px; font-size:12px}
.specgrid label:first-child,.specgrid label:nth-child(7),.specgrid label:nth-child(8){grid-column:1 / -1}

/* preview */
.preview{display:flex; flex-direction:column; overflow:hidden; background:#07080B}
.ptools{display:flex; align-items:center; gap:10px; padding:10px 14px; border-bottom:1px solid var(--line); background:var(--surface)}
.ptools a{font-size:12px; padding:6px 12px; border-radius:6px; text-decoration:none}
#frame{flex:1; width:100%; border:0; background:#fff}
