/* ============================================================
   Agent skills demo, styled after Welley group settings.
   Tokens and shared controls are the ones measured on welley.social
   (theme-navy), as in the group-structure demo.
   ============================================================ */
:root {
  --bg-main: #f1f3f6;
  --bg-primary: #ffffff;
  --bg-secondary: #f1f3f6;
  --bg-secondary-hover: #e4e7ed;
  --bg-tertiary: #f8f9fb;
  --brand: #2259f0;
  --brand-hover: #1c4ace;
  --brand-soft: #ecf0fe;
  --badge-bg: #d9e2fd;
  --badge-text: #13318c;
  --t1: #1d2236;
  --t2: #434c63;
  --t3: #7b859e;
  --t4: #a5adc0;
  --border: #e4e7ed;
  --border-strong: #cfd4de;
  --error: #f04438;
  --error-hover: #d92d20;
  --error-soft: #fef3f2;
  --ok: #558402;
  --ok-soft: #f4fcea;
  --warn: #b36d05;
  --warn-soft: #fff9ec;
  --r-xs: 4px;
  --r-sm: 8px;
  --r-m: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --shadow-pop: 0 8px 28px rgba(29, 34, 54, 0.16);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg-main);
  color: var(--t1);
  font-size: 14px;
  line-height: 20px;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: default; }
svg { display: block; flex-shrink: 0; }
.muted { color: var(--t3); }
.small { font-size: 12px; line-height: 16px; }
.spacer { flex: 1; }

/* ---------- persona bar (demo scaffolding) ---------- */
.persona-bar {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px dashed var(--border-strong);
}
.persona-brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 600; font-size: 15px; }
.brand-tag {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--t3); background: var(--bg-secondary-hover); padding: 2px 8px; border-radius: 999px;
}

/* ---------- product chrome ---------- */
.app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 16px;
  padding: 16px;
}
.rail {
  flex: 0 0 64px;
  background: var(--bg-primary);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
}
.rail-logo { margin-bottom: 8px; }
.rail-btn {
  width: 40px; height: 40px; border-radius: var(--r-m);
  display: grid; place-items: center; color: var(--t2);
}
.rail-sep { width: 40px; height: 1px; background: var(--border); margin: 4px 0; }
.rail-group {
  width: 40px; height: 40px; border-radius: var(--r-m);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
}
.rail-group.active { box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--brand); }
.blurred { filter: blur(1.5px); opacity: .45; pointer-events: none; user-select: none; }

.settings-nav {
  flex: 0 0 240px;
  background: var(--bg-primary);
  border-radius: var(--r-lg);
  padding: 16px 12px;
  overflow-y: auto;
}
.nav-group { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.g-ava {
  width: 36px; height: 36px; border-radius: 10px; background: #f79009; color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.nav-gname { font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-m); color: var(--t2); font-weight: 500;
}
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-label {
  font-size: 12px; line-height: 16px; font-weight: 600; text-transform: uppercase; color: var(--t3);
  margin: 16px 10px 6px;
}

.content {
  flex: 1 1 auto; min-width: 0;
  background: var(--bg-primary);
  border-radius: var(--r-lg);
  overflow-y: auto;
}

.assist {
  flex: 0 0 300px;
  background: var(--bg-primary);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.assist .seg { align-self: flex-start; }
.assist-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; color: var(--t3); padding: 0 12px;
}
.assist-empty b { color: var(--t1); }
.composer {
  height: 44px; border-radius: var(--r-m); border: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 14px; color: var(--t4);
}

/* ---------- editor header ---------- */
.ed-head { padding: 16px 24px 12px; }
.crumbs { display: flex; align-items: center; gap: 4px; color: var(--t3); font-size: 13px; }
.crumbs span:last-child { color: var(--t1); font-weight: 500; }
.bot-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.bot-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #2259f0, #7a5af8); color: #fff;
  display: grid; place-items: center;
}
.bot-id { min-width: 0; }
.bot-name { font-size: 19px; line-height: 24px; font-weight: 600; display: flex; align-items: center; gap: 8px; }

.draft-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 24px; padding: 8px 12px; border-radius: var(--r-m);
  background: var(--warn-soft); color: var(--warn);
}
.draft-bar .draft-note { color: var(--t2); }
.draft-bar.clean { background: var(--bg-tertiary); color: var(--t3); }

.tabs { display: flex; gap: 20px; padding: 0 24px; margin-top: 8px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 12px 0 10px; font-weight: 600; color: var(--t3); white-space: nowrap;
  border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px;
}
.tab.active { color: var(--t1); border-bottom-color: var(--t1); }
.tab.disabled { color: var(--t4); }
.tab .count {
  font-size: 12px; line-height: 18px; padding: 0 6px; border-radius: 999px;
  background: var(--bg-secondary); color: var(--t2);
}

/* ---------- skills tab ---------- */
.skills { padding: 20px 24px 40px; max-width: 920px; }
.skills-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.skills-intro { flex: 1 1 320px; }
.skills-intro h2 { font-size: 17px; line-height: 24px; font-weight: 600; }
.skills-intro p { color: var(--t3); font-size: 13px; line-height: 18px; margin-top: 2px; max-width: 520px; }

.seg { display: inline-flex; background: var(--bg-secondary-hover); border-radius: var(--r-m); padding: 3px; }
.seg button { padding: 6px 14px; border-radius: 9px; font-weight: 500; font-size: 13px; color: var(--t2); }
.seg button.active { background: var(--bg-primary); color: var(--t1); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 48px 24px; border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--t3);
}
.empty b { color: var(--t1); font-size: 16px; }
.empty .btn { margin-top: 8px; }

/* skill card */
.card {
  border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 10px;
  background: var(--bg-primary);
}
.card.open { border-color: var(--border-strong); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 12px 14px 16px; cursor: pointer; }
.card-main { flex: 1; min-width: 0; }
.card-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-title .name { font-weight: 600; font-size: 15px; }
.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.card-sum { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; color: var(--t3); font-size: 13px; }
.sum { display: inline-flex; align-items: center; gap: 4px; }
.card.off .fam, .card.off .card-title .name, .card.off .card-sum { opacity: .5; }
.chev { color: var(--t3); transition: transform .15s; }
.card.open > .card-head .chev, .ev-line.open .ev-more .chev { transform: rotate(180deg); }

.fam {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
}

.switch {
  width: 36px; height: 20px; border-radius: 999px; flex-shrink: 0;
  background: var(--border-strong); position: relative; transition: background .15s;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s;
}
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(16px); }

.card-body { padding: 0 16px 14px 60px; }
.card-desc { color: var(--t2); margin-bottom: 6px; }
.ev-line { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.ev-line:first-of-type { border-top: 0; }
.ev-line-main { min-width: 0; flex: 1; }
.ev-ic {
  width: 28px; height: 28px; border-radius: var(--r-sm); flex-shrink: 0;
  background: var(--bg-secondary); color: var(--t2); display: grid; place-items: center;
}
.only-if { color: var(--t3); font-size: 12px; line-height: 16px; margin-top: 4px; }
.ev-more { font-size: 12px; margin-top: 2px; }
.ev-form { padding-top: 8px; }
.ev-form .field > span em { font-style: normal; color: var(--t3); font-weight: 400; }
.ev-empty { color: var(--t3); padding: 8px 0; }
.add-ev {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px;
  padding: 8px; border: 1px dashed var(--border-strong); border-radius: var(--r-m);
  color: var(--t2); font-weight: 500;
}
.add-ev:hover { background: var(--bg-tertiary); color: var(--t1); }
.card-meta { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.link { color: var(--brand); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { color: var(--brand-hover); }

/* an event as a sentence with inline controls */
.sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; line-height: 28px; }
.sentence.boxed { background: var(--bg-tertiary); border-radius: var(--r-m); padding: 6px 10px; }
.inl {
  height: 28px; padding: 0 8px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-primary);
  font-weight: 500; font-size: 13px; color: var(--t1); outline: none; max-width: 100%;
}
select.inl {
  appearance: none; -webkit-appearance: none; padding-right: 24px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b859e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
}
.inl.num { width: 64px; }
.inl:hover { border-color: var(--t4); }
.inl:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* what a skill may use */
.meta-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.meta-row:last-child { margin-bottom: 0; }
.meta-label {
  flex: 0 0 84px; font-size: 11px; line-height: 16px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .3px; color: var(--t3);
}
.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tchip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; border: 1px dashed var(--border-strong);
  font-size: 12px; line-height: 18px; font-weight: 500; color: var(--t3);
}
.tchip:hover { color: var(--t1); border-color: var(--t4); }
.tchip.on { background: var(--badge-bg); color: var(--badge-text); border: 1px solid transparent; }

.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); } 100% { background: var(--bg-primary); } }

/* ---------- pills and controls ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; line-height: 16px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg-secondary); color: var(--t2); white-space: nowrap;
}
.pill.brand { background: var(--badge-bg); color: var(--badge-text); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--error-soft); color: var(--error); }
.pill[title] { cursor: help; }

.btn {
  height: 40px; padding: 0 16px; border-radius: var(--r-m);
  font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn.small { height: 32px; padding: 0 12px; border-radius: var(--r-sm); font-size: 12px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.secondary { background: var(--bg-secondary); color: var(--t1); }
.btn.secondary:hover { background: var(--bg-secondary-hover); }
.btn:disabled { background: var(--bg-secondary); color: var(--t4); }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--r-sm); flex-shrink: 0;
  display: grid; place-items: center; color: var(--t3);
}
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn:hover { background: var(--bg-secondary); color: var(--t1); }
.input, .textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--r-m);
  background: var(--bg-primary); padding: 0 12px; height: 40px; font-size: 14px; outline: none;
}
.textarea { height: auto; min-height: 64px; padding: 10px 12px; resize: vertical; line-height: 20px; }
.input:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 500; color: var(--t2); }
.field small { color: var(--t3); }

/* ---------- modal ---------- */
.modal {
  margin: auto; border: 0; border-radius: var(--r-lg); width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-pop); padding: 0; color: var(--t1);
}
.modal::backdrop { background: rgba(241, 243, 246, 0.7); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 17px; line-height: 24px; font-weight: 600; }
.modal-body { padding: 10px 20px 6px; }
.modal-body > p { color: var(--t2); margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 20px 20px; }
.type-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: var(--r-m); margin-bottom: 2px;
}
.type-opt:hover { background: var(--bg-secondary); }
.type-ic {
  width: 36px; height: 36px; border-radius: 10px; background: var(--bg-secondary);
  display: grid; place-items: center; color: var(--t2); flex-shrink: 0;
}
.type-opt b { display: block; font-weight: 600; }
.type-opt span span { color: var(--t3); font-size: 13px; }

/* ---------- skill library ---------- */
.modal.wide { width: min(1000px, calc(100vw - 32px)); height: min(860px, calc(100vh - 48px)); }
.lib { height: 100%; display: flex; flex-direction: column; }
.lib-bar { padding: 8px 20px 0; }
.search {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-m); color: var(--t3);
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; font-size: 14px; color: var(--t1); background: none; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 13px; font-weight: 500;
}
.chip span { color: var(--t3); font-size: 12px; }
.chip:hover { background: var(--bg-secondary); }
.chip.active { background: var(--t1); border-color: var(--t1); color: #fff; }
.chip.active span { color: var(--t4); }
.lib-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.lib-empty { color: var(--t3); margin: 12px 0; }
.lib-sec { margin-top: 20px; }
.lib-sec:first-child { margin-top: 0; }
.lib-sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.lib-sec-head b { display: block; font-weight: 600; }
.lib-sec-head span { color: var(--t3); font-size: 13px; }
.sk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.sk-card {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg-primary); text-align: left;
}
.sk-card.later { background: var(--bg-tertiary); }
.sk-card.later .sk-name, .sk-card.later .sk-desc, .sk-card.later .fam { opacity: .6; }
.sk-top { display: flex; align-items: center; gap: 10px; }
.sk-name { font-weight: 600; flex: 1; min-width: 0; }
.sk-desc { color: var(--t2); font-size: 13px; line-height: 18px; }
.sk-line { display: flex; gap: 6px; color: var(--t3); font-size: 12px; line-height: 16px; }
.sk-line svg { margin-top: 1px; }
.sk-line.warn { color: var(--warn); }
.sk-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 4px; }
.sk-evs { display: flex; gap: 6px; color: var(--t3); }
.sk-card.create {
  border-style: dashed; border-color: var(--border-strong); align-items: center; justify-content: center;
  text-align: center; color: var(--t3); font-size: 13px; line-height: 18px; min-height: 120px;
}
.sk-card.create b { color: var(--t1); font-size: 14px; }
.sk-card.create:hover { background: var(--bg-tertiary); }
.create-ic {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center;
}
.lib-body > .sk-grid { margin-bottom: 20px; }

/* ---------- menu popover ---------- */
.menu {
  position: fixed; z-index: 50; min-width: 220px;
  background: var(--bg-primary); border-radius: var(--r-m); box-shadow: var(--shadow-pop);
  padding: 4px; border: 1px solid var(--border);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px;
  padding: 0 10px; border-radius: var(--r-sm); text-align: left; font-size: 14px;
}
.menu button svg { color: var(--t3); }
.menu button:hover:not(:disabled) { background: var(--bg-secondary); }
.menu button.danger, .menu button.danger svg { color: var(--error); }
.menu button:disabled, .menu button:disabled svg { color: var(--t4); }
.menu hr { border: 0; height: 1px; background: var(--border); margin: 4px 6px; }

/* ---------- toasts ---------- */
.toast-stack {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: #292929; color: #fff; padding: 10px 16px; border-radius: var(--r-m);
  font-size: 14px; box-shadow: var(--shadow-pop);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- narrow screens ---------- */
@media (max-width: 1320px) { .assist { display: none; } }
@media (max-width: 1000px) { .settings-nav { display: none; } }
@media (max-width: 720px) {
  .rail { display: none; }
  .app { padding: 0; }
  .content { border-radius: 0; }
  .ed-head, .skills { padding-left: 16px; padding-right: 16px; }
  .draft-bar { margin: 0 16px; }
  .tabs { padding: 0 16px; }
  .card-body { padding-left: 16px; }
  .meta-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .meta-label { flex: none; }
}
