/* ── Jalpi Page Builder — Theme Builder Admin UI ────────────────────────────── */

:root {
  --jalpi-tb-accent:       #5b6af5;
  --jalpi-tb-accent-hover: #4757e8;
  --jalpi-tb-bg:           #f0f1f5;
  --jalpi-tb-surface:      #ffffff;
  --jalpi-tb-border:       #e2e4ea;
  --jalpi-tb-text:         #1a1b26;
  --jalpi-tb-muted:        #6b7280;
  --jalpi-tb-success:      #16a34a;
  --jalpi-tb-danger:       #dc2626;
  --jalpi-tb-warning:      #d97706;
  --jalpi-tb-radius:       8px;
  --jalpi-tb-shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --jalpi-tb-shadow-lg:    0 10px 40px rgba(0,0,0,.14);
}

/* Reset within our wrapper */
.jalpi-tb-wrap * { box-sizing: border-box; }
.jalpi-tb-wrap { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--jalpi-tb-text); }

/* ── Page Header ─────────────────────────────────────────────────────────── */

.jalpi-tb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  background: var(--jalpi-tb-surface);
  border-bottom: 1px solid var(--jalpi-tb-border);
  margin: -8px -20px 0;
}
.jalpi-tb-header__title {
  display: flex;
  align-items: center;
  gap: 14px;
}
.jalpi-tb-header__title svg { color: var(--jalpi-tb-accent); flex-shrink: 0; }
.jalpi-tb-header__title h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--jalpi-tb-text);
  line-height: 1.2;
}
.jalpi-tb-header__title p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--jalpi-tb-muted);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.jalpi-tb-layout {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 140px);
  margin: 0 -20px;
}

/* ── Location Nav ────────────────────────────────────────────────────────── */

.jalpi-tb-nav {
  width: 220px;
  flex-shrink: 0;
  background: var(--jalpi-tb-surface);
  border-right: 1px solid var(--jalpi-tb-border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.jalpi-tb-nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 0;
  text-decoration: none;
  color: var(--jalpi-tb-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background .1s, color .1s;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.jalpi-tb-nav__item:hover {
  background: var(--jalpi-tb-bg);
  color: var(--jalpi-tb-text);
}
.jalpi-tb-nav__item.is-active {
  color: var(--jalpi-tb-accent);
  background: rgba(91,106,245,.07);
  border-left-color: var(--jalpi-tb-accent);
}
.jalpi-tb-nav__icon svg { width: 16px; height: 16px; flex-shrink: 0; }
.jalpi-tb-nav__label { flex: 1; }
.jalpi-tb-nav__count {
  background: var(--jalpi-tb-border);
  color: var(--jalpi-tb-muted);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.jalpi-tb-nav__item.is-active .jalpi-tb-nav__count {
  background: var(--jalpi-tb-accent);
  color: #fff;
}

/* ── Main Content ────────────────────────────────────────────────────────── */

.jalpi-tb-main {
  flex: 1;
  background: var(--jalpi-tb-bg);
  padding: 24px;
  overflow-y: auto;
}

.jalpi-tb-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.jalpi-tb-section-header__info h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--jalpi-tb-text);
}
.jalpi-tb-section-header__info p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--jalpi-tb-muted);
}

/* ── Template List ───────────────────────────────────────────────────────── */

.jalpi-tb-templates {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Template Card ───────────────────────────────────────────────────────── */

.jalpi-tb-card {
  background: var(--jalpi-tb-surface);
  border: 1px solid var(--jalpi-tb-border);
  border-radius: var(--jalpi-tb-radius);
  box-shadow: var(--jalpi-tb-shadow);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow .15s;
}
.jalpi-tb-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.jalpi-tb-card.is-active { border-left: 3px solid var(--jalpi-tb-success); }
.jalpi-tb-card.is-inactive { border-left: 3px solid var(--jalpi-tb-border); opacity: .75; }

.jalpi-tb-card__main { flex: 1; min-width: 0; }

.jalpi-tb-card__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--jalpi-tb-text);
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jalpi-tb-card__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */

.jalpi-tb-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.jalpi-tb-badge--active   { background: #dcfce7; color: var(--jalpi-tb-success); }
.jalpi-tb-badge--inactive { background: #f1f2f5; color: var(--jalpi-tb-muted); }
.jalpi-tb-badge--muted    { background: #f1f2f5; color: var(--jalpi-tb-muted); }
.jalpi-tb-badge--accent   { background: rgba(91,106,245,.1); color: var(--jalpi-tb-accent); }

.jalpi-tb-priority-badge {
  font-size: 11px;
  color: var(--jalpi-tb-muted);
  background: var(--jalpi-tb-bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--jalpi-tb-border);
}

.jalpi-tb-conditions-summary {
  font-size: 11px;
  color: var(--jalpi-tb-muted);
}
.jalpi-tb-conditions-summary strong { color: var(--jalpi-tb-text); }

/* ── Card Actions ────────────────────────────────────────────────────────── */

.jalpi-tb-card__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Status toggle */
.jalpi-tb-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--jalpi-tb-muted);
  user-select: none;
}
.jalpi-tb-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.jalpi-tb-toggle__track {
  width: 36px;
  height: 20px;
  background: var(--jalpi-tb-border);
  border-radius: 10px;
  position: relative;
  transition: background .15s;
  flex-shrink: 0;
}
.jalpi-tb-toggle__track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: left .15s;
}
.jalpi-tb-toggle input:checked ~ .jalpi-tb-toggle__track { background: var(--jalpi-tb-success); }
.jalpi-tb-toggle input:checked ~ .jalpi-tb-toggle__track::after { left: 19px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.jalpi-tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
  text-decoration: none;
  white-space: nowrap;
}
.jalpi-tb-btn--primary { background: var(--jalpi-tb-accent); color: #fff; }
.jalpi-tb-btn--primary:hover { background: var(--jalpi-tb-accent-hover); color: #fff; }
.jalpi-tb-btn--ghost { background: transparent; border-color: var(--jalpi-tb-border); color: var(--jalpi-tb-text); }
.jalpi-tb-btn--ghost:hover { background: var(--jalpi-tb-bg); }
.jalpi-tb-btn--danger { background: transparent; border-color: transparent; color: var(--jalpi-tb-danger); }
.jalpi-tb-btn--danger:hover { background: #fee2e2; }
.jalpi-tb-btn--icon { padding: 6px; border-radius: 6px; }
.jalpi-tb-btn--sm { padding: 5px 10px; font-size: 11px; }
.jalpi-tb-btn svg { flex-shrink: 0; }

/* ── Loading / Empty ─────────────────────────────────────────────────────── */

.jalpi-tb-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 40px 0;
  color: var(--jalpi-tb-muted);
  font-size: 13px;
  justify-content: center;
}

.jalpi-tb-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--jalpi-tb-border);
  border-top-color: var(--jalpi-tb-accent);
  border-radius: 50%;
  animation: jalpi-tb-spin .7s linear infinite;
}
@keyframes jalpi-tb-spin { to { transform: rotate(360deg); } }

.jalpi-tb-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--jalpi-tb-muted);
}
.jalpi-tb-empty__icon {
  margin: 0 auto 14px;
  width: 48px;
  height: 48px;
  background: var(--jalpi-tb-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--jalpi-tb-border);
}
.jalpi-tb-empty h3 { font-size: 14px; font-weight: 600; color: var(--jalpi-tb-text); margin: 0 0 6px; }
.jalpi-tb-empty p  { font-size: 12px; margin: 0 0 16px; }

/* ── Modals ──────────────────────────────────────────────────────────────── */

.jalpi-tb-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}
.jalpi-tb-overlay.is-visible {
  opacity: 1;
  pointer-events: all;
}

.jalpi-tb-modal {
  background: var(--jalpi-tb-surface);
  border-radius: 10px;
  box-shadow: var(--jalpi-tb-shadow-lg);
  width: min(560px, 94vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: jalpi-tb-modal-in .18s ease;
}
.jalpi-tb-modal--sm { width: min(420px, 94vw); }

@keyframes jalpi-tb-modal-in {
  from { transform: translateY(12px) scale(.97); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.jalpi-tb-modal__hd {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--jalpi-tb-border);
  flex-shrink: 0;
}
.jalpi-tb-modal__hd h3 { margin: 0; font-size: 15px; font-weight: 700; flex: 1; }
.jalpi-tb-modal__subtitle { margin: 2px 0 0; font-size: 12px; color: var(--jalpi-tb-muted); }
.jalpi-tb-modal__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--jalpi-tb-muted);
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.jalpi-tb-modal__close:hover { background: var(--jalpi-tb-bg); color: var(--jalpi-tb-text); }

.jalpi-tb-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.jalpi-tb-modal__hint {
  font-size: 12px;
  color: var(--jalpi-tb-muted);
  background: #f8f9ff;
  border: 1px solid #dde0ff;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0;
  line-height: 1.5;
}

.jalpi-tb-modal__ft {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--jalpi-tb-border);
  flex-shrink: 0;
}

/* ── Condition Rows ──────────────────────────────────────────────────────── */

.jalpi-conditions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.jalpi-condition-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--jalpi-tb-bg);
  border: 1px solid var(--jalpi-tb-border);
  border-radius: 6px;
  padding: 8px 10px;
}
.jalpi-condition-row select,
.jalpi-condition-row input {
  border: 1px solid var(--jalpi-tb-border);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--jalpi-tb-text);
  background: var(--jalpi-tb-surface);
  outline: none;
  transition: border-color .12s;
}
.jalpi-condition-row select:focus,
.jalpi-condition-row input:focus { border-color: var(--jalpi-tb-accent); }

.jalpi-condition-row__type     { flex: 0 0 160px; }
.jalpi-condition-row__operator { flex: 0 0 90px; }
.jalpi-condition-row__value    { flex: 1; min-width: 0; }
.jalpi-condition-row__remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--jalpi-tb-muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  flex-shrink: 0;
  align-items: center;
}
.jalpi-condition-row__remove:hover { background: #fee2e2; color: var(--jalpi-tb-danger); }

/* ── Form Fields ─────────────────────────────────────────────────────────── */

.jalpi-tb-field { display: flex; flex-direction: column; gap: 5px; }
.jalpi-tb-field__label { font-size: 12px; font-weight: 600; color: var(--jalpi-tb-text); }
.jalpi-tb-input {
  border: 1px solid var(--jalpi-tb-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--jalpi-tb-text);
  background: var(--jalpi-tb-surface);
  outline: none;
  width: 100%;
  transition: border-color .12s;
}
.jalpi-tb-input:focus { border-color: var(--jalpi-tb-accent); }

/* ── Priority Input ──────────────────────────────────────────────────────── */

.jalpi-tb-priority-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}
.jalpi-tb-priority-wrap input {
  width: 54px;
  border: 1px solid var(--jalpi-tb-border);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 12px;
  text-align: center;
  outline: none;
  background: var(--jalpi-tb-surface);
  color: var(--jalpi-tb-text);
}
.jalpi-tb-priority-wrap input:focus { border-color: var(--jalpi-tb-accent); }
.jalpi-tb-priority-label { font-size: 11px; color: var(--jalpi-tb-muted); }


