/* QP AI Studio — dark, ChatGPT-style layout. Mobile-first friendly. */
:root {
  --bg: #0e1214;
  --panel: #151b20;
  --panel2: #1b232a;
  --border: #263139;
  --text: #e8eef2;
  --dim: #94a6b4;
  --accent: #34d399;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --radius: 14px;
  --sidebar-w: 272px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.m-only { display: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
::selection { background: rgba(52, 211, 153, 0.35); }

/* ---------- buttons ---------- */
.btn {
  border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border); background: var(--panel2); display: inline-flex;
  align-items: center; gap: 8px; justify-content: center; transition: filter .15s, opacity .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #06251a; border-color: transparent; }
.btn.danger { background: #7f1d1d; border-color: #991b1b; color: #fecaca; }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; }
.linklike { color: var(--dim); font-size: 13px; }
.linklike:hover { color: var(--text); }
.icon { padding: 6px 9px; border-radius: 8px; font-size: 16px; color: var(--dim); }
.icon:hover { background: var(--panel2); color: var(--text); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  display: grid; grid-template-columns: 1.1fr 1fr; max-width: 920px; width: 100%;
  border: 1px solid var(--border); border-radius: 22px; overflow: hidden; background: var(--panel);
}
.auth-hero { padding: 48px 40px; background: radial-gradient(120% 120% at 0% 0%, #122521 0%, var(--panel) 55%); }
.qp-logo { display: block; height: 64px; width: auto; max-width: 80%; margin: 0 auto 12px; }
.auth-hero h1 { font-size: 30px; letter-spacing: -.5px; }
.auth-hero .tag { color: var(--accent); font-weight: 600; margin: 6px 0 14px; font-size: 17px; }
.auth-hero .sub { color: var(--dim); font-size: 14px; margin-bottom: 22px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); color: var(--dim); padding: 5px 12px; border-radius: 999px; font-size: 12.5px; background: var(--bg); }
.auth-form { padding: 40px 32px; border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.tabs { display: flex; gap: 4px; margin-bottom: 22px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { flex: 1; padding: 8px; border-radius: 8px; color: var(--dim); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--panel2); color: var(--text); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 5px; font-weight: 600; }
.field input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.hp { position: absolute; left: -9999px; height: 0; width: 0; opacity: 0; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.auth-foot { margin-top: auto; padding-top: 18px; font-size: 12.5px; color: var(--dim); display: flex; flex-direction: column; gap: 8px; }

/* ---------- shell ---------- */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 12px; gap: 12px;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.logo { color: var(--accent); font-size: 20px; text-shadow: 0 0 14px rgba(52,211,153,.45); }
.brand { font-weight: 800; letter-spacing: .2px; }
#new-chat { margin-bottom: 2px; }
#conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  padding: 9px 11px; border-radius: 10px; color: var(--dim); font-size: 14px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px;
}
.conv-item:hover { background: var(--panel2); color: var(--text); }
.conv-item.active { background: var(--panel2); color: var(--text); }
.conv-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.side-foot { border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px; }
.user-chip { font-weight: 700; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; }
.foot-row { display: flex; justify-content: space-between; align-items: center; }

/* ---------- main / chat ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
}
#chat-title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 8px; }
#model-select, select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 13.5px; outline: none; max-width: 190px;
}
#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#messages { flex: 1; overflow-y: auto; padding: 26px 18px 8px; scroll-behavior: smooth; }
.msg-col { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* empty state */
#empty-state { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.hero-diamond { color: var(--accent); font-size: 44px; text-shadow: 0 0 30px rgba(52,211,153,.5); margin-bottom: 10px; }
#empty-state h2 { font-size: 24px; margin-bottom: 22px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chipbtn {
  border: 1px solid var(--border); background: var(--panel); color: var(--dim); text-align: left;
  padding: 13px 15px; border-radius: 14px; font-size: 13.5px; line-height: 1.4; transition: border-color .15s, color .15s;
}
.chipbtn:hover { border-color: var(--accent); color: var(--text); }

/* message bubbles */
.msg.user { align-self: flex-end; background: var(--accent-soft); border: 1px solid rgba(52,211,153,.25); padding: 11px 15px; border-radius: 16px 16px 4px 16px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 13px 16px; }
.msg.assistant .who { font-size: 12px; color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.msg.error { color: var(--danger); }
.msg .meta { font-size: 11.5px; color: var(--dim); margin-top: 8px; font-family: var(--mono); }
.md p { margin: 0 0 8px; } .md p:last-child { margin: 0; }
.md h3 { font-size: 16px; margin: 10px 0 6px; }
.md ul { margin: 4px 0 8px 20px; } .md li { margin: 2px 0; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--bg); padding: 1.5px 5px; border-radius: 6px; }
.md pre { background: var(--bg); border: 1px solid var(--border); padding: 12px; border-radius: 10px; overflow-x: auto; margin: 8px 0; }
.md pre code { background: none; padding: 0; }
.md a { text-decoration: underline; }

/* live activity feed */
#activity { max-width: 780px; margin: 0 auto 8px; width: 100%; display: flex; flex-direction: column; gap: 6px; padding: 0 18px; }
.status-pill { text-align: center; color: var(--dim); font-size: 12.5px; }
.status-pill .typing { display: inline-flex; gap: 4px; margin-left: 6px; }
.status-pill .typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.status-pill .typing i:nth-child(2) { animation-delay: .2s; }
.status-pill .typing i:nth-child(3) { animation-delay: .4s; }
.tool-card {
  display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--dim);
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 8px 12px; border-radius: 10px; animation: slidein .25s ease;
}
.tool-card.err { border-left-color: var(--danger); }
.tool-card .tname { font-weight: 700; color: var(--text); font-family: var(--mono); font-size: 12px; }
.tool-card .tdetail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
@keyframes slidein { from { opacity: 0; transform: translateY(4px); } }
.think-line { color: var(--dim); font-size: 13px; font-style: italic; padding-left: 6px; }
.failover-pill { text-align: center; font-size: 12px; color: #fbbf24; }

/* composer */
#composer { border-top: 1px solid var(--border); background: var(--bg); padding: 10px 18px 14px; }
.composer-row { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
#prompt {
  flex: 1; resize: none; max-height: 180px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px; color: var(--text); font: inherit; outline: none;
}
#prompt:focus { border-color: var(--accent); }
#hint { max-width: 780px; margin: 8px auto 0; text-align: center; color: var(--dim); font-size: 11.5px; }

/* ---------- workspace panel ---------- */
.ws {
  width: 330px; min-width: 330px; background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; overflow: hidden;
}
.ws-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 14px; }
.ws-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ws-actions .btn { font-size: 12.5px; padding: 8px 6px; }
.ws-empty { color: var(--dim); font-size: 13px; text-align: center; margin-top: 30px; }
#file-tree { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.file-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px;
  font-size: 13px; cursor: pointer; color: var(--text); font-family: var(--mono); font-size: 12.5px;
}
.file-row:hover { background: var(--panel2); }
.file-row .sz { color: var(--dim); flex: none; }
#file-view {
  flex: 1; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all;
}

/* ---------- admin ---------- */
#admin-view { flex: 1; overflow-y: auto; padding: 24px; }
.admin-wrap { max-width: 1000px; margin: 0 auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.stat .n { font-size: 26px; font-weight: 800; color: var(--accent); }
.stat .l { color: var(--dim); font-size: 13px; margin-top: 2px; }
.admin-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 18px; overflow-x: auto; }
.admin-card h3 { margin-bottom: 12px; font-size: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--dim); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.badge { font-size: 11px; padding: 2.5px 8px; border-radius: 999px; background: var(--panel2); color: var(--dim); white-space: nowrap; }
.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: rgba(248,113,113,.12); color: var(--danger); }
.mini { padding: 4px 9px; font-size: 12px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 18px; font-size: 14px; z-index: 99;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ---------- mobile ---------- */
@media (max-width: 920px) {
  .m-only { display: inline-flex; }
  #sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: calc(-1 * var(--sidebar-w) - 12px);
    transition: left .22s ease; box-shadow: none;
  }
  #sidebar.open { left: 0; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .ws { position: fixed; z-index: 40; top: 0; bottom: 0; right: -346px; width: min(340px, 92vw); transition: right .22s ease; }
  .ws.open { right: 0; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .auth-card { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 26px; }
  .qp-logo { height: 46px; }
  .auth-form { border-left: none; border-top: 1px solid var(--border); padding: 28px 24px; }
  .suggest { grid-template-columns: 1fr; }
  #model-select { max-width: 132px; }
  #messages { padding: 16px 10px 6px; }
  #composer { padding: 8px 10px 10px; }
  #activity { padding: 0 10px; }
  #topbar { padding: 8px 10px; }
}
