/* ====================================================================
   Prompt Generator — styles
   Clean minimal utility tool. IBM Plex Sans + Mono. Warm paper canvas.
   ==================================================================== */

:root {
  --paper:      #f4f2ec;
  --surface:    #ffffff;
  --surface-2:  #faf9f5;
  --ink:        #191815;
  --ink-2:      #57544c;
  --muted:      #908b7e;
  --hair:       #e3e0d6;
  --hair-2:     #ece9e0;

  --accent:        oklch(0.55 0.19 28);     /* warm vermilion-red */
  --accent-press:  oklch(0.48 0.19 28);
  --accent-soft:   oklch(0.95 0.045 40);    /* token / chip background */
  --accent-line:   oklch(0.86 0.08 40);
  --accent-ink:    oklch(0.44 0.17 28);

  --ok:    oklch(0.55 0.12 150);
  --warn:  oklch(0.62 0.13 70);

  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(30,25,15,.05), 0 1px 1px rgba(30,25,15,.04);
  --shadow-md: 0 4px 16px rgba(40,33,20,.08), 0 1px 3px rgba(40,33,20,.06);
  --shadow-pop: 0 12px 38px rgba(35,28,15,.16), 0 2px 8px rgba(35,28,15,.10);

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--accent-soft); }

/* ---- App shell ----------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "head head" "side main";
  height: 100vh;
  min-height: 0;
}

.topbar {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--hair);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-family: var(--mono); font-weight: 600; font-size: 16px;
  box-shadow: var(--shadow-sm);
}
.brand .title { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.brand .title small { color: var(--muted); font-weight: 500; }
.topbar .spacer { flex: 1; }

.icon-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---- Model selector ------------------------------------------------ */
.model-select { position: relative; }
.model-trigger {
  display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 12px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 500;
  transition: border-color .12s, box-shadow .12s;
}
.model-trigger:hover { border-color: #d2cec1; }
.model-trigger:disabled { opacity: .6; cursor: default; }
.model-trigger .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.model-trigger .dot.off { background: #cfcabd; }
.model-trigger .mname { font-family: var(--mono); font-size: 12.5px; }
.model-trigger .caret { color: var(--muted); margin-left: 2px; }
.model-trigger .label-pre { color: var(--muted); font-weight: 500; }

.model-menu {
  position: absolute; top: calc(100% + 7px); right: 0;
  width: 320px; max-height: 64vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--hair);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  padding: 6px; z-index: 50;
}
.model-group-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 9px 10px 4px;
}
.model-opt {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink); font-size: 13.5px;
}
.model-opt:hover { background: var(--surface-2); }
.model-opt.sel { background: var(--accent-soft); }
.model-opt .ml { font-weight: 500; }
.model-opt .mid { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: auto; }
.model-opt .check { color: var(--accent-ink); }

/* search box inside the model menu */
.model-search {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; margin: 2px 2px 6px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--muted);
  position: sticky; top: 0; z-index: 1;
}
.model-search input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-family: var(--sans); font-size: 13.5px; color: var(--ink);
}
.menu-msg { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.menu-msg.err { color: var(--accent); }

/* ---- API key menu -------------------------------------------------- */
.key-select { position: relative; }
.key-trigger .kicon { color: var(--ink-2); display: inline-flex; }
.key-trigger.unset { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-ink); }
.key-trigger.unset .kicon { color: var(--accent-ink); }

.key-menu { width: 320px; padding: 14px; }
.key-title { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 9px; }
.key-input {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); font-size: 13px; outline: none;
}
.key-input:focus { border-color: var(--accent-line); background: var(--surface); }
.key-actions { display: flex; gap: 8px; margin-top: 10px; }
.key-save, .key-clear {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; border: 1px solid transparent;
}
.key-save { background: var(--accent); color: #fff; }
.key-save:hover:not(:disabled) { background: var(--accent-press); }
.key-save:disabled { background: #d8d3c6; cursor: not-allowed; }
.key-clear { background: var(--surface); color: var(--ink-2); border-color: var(--hair); }
.key-clear:hover { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }

.key-usage {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--hair-2);
  font-size: 13px;
}
.key-usage .ku-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.key-usage .ku-val b { font-family: var(--mono); font-weight: 600; }
.key-usage .ku-muted { color: var(--muted); }
.key-usage .ku-err { color: var(--accent); font-size: 12.5px; }
.key-usage .ku-tag {
  margin-left: 6px; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink); text-transform: uppercase; letter-spacing: .04em;
}
.key-usage .ku-refresh {
  margin-left: auto; width: 26px; height: 26px; display: grid; place-items: center;
  border: 1px solid var(--hair); border-radius: var(--r-sm); background: var(--surface); color: var(--ink-2);
}
.key-usage .ku-refresh:hover:not(:disabled) { border-color: var(--accent-line); color: var(--accent-ink); }
.key-usage .ku-refresh:disabled { opacity: .5; cursor: default; }

.key-hint { display: inline-block; margin-top: 12px; font-size: 12.5px; color: var(--accent-ink); text-decoration: none; }
.key-hint:hover { text-decoration: underline; }
.key-note { margin-top: 8px; font-size: 11.5px; line-height: 1.45; color: var(--muted); }

/* ---- "set key" banner above the composer --------------------------- */
.keybar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px;
  border: 1px solid var(--accent-line); border-radius: var(--r-md);
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 13.5px; font-weight: 500;
}
.keybar-btn {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
  height: 32px; padding: 0 13px; border-radius: var(--r-sm);
  background: var(--accent); color: #fff; border: 0; font-size: 13px; font-weight: 600;
}
.keybar-btn:hover { background: var(--accent-press); }

/* ---- Sidebar / library --------------------------------------------- */
.sidebar {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--hair);
  display: flex; flex-direction: column;
  min-height: 0;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px;
}
.side-head h2 {
  margin: 0; font-size: 12px; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.new-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px 0 8px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2);
  font-size: 12.5px; font-weight: 500;
}
.new-btn:hover { border-color: var(--accent-line); color: var(--accent-ink); background: var(--accent-soft); }

.lib-list { flex: 1; overflow-y: auto; padding: 4px 12px 16px; min-height: 0; }
.lib-item {
  position: relative;
  padding: 11px 12px; margin-bottom: 6px;
  border: 1px solid transparent; border-radius: var(--r-md);
  cursor: pointer; transition: background .12s, border-color .12s;
}
.lib-item:hover { background: var(--surface-2); }
.lib-item.active { background: var(--accent-soft); border-color: var(--accent-line); }
.lib-item .li-name { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; letter-spacing: -0.005em; }
.lib-item .li-tmpl {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2);
  line-height: 1.45; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.lib-item .li-tmpl b { color: var(--accent-ink); font-weight: 600; }
.lib-del {
  position: absolute; top: 9px; right: 8px;
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  display: none; align-items: center; justify-content: center;
}
.lib-item:hover .lib-del { display: flex; }
.lib-del:hover { background: rgba(0,0,0,.06); color: var(--accent); }
.lib-empty { color: var(--muted); font-size: 13px; padding: 16px 12px; line-height: 1.5; }

/* ---- Main workspace ------------------------------------------------ */
.main {
  grid-area: main;
  overflow-y: auto;
  min-height: 0;
}
.workspace {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 28px 80px;
}

/* Composer card */
.composer {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.composer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hair-2);
}
.name-input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  font-family: var(--sans); font-size: 16px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.01em;
}
.name-input:focus { outline: none; }
.name-input::placeholder { color: var(--muted); font-weight: 500; }
.save-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 13px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.save-btn:hover { border-color: #d2cec1; background: var(--surface-2); }
.save-btn.saved { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 35%, var(--hair)); }

.editor-wrap { padding: 16px 18px 4px; }
.editor {
  width: 100%; min-height: 92px; resize: vertical;
  border: 0; background: transparent; padding: 0;
  font-family: var(--mono); font-size: 17px; line-height: 1.55; color: var(--ink);
  letter-spacing: -0.005em;
}
.editor:focus { outline: none; }
.editor::placeholder { color: #b9b4a6; }

/* token palette + detected chips */
.token-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  padding: 12px 18px 16px;
}
.token-row .row-label {
  font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); margin-right: 2px;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px;
  border: 1px solid var(--hair); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  transition: all .12s;
}
button.chip:hover { border-color: var(--accent-line); color: var(--accent-ink); background: var(--accent-soft); }
.chip.detected { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.chip.unknown { border-color: color-mix(in oklch, var(--warn) 40%, var(--hair)); color: var(--warn); background: color-mix(in oklch, var(--warn) 8%, white); }
.chip .x { opacity: .55; }

.palette-toggle { color: var(--muted); font-size: 12px; background: none; border: 0; text-decoration: underline; text-underline-offset: 2px; }

/* composer footer / controls */
.composer-foot {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  border-top: 1px solid var(--hair-2);
  background: var(--surface-2);
}
.batch {
  display: flex; align-items: center; gap: 0;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); overflow: hidden; height: 40px;
}
.batch .blab { font-size: 12.5px; color: var(--ink-2); padding: 0 11px; font-weight: 500; }
.batch .bbtn {
  width: 34px; height: 100%; border: 0; background: var(--surface); color: var(--ink-2);
  font-size: 18px; display: grid; place-items: center; border-left: 1px solid var(--hair-2);
}
.batch .bbtn:hover:not(:disabled) { background: var(--surface-2); color: var(--accent-ink); }
.batch .bbtn:disabled { color: #cfcabd; cursor: not-allowed; }
.batch .bval { min-width: 30px; text-align: center; font-family: var(--mono); font-weight: 600; font-size: 14px; border-left: 1px solid var(--hair-2); height: 100%; display: grid; place-items: center; padding: 0 4px; }

.foot-spacer { flex: 1; }

.run-btn {
  display: inline-flex; align-items: center; gap: 9px;
  height: 40px; padding: 0 20px; white-space: nowrap;
  border: 0; border-radius: var(--r-sm);
  background: var(--accent); color: #fff;
  font-size: 14.5px; font-weight: 600; letter-spacing: -0.005em;
  box-shadow: var(--shadow-sm);
  transition: background .12s, transform .06s;
}
.run-btn:hover { background: var(--accent-press); }
.run-btn:active { transform: translateY(1px); }
.run-btn:disabled { background: #d8d3c6; color: #fff; cursor: not-allowed; box-shadow: none; }
.run-btn kbd {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.2); padding: 2px 5px; border-radius: 4px;
}

/* ---- Results feed -------------------------------------------------- */
.results { margin-top: 30px; }
.results-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px;
}
.results-head h3 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.results-head .count { font-size: 12.5px; color: var(--muted); font-family: var(--mono); }
.clear-link { margin-left: auto; font-size: 12.5px; color: var(--muted); background: none; border: 0; white-space: nowrap; }
.clear-link:hover { color: var(--accent); }

.batch-group { margin-bottom: 22px; }
.batch-tag {
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: 9px;
  font-size: 11.5px; color: var(--muted); font-family: var(--mono);
}
.batch-tag .bt-model { color: var(--ink-2); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  overflow: hidden;
  animation: rise .28s cubic-bezier(.2,.7,.3,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-prompt {
  font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--ink-2);
  padding: 13px 16px; border-bottom: 1px dashed var(--hair);
  background: var(--surface-2);
}
.card-prompt .fill {
  background: var(--accent-soft); color: var(--accent-ink);
  border: 1px solid var(--accent-line);
  border-radius: 5px; padding: 0 5px; font-weight: 600;
  white-space: nowrap;
}
.card-body { padding: 15px 16px 14px; }
.card-resp {
  font-family: var(--sans); font-size: 17px; line-height: 1.6; color: var(--ink);
  white-space: pre-wrap; letter-spacing: -0.005em;
  text-wrap: pretty;
}
.card-resp.thinking { color: var(--muted); }
.card-resp.errored { color: var(--accent); font-family: var(--mono); font-size: 13.5px; }

.card-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-top: 1px solid var(--hair-2);
}
.card-foot .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.card-foot .meta b { color: var(--ink-2); font-weight: 600; }
.card-foot .fspacer { flex: 1; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2); font-size: 12px; font-weight: 500;
  transition: all .12s;
}
.mini-btn:hover { border-color: var(--accent-line); color: var(--accent-ink); background: var(--accent-soft); }
.mini-btn.copied { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 35%, var(--hair)); }

/* thinking shimmer */
.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.1s infinite both;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }

/* empty state */
.empty {
  text-align: center; padding: 54px 20px; color: var(--muted);
  border: 1px dashed var(--hair); border-radius: var(--r-lg); background: var(--surface-2);
}
.empty .big { font-size: 15px; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.empty .sub { font-size: 13.5px; line-height: 1.55; }
.empty code { font-family: var(--mono); background: var(--accent-soft); color: var(--accent-ink); padding: 1px 6px; border-radius: 5px; }

/* sidebar scrim for mobile */
.scrim { display: none; }

/* ---- Responsive ---------------------------------------------------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "head" "main"; }
  .icon-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 290px; z-index: 60;
    transform: translateX(-100%); transition: transform .22s cubic-bezier(.2,.7,.3,1);
    box-shadow: var(--shadow-pop);
  }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(25,20,10,.34);
  }
  .workspace { padding: 18px 16px 70px; }
  .model-trigger .label-pre { display: none; }
  .topbar { gap: 10px; padding: 0 14px; }
  .key-menu, .model-menu { right: 0; }
}
@media (max-width: 520px) {
  .composer-foot { flex-wrap: wrap; }
  .foot-spacer { display: none; }
  .run-btn { flex: 1; justify-content: center; }
  .editor { font-size: 16px; }
  .card-resp { font-size: 16px; }
  .model-trigger .mname { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
