/* ── Modal Overlay & Shell ───────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.52);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; opacity: 0; pointer-events: none; transition: opacity .22s; contain: strict;
}
.modal-overlay.visible { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 20px; width: calc(100% - 32px); max-width: 500px; max-height: 86vh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  transform: translateY(10px) scale(.98); transition: transform .22s var(--ease);
  will-change: transform; contain: layout style;
}
.modal-overlay.visible .modal { transform: none; }

.modal-hd {
  display: flex; align-items: center; justify-content: center;
  padding: 20px 22px 0; flex-shrink: 0;
  position: relative;
}
.modal-title { font-size: 17px; font-weight: 600; text-align: center; }
.modal-hd .icon-btn { position: absolute; right: 22px; }

.modal-tabs {
  display: flex; gap: 2px; padding: 14px 22px 0; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.modal-tab {
  padding: 7px 14px; border: none; background: none;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--text2);
  border-bottom: 2px solid transparent;
  position: relative; bottom: -1px; border-radius: 4px 4px 0 0; transition: color .15s;
}
.modal-tab.active { color: var(--accent2); border-bottom-color: var(--accent2); }

.modal-body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.modal-body::-webkit-scrollbar       { width: 3px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0;
}

.preview-modal {
  width: calc(100% - 32px);
  max-height: min(86vh, 820px);
}

.preview-modal-body {
  padding: 14px 18px 18px;
}

.code-preview-frame {
  display: block;
  width: 100%;
  height: min(70vh, 640px);
  border: 1px solid var(--border2);
  border-radius: 14px;
  background: #fff;
}

/* ── Settings Sections ───────────────────────────────── */
.sec-title {
  font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 8px;
}
.sec-card    { background: var(--bg3); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
.sec-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.sec-row:last-child  { border-bottom: none; }
.sec-row-l           { display: flex; flex-direction: column; gap: 2px; }
.sec-row-label       { font-size: 13.5px; color: var(--text); font-weight: 500; }
.sec-row-desc        { font-size: 12px; color: var(--text2); }

/* ── Key Items ───────────────────────────────────────── */
.key-item         { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.key-item:last-child { border-bottom: none; }
.ki-text          { flex: 1; }
.ki-label         { font-size: 13px; font-weight: 500; color: var(--text); }
.ki-val           { font-size: 11.5px; color: var(--text2); font-family: monospace; }
.ki-badge         { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.ki-badge.active  { background: rgba(74,222,128,.12); color: var(--success); }
.ki-badge.inactive { background: var(--bg4); color: var(--text3); }

/* ── Memory Items ────────────────────────────────────── */
.mem-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.mem-item:last-child { border-bottom: none; }
.mem-num {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-glow); color: var(--accent2);
  font-size: 10.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;
}
.mem-text  { flex: 1; font-size: 13.5px; color: var(--text); line-height: 1.5; outline: none; }
.mem-text[contenteditable="true"]:focus { color: var(--accent2); }
.mem-acts  { display: flex; gap: 3px; opacity: 0; transition: opacity .15s; flex-shrink: 0; }
.mem-item:hover .mem-acts { opacity: 1; }
.mem-btn {
  width: 24px; height: 24px; background: none; border: none;
  border-radius: 5px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3); transition: background .15s, color .15s;
}
.mem-btn:hover     { background: var(--bg4); color: var(--text); }
.mem-btn.del:hover { background: rgba(248,113,113,.1); color: var(--danger); }

/* ── Model Picker ────────────────────────────────────── */
.mp-search-wrapper {
  position: relative;
  margin-bottom: 12px;
}

.mp-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}

.mp-search-input {
  width: 100%;
  padding: 10px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

.mp-search-input:focus {
  outline: none;
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.mp-search-input::placeholder {
  color: var(--text3);
}

.mp-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  transition: background .15s, color .15s;
}

.mp-search-clear:hover {
  background: var(--bg4);
  color: var(--text);
}

.mp-models-wrap { max-height: 240px; overflow-y: auto; border-radius: var(--radius); margin-bottom: 4px; }
.mp-models-wrap::-webkit-scrollbar       { width: 3px; }
.mp-models-wrap::-webkit-scrollbar-thumb { background: var(--border2); }
.mp-model-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  background: var(--bg3); transition: background .12s;
}
.mp-model-row:last-child { border-bottom: none; }
.mp-model-row:hover      { background: var(--bg4); }
.mp-model-row.mp-active  { background: var(--accent-glow); }
.mp-context-tag {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg2);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.mp-cost-badge           { font-size: 11.5px; color: var(--text3); white-space: nowrap; margin-left: auto; margin-right: 6px; }
.mp-balance-card         { margin-top: 4px; }
.mp-stat-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center;
}
.mp-stat-icon { font-size: 18px; line-height: 1; }
.mp-stat-val  { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.1; }
.mp-stat-lbl  { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ── Create Agent Form ────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { 
  display: block; font-size: 13px; font-weight: 500; 
  color: var(--text); margin-bottom: 6px; 
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg3);
  font-family: var(--font); font-size: 13.5px; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus {
  outline: none; border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text3); }
.form-textarea {
  width: 100%; min-height: 100px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg3); font-family: var(--font);
  font-size: 13.5px; color: var(--text); resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
.form-textarea:focus {
  outline: none; border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-textarea::placeholder { color: var(--text3); }

.emoji-picker-container { display: flex; gap: 8px; align-items: center; }
.emoji-display {
  width: 48px; height: 48px; border: 2px solid var(--border);
  border-radius: var(--radius); background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; cursor: pointer; transition: border-color .15s;
}
.emoji-display:hover { border-color: var(--accent2); }
.emoji-input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg3);
  font-family: var(--font); font-size: 13.5px; color: var(--text);
}
.emoji-input:focus {
  outline: none; border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 4px; margin-top: 8px; padding: 8px;
  background: var(--bg3); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.emoji-item {
  width: 32px; height: 32px; border: none; background: none;
  border-radius: 4px; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, transform .12s;
}
.emoji-item:hover { 
  background: var(--bg4); transform: scale(1.15); 
}
.emoji-item.selected {
  background: var(--accent-glow); border: 1px solid var(--accent2);
}

.category-select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg3);
  font-family: var(--font); font-size: 13.5px; color: var(--text);
  cursor: pointer; transition: border-color .15s;
}
.category-select:focus {
  outline: none; border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-hint {
  font-size: 11.5px; color: var(--text3);
  margin-top: 4px; line-height: 1.4;
}

.custom-agent-badge {
  display: inline-block; padding: 2px 6px;
  background: var(--accent-glow); color: var(--accent2);
  font-size: 10px; font-weight: 600; border-radius: 4px;
  margin-left: 6px;
}

/* ── Model Selector ───────────────────────────────────── */
.model-selector {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  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='%239CA3AF' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.model-selector:hover {
  border-color: var(--accent2);
}

.model-selector:focus {
  outline: none;
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.model-selector option {
  background: var(--bg2);
  color: var(--text);
  padding: 8px;
}

/* ── Slider Controls ──────────────────────────────────── */
.slider-row {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.slider-container {
  width: 100%;
}

.slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg4);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, box-shadow 0.15s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.slider-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.slider-desc {
  font-size: 12px;
  color: var(--text3);
}

.slider-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent2);
  min-width: 50px;
  text-align: right;
}
