:root{
  --bg: #ffffff;
  --panel: #fbfbfc;
  --panel2:#f6f7f9;
  --text:#0f172a;
  --muted:#64748b;
  --border:#e5e7eb;
  --border2:#d9dde5;
  --shadow: 0 10px 30px rgba(2,8,23,.06);
  --shadow2: 0 8px 22px rgba(2,8,23,.08);
  --radius: 16px;
  --radius2: 20px;
  --accent:#111827;
  --accent2:#0f172a;
  --good:#16a34a;
  --warn:#f59e0b;
  --bad:#ef4444;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  color:var(--text);
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);
}

.app{
  height:100vh;
  display:grid;
  grid-template-columns: 340px 1fr;
}

.sidebar{
  border-right:1px solid var(--border);
  background: var(--panel);
  padding:18px 16px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.brand{
  border:1px solid var(--border);
  border-radius: var(--radius);
  background:#fff;
  box-shadow: var(--shadow);
  padding:0;
  overflow:hidden;
  min-height:118px;
}

.brand-image{
  display:block;
  width:100%;
  height:118px;
  object-fit:contain;
}

.logo{
  width:36px;height:36px;
  border-radius: 12px;
  display:grid;place-items:center;
  border:1px solid var(--border);
  background: linear-gradient(180deg,#fff,#f7f7fa);
}
.brand-title{font-weight:700; letter-spacing:-0.02em}
.brand-sub{color:var(--muted); font-size:12px; margin-top:2px}

.panel{
  border:1px solid var(--border);
  border-radius: var(--radius);
  background:#fff;
  box-shadow: var(--shadow);
  padding:12px;
}
.panel-muted{background: var(--panel2)}
.panel-title{font-weight:600; font-size:13px; color:#111827; margin-bottom:8px}

.muted-list{margin:0; padding-left:18px; color:var(--muted); font-size:13px; line-height:1.5}
.muted-list b{color:#111827}

.files{
  display:flex;
  flex-direction:column;
  gap:8px;
  min-height: 120px;
  max-height: 40vh;
  overflow:auto;
  padding-right:4px;
}
.file-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 10px;
  border:1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}
.file-meta{min-width:0}
.file-name{
  font-size:13px;
  font-weight:600;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.file-sub{font-size:12px; color:var(--muted); margin-top:2px}

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

.topbar{
  border-bottom:1px solid var(--border);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  padding:12px 16px;
}

.controls{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:end;
}

.field{display:flex; flex-direction:column; gap:6px}
.field span{font-size:12px; color:var(--muted)}
.field input,.field select{
  height:38px;
  padding:0 12px;
  border:1px solid var(--border2);
  border-radius: 12px;
  background:#fff;
  outline:none;
}
.field input:focus,.field select:focus{border-color:#b6c0d3; box-shadow: 0 0 0 3px rgba(2,8,23,.06)}
.field-small select{min-width:120px}

.checkbox{display:flex; align-items:center; gap:8px; color:var(--muted); font-size:13px; user-select:none}
.checkbox input{width:16px; height:16px}

.segmented{
  display:flex;
  border:1px solid var(--border2);
  border-radius: 12px;
  overflow:hidden;
  background:#fff;
  height:38px;
}
.seg-btn{
  border:0;
  padding:0 14px;
  font-weight:600;
  color:#111827;
  background:transparent;
  cursor:pointer;
}
.seg-btn.is-active{
  background: #111827;
  color:#fff;
}

.mode-hint{
  margin-top:10px;
  font-size:13px;
  color:var(--muted);
}
.mode-hint b{color:#111827}

.chat{
  flex:1;
  overflow:auto;
  padding: 18px 18px 10px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);
}

.msg{
  display:flex;
  gap:12px;
  margin: 10px auto;
  max-width: 980px;
}

.avatar{
  width:34px; height:34px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: linear-gradient(180deg,#fff,#f5f6fa);
  display:grid;
  place-items:center;
  flex:0 0 auto;
  color:#111827;
  font-weight:700;
}

.bubble{
  border:1px solid var(--border);
  background:#fff;
  border-radius: var(--radius2);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  width: fit-content;
  max-width: 860px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user .bubble{
  background: #111827;
  color:#fff;
  border-color:#111827;
  box-shadow: var(--shadow2);
}

.msg.user{
  flex-direction: row-reverse;
}

.msg.user .avatar{
  background: #111827;
  color:#fff;
  border-color:#111827;
}

.bubble .meta{
  margin-top:8px;
  font-size: 12px;
  color: var(--muted);
}

.composer{
  border-top:1px solid var(--border);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  padding: 12px 16px;
}

.composer-top{
  display:flex;
  align-items:center;
  gap:10px;
  margin-bottom: 10px;
}

.filepick input{display:none}
.filepick-btn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 8px 12px;
  border:1px solid var(--border2);
  border-radius: 12px;
  background:#fff;
  cursor:pointer;
  user-select:none;
  font-weight:600;
  font-size:13px;
}

.chips{display:flex; flex-wrap:wrap; gap:8px; min-height: 22px}
.chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 6px 10px;
  border:1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
}
.chip.warn{border-color: rgba(245,158,11,.6); background: rgba(245,158,11,.08)}
.chip button{
  border:0;
  background:transparent;
  cursor:pointer;
  color: var(--muted);
  font-size: 14px;
  line-height:1;
}

.composer-bottom{
  display:flex;
  gap:10px;
  align-items:flex-end;
}

textarea{
  width:100%;
  resize:none;
  min-height: 44px;
  max-height: 180px;
  padding: 10px 12px;
  border:1px solid var(--border2);
  border-radius: 14px;
  outline:none;
  font-size: 14px;
  line-height: 1.5;
  background:#fff;
}
textarea:focus{border-color:#b6c0d3; box-shadow: 0 0 0 3px rgba(2,8,23,.06)}

.btn{
  height:44px;
  padding:0 14px;
  border-radius: 14px;
  border:1px solid var(--border2);
  background:#fff;
  cursor:pointer;
  font-weight:700;
  font-size: 13px;
  user-select:none;
}
.btn:disabled{opacity:.55; cursor:not-allowed}

.btn-primary{
  background:#111827;
  color:#fff;
  border-color:#111827;
}
.btn-secondary{
  background:#fff;
}

.btn-mic{
  min-width:56px;
  width:56px;
  padding:0;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:0;
  position:relative;
  overflow:hidden;
}

.mic-icon{
  font-size:18px;
  line-height:1;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.mic-timer{
  position:absolute;
  inset:auto 6px 4px 6px;
  font-size:10px;
  line-height:1;
  color:var(--muted);
  opacity:0;
  transform:translateY(4px);
  transition:opacity .18s ease, transform .18s ease;
  pointer-events:none;
}

.btn-mic.is-recording{
  background: rgba(239,68,68,.12);
  border-color: rgba(239,68,68,.5);
  color: var(--bad);
  box-shadow: 0 0 0 3px rgba(239,68,68,.08);
  animation: mic-pulse 1.3s ease-in-out infinite;
}

.btn-mic.is-recording .mic-timer{
  opacity:1;
  transform:translateY(0);
  color:var(--bad);
}

.btn-mic.is-transcribing{
  background:#fff7ed;
  border-color: rgba(245,158,11,.45);
  color: #9a3412;
}

.voice-status{
  margin-top:6px;
}

@keyframes mic-pulse{
  0%{ box-shadow: 0 0 0 0 rgba(239,68,68,.18); }
  70%{ box-shadow: 0 0 0 10px rgba(239,68,68,0); }
  100%{ box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}


.status{
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}

@media (max-width: 980px){
  .app{grid-template-columns: 1fr}
  .sidebar{display:none}
  .msg{max-width: 100%}
}

@media (max-width: 640px){
  .composer-bottom{
    gap:8px;
  }

  .btn-mic,
  .btn-primary{
    flex: 0 0 auto;
  }
}

.is-hidden{display:none !important;}
