/* ═══════════════════════════════════════
   TEMPLATE EDITOR — Obsidian Gold Theme
   ═══════════════════════════════════════ */

/* ── Split layout ── */
.tpl-split {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - var(--topbar-h, 64px) - 32px);
  gap: 0;
}

/* ── Left panel: template list ── */
.tpl-list-panel {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tpl-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
}

.tpl-filters {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}

.tpl-filters .chip {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: .15s;
  font-family: inherit;
}
.tpl-filters .chip:hover {
  border-color: var(--gold-border);
  color: var(--text);
}
.tpl-filters .chip.active {
  background: var(--gold-bg);
  border-color: var(--gold-border);
  color: var(--gold);
}

.tpl-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

/* ── Template card ── */
.tpl-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: .15s;
}
.tpl-card:hover {
  border-color: var(--border-2);
  background: var(--bg-hover);
}
.tpl-card.active {
  border-color: var(--gold-border);
  box-shadow: 0 0 0 1px var(--gold-border), 0 0 12px rgba(47,160,132,.08);
}

.tpl-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.3;
}

.tpl-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Type badge ── */
.tpl-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.tpl-type-badge.nda {
  background: var(--purple-bg);
  color: #b080ee;
}
.tpl-type-badge.offer_letter {
  background: var(--blue-bg);
  color: var(--blue-2);
}
.tpl-type-badge.contract {
  background: var(--green-bg);
  color: var(--green);
}

/* ── Default badge ── */
.tpl-default-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--gold-bg);
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Right panel: editor ── */
.tpl-editor-panel {
  background: var(--bg-surface);
  border-radius: 0 var(--r-lg) var(--r-lg) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tpl-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.tpl-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ── Top bar ── */
.tpl-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--bg-card);
}

.tpl-name-input {
  height: 36px;
  padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  outline: none;
  transition: .15s;
  min-width: 180px;
}
.tpl-name-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(47,160,132,.15);
}
.tpl-name-input::placeholder {
  color: var(--text-3);
}

/* ── Sections ── */
.tpl-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.tpl-section-label {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .15em;
  margin-bottom: 8px;
}

/* ── Image upload zone ── */
.tpl-img-upload {
  border: 1.5px dashed var(--border-2);
  border-radius: var(--r-sm);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: .15s;
  margin-bottom: 8px;
  background: var(--bg-elevated);
}
.tpl-img-upload:hover {
  border-color: var(--gold-border);
  background: rgba(47,160,132,.04);
}

/* ── Contenteditable areas ── */
.tpl-editable {
  min-height: 48px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  outline: none;
  transition: border-color .15s;
}
.tpl-editable:focus {
  border-color: var(--gold-border);
}
.tpl-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}

.tpl-body {
  flex: 1;
  min-height: 300px;
  overflow-y: auto;
}

/* ── Toolbar ── */
.tpl-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tb-btn {
  width: 32px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: .15s;
}
.tb-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-2);
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.tb-select {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.tb-select option {
  background: var(--bg-card);
  color: var(--text);
}

/* ── Merge tag dropdown ── */
.tb-merge-dropdown {
  position: relative;
}

.tb-merge-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  width: auto;
  padding: 0 10px;
  white-space: nowrap;
}

.tb-merge-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 6px 0;
  margin-top: 4px;
}
.tb-merge-dropdown.open .tb-merge-menu {
  display: block;
}

.tb-merge-group {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: 8px 14px 4px;
}
.tb-merge-group:first-child {
  padding-top: 4px;
}

.tb-merge-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  transition: .1s;
}
.tb-merge-item:hover {
  background: var(--bg-hover);
  color: var(--gold);
}

/* ── Inline merge tag pill ── */
.merge-tag {
  display: inline-block;
  background: var(--blue-bg);
  color: var(--blue-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid rgba(58,106,212,.2);
  vertical-align: baseline;
  white-space: nowrap;
  user-select: all;
}

/* ── Responsive: collapse to single column ── */
@media (max-width: 800px) {
  .tpl-split {
    grid-template-columns: 1fr;
    height: auto;
  }
  .tpl-list-panel {
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 260px;
  }
  .tpl-editor-panel {
    border-radius: 0 0 var(--r-lg) var(--r-lg);
    min-height: 500px;
  }
}
