/* Puter Playground — dark-first, light supported via [data-theme="light"]. */

:root {
  --bg:        #0d1117;
  --bg-soft:   #131a23;
  --bg-elev:   #1a222d;
  --line:      #263242;
  --line-soft: #1c2531;
  --fg:        #e6edf3;
  --fg-dim:    #9aa8b8;
  --fg-faint:  #6b7a8d;
  --accent:    #4c8dff;
  --accent-dim:#2b5eb8;
  --free:      #2ea86b;
  --warn:      #d99a2b;
  --danger:    #e5534b;
  --radius:    10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

[data-theme="light"] {
  --bg:        #ffffff;
  --bg-soft:   #f6f8fa;
  --bg-elev:   #ffffff;
  --line:      #d8dee4;
  --line-soft: #e6eaef;
  --fg:        #1f2328;
  --fg-dim:    #57606a;
  --fg-faint:  #848d97;
  --accent:    #0969da;
  --accent-dim:#84aede;
  --free:      #1a7f4b;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ───────────────────────── sidebar ───────────────────────── */

#sidebar {
  width: 330px;
  flex: 0 0 330px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line-soft); }
.brand { display: flex; gap: 11px; align-items: center; }
.brand-mark { font-size: 26px; line-height: 1; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--fg-faint); }

.side-search { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }

#search {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
#search:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; border-color: var(--accent); }

.filter-row { display: flex; gap: 12px; margin-top: 9px; flex-wrap: wrap; }
.chk { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--fg-dim); cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); margin: 0; cursor: pointer; }

.model-list { flex: 1; overflow-y: auto; padding: 8px 8px 16px; min-height: 0; }

.group-head {
  position: sticky; top: 0;
  background: var(--bg-soft);
  padding: 9px 8px 5px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg-faint);
  z-index: 1;
}

.mitem {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  line-height: 1.35;
}
.mitem:hover { background: var(--bg-elev); }
.mitem.sel { background: var(--accent); color: #fff; }
.mitem.sel .mitem-sub { color: rgba(255,255,255,0.8); }
.mitem-top { display: flex; align-items: center; gap: 6px; }
.mitem-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mitem-sub { font-size: 11px; color: var(--fg-faint); font-family: var(--mono); }

.badge {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em;
  padding: 1px 5px; border-radius: 999px; flex: none;
}
.badge.free  { background: var(--free); color: #fff; }
.badge.tool  { background: var(--line); color: var(--fg-dim); }
.mitem.sel .badge.tool { background: rgba(255,255,255,0.25); color: #fff; }
.free-badge { color: var(--free); }

.side-foot { border-top: 1px solid var(--line-soft); padding: 11px 14px; }
.auth-box { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex: none; }
.dot.on  { background: var(--free); }
.dot.off { background: var(--danger); }
#authText { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.usage { margin-top: 9px; }
.usage-bar { height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; }
.usage-fill { height: 100%; background: var(--free); width: 0; transition: width .4s ease; }
.usage-txt { font-size: 11px; color: var(--fg-faint); margin-top: 4px; font-family: var(--mono); }

/* ───────────────────────── main ───────────────────────── */

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.current { flex: 1; min-width: 0; }
.current-name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-meta { font-size: 11.5px; color: var(--fg-faint); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn-icon, .btn-ghost, .btn-mini {
  background: transparent; border: 1px solid var(--line);
  color: var(--fg-dim); border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 13px; padding: 5px 10px;
}
.btn-icon { padding: 5px 9px; }
.btn-mini { padding: 3px 9px; font-size: 12px; }
.btn-icon:hover, .btn-ghost:hover, .btn-mini:hover { color: var(--fg); border-color: var(--fg-faint); }
#menuBtn { display: none; }

/* chat */

.chat { flex: 1; overflow-y: auto; min-height: 0; }

.welcome { max-width: 760px; margin: 0 auto; padding: 54px 24px 20px; }
.welcome h1 { font-size: 30px; letter-spacing: -0.02em; margin: 0 0 10px; }
.lede { color: var(--fg-dim); margin: 0 0 26px; font-size: 15.5px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 13px; }
.card { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 15px; }
.card h3 { margin: 0 0 6px; font-size: 14px; }
.card p { margin: 0; font-size: 13px; color: var(--fg-dim); line-height: 1.5; }
.fineprint { margin-top: 26px; font-size: 12px; color: var(--fg-faint); }
.fineprint a { color: var(--fg-dim); }

.messages { max-width: 820px; margin: 0 auto; padding: 22px 24px 8px; }

.msg { display: flex; gap: 13px; padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.msg:last-child { border-bottom: 0; }
.avatar {
  width: 27px; height: 27px; flex: none; border-radius: 7px;
  display: grid; place-items: center; font-size: 13px;
  background: var(--bg-elev); border: 1px solid var(--line);
}
.msg.user .avatar { background: var(--accent); border-color: var(--accent); color: #fff; }
.body { flex: 1; min-width: 0; }
.who { font-size: 11.5px; color: var(--fg-faint); margin-bottom: 3px; font-family: var(--mono); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text code {
  background: var(--bg-soft); border: 1px solid var(--line-soft);
  padding: 1px 5px; border-radius: 5px; font-family: var(--mono); font-size: 0.9em;
}
.text pre {
  background: var(--bg-soft); border: 1px solid var(--line-soft);
  padding: 12px 13px; border-radius: var(--radius); overflow-x: auto;
}
.text pre code { background: none; border: 0; padding: 0; }

.err {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--fg); padding: 10px 13px; border-radius: var(--radius); font-size: 13.5px;
}
.err b { color: var(--danger); }

.cursor::after {
  content: "▍"; color: var(--accent);
  animation: blink 1.05s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* composer */

#composer { border-top: 1px solid var(--line); background: var(--bg); padding: 13px 24px 15px; }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 9px; align-items: flex-end; }

#input {
  flex: 1; resize: none; max-height: 200px;
  padding: 11px 13px;
  background: var(--bg-soft); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; font-size: 14.5px; line-height: 1.5;
}
#input:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; border-color: var(--accent); }

.btn-send, .btn-stop {
  flex: none; width: 41px; height: 41px; border-radius: var(--radius);
  border: 0; cursor: pointer; font-size: 15px; color: #fff;
}
.btn-send { background: var(--accent); }
.btn-send:disabled { background: var(--line); color: var(--fg-faint); cursor: not-allowed; }
.btn-stop { background: var(--danger); }

.composer-foot {
  max-width: 820px; margin: 6px auto 0;
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--fg-faint); font-family: var(--mono);
}

/* mobile */

@media (max-width: 820px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.45);
  }
  #sidebar.open { transform: none; }
  #menuBtn { display: block; }
  .welcome { padding-top: 32px; }
  .welcome h1 { font-size: 24px; }
  .messages, #composer { padding-left: 15px; padding-right: 15px; }
}
