/* ═══════════════════════════════════════════
   TFA-AVA – Template Management Styles
   Splitview: List ↔ Detail/Edit
   iPhone-first → iPad → Desktop
   ═══════════════════════════════════════════ */

/* ─── Layout Container ─── */
.tmpl-layout {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 60px);
}

/* ─── List Panel ─── */
.tmpl-list-panel {
  display: flex;
  flex-direction: column;
  padding: var(--sp-md);
}

.tmpl-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-md);
  padding-top: var(--sp-sm);
}

.tmpl-list-title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
}

.tmpl-list-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

/* ─── List Items ─── */
.tmpl-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-sm) var(--sp-md);
  background: var(--c-bg-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--tr-fast);
}

.tmpl-list-item:hover {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}

.tmpl-list-item-active {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}

.tmpl-list-item-inactive {
  opacity: 0.55;
}

.tmpl-list-item-main {
  flex: 1;
  min-width: 0;
}

.tmpl-list-item-title {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tmpl-list-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-top: 2px;
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.tmpl-list-item-arrow {
  font-size: var(--fs-xl);
  color: var(--c-text-muted);
  margin-left: var(--sp-sm);
  flex-shrink: 0;
}

/* ─── Empty State ─── */
.tmpl-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2xl) var(--sp-md);
  text-align: center;
}

/* ─── Detail Panel ─── */
.tmpl-detail-panel {
  display: none;
  padding: var(--sp-md);
}

.tmpl-detail-visible {
  display: block;
}

.tmpl-detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
}

.tmpl-detail-content {
  max-width: 700px;
}

/* Mobile back button */
.tmpl-back-btn {
  margin-bottom: var(--sp-md);
}

/* ─── Detail: Action Bar ─── */
.tmpl-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
  padding: var(--sp-sm);
  background: var(--c-bg-elevated);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
}

.btn-danger-text {
  color: var(--c-error) !important;
}

.btn-danger-text:hover {
  background: var(--c-error-soft) !important;
}

/* ─── Detail: Inactive banner ─── */
.tmpl-inactive-banner {
  padding: var(--sp-sm) var(--sp-md);
  background: var(--c-warning);
  color: #000;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  margin-bottom: var(--sp-lg);
}

/* ─── Detail: Title + Description ─── */
.tmpl-detail-title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-sm);
  line-height: 1.2;
}

.tmpl-detail-desc {
  color: var(--c-text-secondary);
  line-height: var(--lh-normal);
  margin-bottom: var(--sp-lg);
}

/* ─── Detail: Info Cards ─── */
.tmpl-detail-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
}

.tmpl-info-card {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-md);
  background: var(--c-bg-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.tmpl-info-link {
  cursor: pointer;
}

.tmpl-info-link:hover {
  border-color: var(--c-primary);
}

.tmpl-info-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.tmpl-info-label {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.tmpl-info-value {
  font-weight: var(--fw-medium);
}

/* ─── Detail: Subtasks ─── */
.tmpl-subtask-section {
  margin-bottom: var(--sp-lg);
}

.tmpl-subtask-title {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-sm);
}

.tmpl-subtask-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.tmpl-subtask-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  background: var(--c-bg-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.tmpl-subtask-number {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  border-radius: 50%;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
}

.tmpl-subtask-text {
  flex: 1;
}

/* ─── Edit Form ─── */
.tmpl-edit-heading {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-lg);
}

.tmpl-edit-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.tmpl-edit-subtasks {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  margin-bottom: var(--sp-sm);
}

.tmpl-edit-subtask-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-xs);
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  cursor: grab;
}

.tmpl-edit-subtask-item:active {
  cursor: grabbing;
}

.tmpl-edit-subtask-grip {
  color: var(--c-text-muted);
  font-size: var(--fs-lg);
  cursor: grab;
  flex-shrink: 0;
  padding: 0 var(--sp-xs);
  user-select: none;
}

.tmpl-edit-subtask-input {
  flex: 1;
  min-width: 0;
}

.tmpl-add-subtask-row {
  display: flex;
  gap: var(--sp-sm);
}

.tmpl-add-subtask-row .input {
  flex: 1;
}

.tmpl-edit-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  margin-top: var(--sp-lg);
}

/* ─── Drag & Drop states ─── */
.tmpl-dragging {
  opacity: 0.4;
}

.tmpl-dragover {
  border-color: var(--c-primary) !important;
  background: var(--c-primary-soft) !important;
}

/* Badge for inactive */
.badge-muted {
  background: var(--c-bg-elevated);
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
  padding: 1px 6px;
  border-radius: var(--r-sm);
}

/* ═══════════════════════════════════════════
   TABLET (768px+): Splitview side-by-side
   ═══════════════════════════════════════════ */
@media (min-width: 768px) {
  .tmpl-layout {
    flex-direction: row;
    height: calc(100dvh - 60px);
    overflow: hidden;
  }

  .tmpl-list-panel {
    width: 320px;
    min-width: 320px;
    border-right: 1px solid var(--c-border);
    overflow-y: auto;
    height: 100%;
    padding: var(--sp-lg) var(--sp-md);
  }

  .tmpl-detail-panel {
    flex: 1;
    overflow-y: auto;
    height: 100%;
    padding: var(--sp-lg);
    display: block; /* Always visible on tablet+ */
  }

  .tmpl-back-btn {
    display: none; /* No back button needed on split view */
  }

  .tmpl-detail-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .tmpl-detail-content {
    max-width: 800px;
  }
}

/* ═══════════════════════════════════════════
   DESKTOP (1024px+): Wider list, more space
   ═══════════════════════════════════════════ */
@media (min-width: 1024px) {
  .tmpl-list-panel {
    width: 380px;
    min-width: 380px;
    padding: var(--sp-xl) var(--sp-lg);
  }

  .tmpl-detail-panel {
    padding: var(--sp-xl);
  }

  .tmpl-detail-actions {
    flex-wrap: nowrap;
  }
}

/* ═══════════════════════════════════════════
   MOBILE BEHAVIOR: Show list OR detail
   JS toggles list-panel display; CSS hides via :has()
   ═══════════════════════════════════════════ */
@media (max-width: 767px) {
  .tmpl-layout:has(.tmpl-detail-visible) > .tmpl-list-panel {
    display: none;
  }

  .tmpl-detail-panel {
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--sp-lg));
  }

  .tmpl-list-panel {
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--sp-lg));
  }
}
